diff --git a/src/java/com/threerings/cast/CharacterComponent.java b/src/java/com/threerings/cast/CharacterComponent.java index c2b02dad0..b69136fe0 100644 --- a/src/java/com/threerings/cast/CharacterComponent.java +++ b/src/java/com/threerings/cast/CharacterComponent.java @@ -1,5 +1,5 @@ // -// $Id: CharacterComponent.java,v 1.4 2001/11/27 08:09:34 mdb Exp $ +// $Id: CharacterComponent.java,v 1.5 2002/02/19 22:09:50 mdb Exp $ package com.threerings.cast; @@ -51,13 +51,25 @@ public class CharacterComponent implements Serializable return _frameProvider.getFrames(this, action); } + /** + * Returns true if this component is equal to the other component. The + * comparison is made on componentId. + */ + public boolean equals (Object other) + { + if (other instanceof CharacterComponent) { + return componentId == ((CharacterComponent)other).componentId; + } else { + return false; + } + } + /** * Returns a string representation of this character component. */ public String toString () { - return "[componentId=" + componentId + ", name=" + name + - ", class=" + componentClass + "]"; + return StringUtil.fieldsToString(this); } /** The entity from which we obtain our animation frames. */ diff --git a/src/java/com/threerings/cast/ComponentRepository.java b/src/java/com/threerings/cast/ComponentRepository.java index 0c90a19aa..5374778c9 100644 --- a/src/java/com/threerings/cast/ComponentRepository.java +++ b/src/java/com/threerings/cast/ComponentRepository.java @@ -1,5 +1,5 @@ // -// $Id: ComponentRepository.java,v 1.4 2001/11/27 08:09:35 mdb Exp $ +// $Id: ComponentRepository.java,v 1.5 2002/02/19 22:09:50 mdb Exp $ package com.threerings.cast; @@ -20,6 +20,19 @@ public interface ComponentRepository public CharacterComponent getComponent (int componentId) throws NoSuchComponentException; + /** + * Returns the {@link CharacterComponent} object with the given + * component class and name. + */ + public CharacterComponent getComponent (String className, String compName) + throws NoSuchComponentException; + + /** + * Returns the {@link ComponentClass} with the specified name or null + * if none exists with that name. + */ + public ComponentClass getComponentClass (String className); + /** * Iterates over the {@link ComponentClass} instances representing all * available character component classes. diff --git a/src/java/com/threerings/cast/NoSuchComponentException.java b/src/java/com/threerings/cast/NoSuchComponentException.java index 60c40b405..997979fc7 100644 --- a/src/java/com/threerings/cast/NoSuchComponentException.java +++ b/src/java/com/threerings/cast/NoSuchComponentException.java @@ -1,5 +1,5 @@ // -// $Id: NoSuchComponentException.java,v 1.2 2001/11/27 08:09:35 mdb Exp $ +// $Id: NoSuchComponentException.java,v 1.3 2002/02/19 22:09:50 mdb Exp $ package com.threerings.cast; @@ -15,6 +15,14 @@ public class NoSuchComponentException extends Exception _componentId = componentId; } + public NoSuchComponentException ( + String componentClass, String componentName) + { + super("No such component [class=" + componentClass + + ", name=" + componentName + "]"); + _componentId = -1; + } + public int getComponentId () { return _componentId; diff --git a/src/java/com/threerings/cast/bundle/BundledComponentRepository.java b/src/java/com/threerings/cast/bundle/BundledComponentRepository.java index 4e706d09f..8fb22bda2 100644 --- a/src/java/com/threerings/cast/bundle/BundledComponentRepository.java +++ b/src/java/com/threerings/cast/bundle/BundledComponentRepository.java @@ -1,5 +1,5 @@ // -// $Id: BundledComponentRepository.java,v 1.6 2002/02/18 00:06:57 mdb Exp $ +// $Id: BundledComponentRepository.java,v 1.7 2002/02/19 22:09:50 mdb Exp $ package com.threerings.cast.bundle; @@ -10,6 +10,7 @@ import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; +import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; @@ -130,6 +131,31 @@ public class BundledComponentRepository return component; } + // documentation inherited + public CharacterComponent getComponent (String className, String compName) + throws NoSuchComponentException + { + // look up the list for that class + ArrayList comps = (ArrayList)_classComps.get(className); + if (comps != null) { + // scan the list for the named component + int ccount = comps.size(); + for (int i = 0; i < ccount; i++) { + CharacterComponent comp = (CharacterComponent)comps.get(i); + if (comp.name.equals(compName)) { + return comp; + } + } + } + throw new NoSuchComponentException(className, compName); + } + + // documentation inherited + public ComponentClass getComponentClass (String className) + { + return (ComponentClass)_classes.get(className); + } + // documentation inherited public Iterator enumerateComponentClasses () { @@ -174,8 +200,21 @@ public class BundledComponentRepository CharacterComponent component = new CharacterComponent( componentId, cname, clazz, fprov); - // cache it + // stick it into the appropriate tables _components.put(componentId, component); + + // we have a hash of lists for mapping components by class/name + ArrayList comps = (ArrayList)_classComps.get(cclass); + if (comps == null) { + comps = new ArrayList(); + _classComps.put(cclass, comps); + } + if (!comps.contains(component)) { + comps.add(component); + } else { + Log.info("Requested to register the same component twice? " + + "[component=" + component + "]."); + } } /** @@ -307,6 +346,9 @@ public class BundledComponentRepository /** A table of component classes. */ protected HashMap _classes; + /** A table of component lists indexed on classname. */ + protected HashMap _classComps = new HashMap(); + /** The component table. */ protected HashIntMap _components = new HashIntMap(); }