/// <summary> /// Saves a component to an entity /// </summary> /// <param name="entityId"> </param> /// <param name="component"> </param> public override void saveComponent(int entityId, Component component) { Component oldComponent = store.put(entityId, component); if (oldComponent == null) { logger.error("Saving a component ({}) that doesn't belong to this entity {}", component.GetType(), entityId); } if (eventSystem != null) { EntityRef entityRef = createEntityRef(entityId); if (oldComponent == null) { eventSystem.send(entityRef, OnAddedComponent.newInstance(), component); eventSystem.send(entityRef, OnActivatedComponent.newInstance(), component); } else { eventSystem.send(entityRef, OnChangedComponent.newInstance(), component); } } if (oldComponent == null) { notifyComponentAdded(getEntity(entityId), component.GetType()); } else { notifyComponentChanged(getEntity(entityId), component.GetType()); } }
/// <summary> /// Adds (or replaces) a component to an entity /// </summary> /// <param name="entityId"> </param> /// <param name="component"> </param> /// @param <T> </param> /// <returns> The added component </returns> public override T addComponent <T>(int entityId, T component) where T : org.terasology.entitySystem.Component { Preconditions.checkNotNull(component); Component oldComponent = store.put(entityId, component); if (oldComponent != null) { logger.error("Adding a component ({}) over an existing component for entity {}", component.GetType(), entityId); } if (eventSystem != null) { EntityRef entityRef = createEntityRef(entityId); if (oldComponent == null) { eventSystem.send(entityRef, OnAddedComponent.newInstance(), component); eventSystem.send(entityRef, OnActivatedComponent.newInstance(), component); } else { eventSystem.send(entityRef, OnChangedComponent.newInstance(), component); } } if (oldComponent == null) { notifyComponentAdded(getEntity(entityId), component.GetType()); } else { notifyComponentChanged(getEntity(entityId), component.GetType()); } return(component); }
public override EntityRef create(IEnumerable <Component> components) { EntityRef entity = createEntity(components); if (eventSystem != null) { eventSystem.send(entity, OnAddedComponent.newInstance()); eventSystem.send(entity, OnActivatedComponent.newInstance()); } return(entity); }
public override EntityRef createEntityWithId(int id, IEnumerable <Component> components) { if (!freedIds.contains(id)) { foreach (Component c in components) { store.put(id, c); } loadedIds.add(id); EntityRef entity = createEntityRef(id); if (eventSystem != null) { eventSystem.send(entity, OnActivatedComponent.newInstance()); } return(entity); } return(EntityRef.NULL); }