From 9006af28b92ed9b13fb280fbc02f13beba8a4eda Mon Sep 17 00:00:00 2001 From: Mike Thomas Date: Sat, 3 Feb 2007 00:22:14 +0000 Subject: [PATCH] Some convenience functions for getting color information entirely by name. git-svn-id: svn+ssh://src.earth.threerings.net/nenya/trunk@145 ed5b42cb-e716-0410-a449-f6a68f950b19 --- .../threerings/media/image/ColorPository.java | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/src/java/com/threerings/media/image/ColorPository.java b/src/java/com/threerings/media/image/ColorPository.java index bf56b74e..4a063ba9 100644 --- a/src/java/com/threerings/media/image/ColorPository.java +++ b/src/java/com/threerings/media/image/ColorPository.java @@ -351,6 +351,29 @@ public class ColorPository implements Serializable return null; } + /** + * Looks up a colorization by class and color names. + */ + public Colorization getColorization (String className, String colorName) + { + ClassRecord crec = getClassRecord(className); + if (crec != null) { + int colorId = 0; + try { + colorId = crec.getColorId(colorName); + } catch (ParseException pe) { + Log.info("Error getting colorization by name. [error=" + pe + "]"); + return null; + } + + ColorRecord color = (ColorRecord)crec.colors.get(colorId); + if (color != null) { + return color.getColorization(); + } + } + return null; + } + /** * Loads up a colorization class by name and logs a warning if it * doesn't exist. @@ -389,6 +412,30 @@ public class ColorPository implements Serializable return (ColorRecord)record.colors.get(colorId); } + /** + * Looks up the requested color record by class & color names. + */ + public ColorRecord getColorRecord (String className, String colorName) + { + ClassRecord record = getClassRecord(className); + if (record == null) { + Log.warning("Requested unknown color class " + + "[className=" + className + ", colorName=" + colorName + "]."); + Thread.dumpStack(); + return null; + } + + int colorId = 0; + try { + colorId = record.getColorId(colorName); + } catch (ParseException pe) { + Log.info("Error getting color record by name. [error=" + pe + "]"); + return null; + } + + return (ColorRecord)record.colors.get(colorId); + } + /** * Adds a fully configured color class record to the pository. This is * only called by the XML parsing code, so pay it no mind.