@Override public String toString() { return "ComponentMapper[" + type.getType().getSimpleName() + ']'; } }
@Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; LinkSite that = (LinkSite) o; return type.equals(that.type) && field.equals(that.field); }
/** * Get all components from all entities for a given type. * * @param type * the type of components to get * @return a bag containing all components of the given type */ protected Bag<Component> getComponentsByType(ComponentType type) { return mappers.get(type.getIndex()).components; }
@Override public int hashCode() { return type.hashCode() ^ field.hashCode(); }
private ComponentType createComponentType(Class<? extends Component> c) { try { Constructor ctor = ClassReflection.getConstructor(c); if ((ctor.getModifiers() & Modifier.PUBLIC) == 0) throw new InvalidComponentException(c, "missing public constructor"); } catch (ReflectionException e) { throw new InvalidComponentException(c, "missing public constructor", e); } ComponentType type = new ComponentType(c, types.size()); componentTypes.put(c, type); types.add(type); cm.registerComponentType(type, initialMapperCapacity); for (int i = 0; i < listeners.size(); i++) { listeners.get(i).onCreated(type); } return type; }
/** * Get the index of the component type of given component class. * * @param c * the component class to get the type index for * * @return the component type's index */ public int getIndexFor(Class<? extends Component> c) { return getTypeFor(c).getIndex(); }
@Override public int hashCode() { return type.hashCode() ^ field.hashCode(); }
private ComponentType createComponentType(Class<? extends Component> c) { try { Constructor ctor = ClassReflection.getConstructor(c); if ((ctor.getModifiers() & Modifier.PUBLIC) == 0) throw new InvalidComponentException(c, "missing public constructor"); } catch (ReflectionException e) { throw new InvalidComponentException(c, "missing public constructor", e); } ComponentType type = new ComponentType(c, types.size()); componentTypes.put(c, type); types.add(type); cm.registerComponentType(type, initialMapperCapacity); for (int i = 0; i < listeners.size(); i++) { listeners.get(i).onCreated(type); } return type; }
@Override public String toString() { return "ComponentMapper[" + type.getType().getSimpleName() + ']'; } }
/** * Get all components from all entities for a given type. * * @param type * the type of components to get * @return a bag containing all components of the given type */ protected Bag<Component> getComponentsByType(ComponentType type) { return mappers.get(type.getIndex()).components; }
@Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; LinkSite that = (LinkSite) o; return type.equals(that.type) && field.equals(that.field); }
@Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("TransmuteOperation("); if (additions.length > 0) { sb.append("add={"); String delim = ""; for (ComponentMapper mapper : additions) { sb.append(delim).append(mapper.getType().getType().getSimpleName()); delim = ", "; } sb.append("}"); } if (removals.length > 0) { if (additions.length > 0) sb.append(" "); sb.append("remove={"); String delim = ""; for (ComponentMapper mapper : removals) { sb.append(delim).append(mapper.getType().getType().getSimpleName()); delim = ", "; } sb.append("}"); } sb.append(")"); return sb.toString(); } }
/** * Get the index of the component type of given component class. * * @param c * the component class to get the type index for * * @return the component type's index */ public int getIndexFor(Class<? extends Component> c) { return getTypeFor(c).getIndex(); }
/** * <p>Injects and associates the listener with a specific field for a given * component type.</p> * * <p>Each <code>ComponentType::Field</code> pair can only have one {@link LinkListener}</p> * * @param component component type associated with listener * @param field target field for listener * @param listener link listener */ public void register(Class<? extends Component> component, String field, LinkListener listener) { world.inject(listener); try { Field f = (field != null) ? ClassReflection.getDeclaredField(component, field) : null; ComponentType ct = world.getComponentManager().getTypeFactory().getTypeFor(component); for (LinkSite site : linkSites) { if (ct.equals(site.type) && (f == null || site.field.equals(f))) { site.listener = listener; if (!decoratedLinkSites.contains(site)) decoratedLinkSites.add(site); if (fireEventsOnRegistration) site.inserted(site.subscription.getEntities()); } } } catch (ReflectionException e) { throw new RuntimeException(e); } }
private A createNew() { return (A) ((pool != null) ? pool.obtain() : ComponentManager.newInstance(type.getType())); }
/** Fetch mapper, or create if missing. */ @SuppressWarnings("unchecked") private <T extends Component> M<T> getCreateMapper(ComponentType type) { final int index = type.getIndex(); mappers.ensureCapacity(index); M m = mappers.get(index); if (m == null) { m = setMapper(index, type.getType()); } return m; }
/** * Get all components from all entities for a given type. * * @param type * the type of components to get * @return a bag containing all components of the given type */ protected Bag<Component> getComponentsByType(ComponentType type) { return mappers.get(type.getIndex()).components; }