use of org.terasology.entitySystem.Component in project Terasology by MovingBlocks.
the class ParticleUpdaterImpl method configureEmitter.
@Override
public void configureEmitter(final ParticleEmitterComponent emitter, final BiMap<Class<Component>, AffectorFunction> registeredAffectorFunctions, final BiMap<Class<Component>, GeneratorFunction> registeredGeneratorFunctions) {
emitter.generatorFunctionMap.clear();
emitter.affectorFunctionMap.clear();
for (Component c : emitter.ownerEntity.iterateComponents()) {
if (registeredGeneratorFunctions.containsKey(c.getClass())) {
emitter.generatorFunctionMap.put(c, registeredGeneratorFunctions.get(c.getClass()));
} else if (registeredAffectorFunctions.containsKey(c.getClass())) {
emitter.affectorFunctionMap.put(c, registeredAffectorFunctions.get(c.getClass()));
}
}
}
use of org.terasology.entitySystem.Component in project Terasology by MovingBlocks.
the class EntitySetDeltaRecorder method onEntityComponentChange.
public void onEntityComponentChange(EntityRef entity, Class<? extends Component> componentClass) {
if (entity.isPersistent()) {
EntityDelta entityDelta = getOrCreateEntityDeltaFor(entity);
Component component = entity.getComponent(componentClass);
Component componentSnapshot = componentLibrary.copy(component);
entityDelta.setChangedComponent(componentSnapshot);
}
}
use of org.terasology.entitySystem.Component in project Terasology by MovingBlocks.
the class EntitySetDeltaRecorder method onReactivation.
public void onReactivation(EntityRef entity, Collection<Component> components) {
if (entity.isPersistent()) {
EntityDelta entityDelta = getOrCreateEntityDeltaFor(entity);
for (Component component : components) {
Component componentSnapshot = componentLibrary.copy(component);
entityDelta.setChangedComponent(componentSnapshot);
}
}
}
use of org.terasology.entitySystem.Component in project Terasology by MovingBlocks.
the class GlobalStoreBuilder method build.
public EntityData.GlobalStore build(EngineEntityManager entityManager, Iterable<EntityRef> entities) {
EntityData.GlobalStore.Builder store = EntityData.GlobalStore.newBuilder();
Map<Class<? extends Component>, Integer> componentIdTable = Maps.newHashMap();
for (ComponentMetadata<?> componentMetadata : entityManager.getComponentLibrary().iterateComponentMetadata()) {
store.addComponentClass(componentMetadata.getUri().toString());
componentIdTable.put(componentMetadata.getType(), componentIdTable.size());
}
prefabSerializer.setComponentIdMapping(componentIdTable);
/*
* The prefabs can't be obtained from entityManager.getPrefabManager().listPrefabs() as that might not
* be thread save.
*/
Set<Prefab> prefabsRequiredForEntityStorage = new HashSet<>();
for (EntityRef entityRef : entityManager.getAllEntities()) {
Prefab prefab = entityRef.getParentPrefab();
if (prefab != null) {
prefabsRequiredForEntityStorage.add(prefab);
}
}
for (Prefab prefab : prefabsRequiredForEntityStorage) {
store.addPrefab(prefabSerializer.serialize(prefab));
}
EntitySerializer entitySerializer = new EntitySerializer(entityManager);
entitySerializer.setComponentIdMapping(componentIdTable);
for (EntityRef entity : entities) {
if (entity.isPersistent()) {
store.addEntity(entitySerializer.serialize(entity));
}
}
store.setNextEntityId(nextEntityId);
return store.build();
}
use of org.terasology.entitySystem.Component in project Terasology by MovingBlocks.
the class PrefabData method createFromPrefab.
public static PrefabData createFromPrefab(Prefab prefab) {
PrefabData result = new PrefabData();
for (Component component : prefab.iterateComponents()) {
result.addComponent(component);
}
result.setAlwaysRelevant(prefab.isAlwaysRelevant());
result.setParent(prefab.getParent());
result.setPersisted(prefab.isPersisted());
return result;
}
Aggregations