Search in sources :

Example 1 with ComponentMetadata

use of org.terasology.engine.entitySystem.metadata.ComponentMetadata in project Terasology by MovingBlocks.

the class EntitySerializer method createInitialComponents.

/**
 * Creates the components for the entity being deserialized based on its prefab (if any)
 *
 * @param entityData
 * @return The mapping of components
 */
private Map<Class<? extends Component>, Component> createInitialComponents(EntityData.Entity entityData) {
    Set<ComponentMetadata<?>> removedComponents = Sets.newHashSet();
    for (String removedComp : entityData.getRemovedComponentList()) {
        ComponentMetadata<?> removedMetadata = componentLibrary.resolve(removedComp);
        if (removedMetadata != null) {
            removedComponents.add(removedMetadata);
        }
    }
    Map<Class<? extends Component>, Component> componentMap = Maps.newHashMap();
    if (entityData.hasParentPrefab() && !entityData.getParentPrefab().isEmpty() && prefabManager.exists(entityData.getParentPrefab())) {
        Prefab prefab = prefabManager.getPrefab(entityData.getParentPrefab());
        for (Component component : prefab.iterateComponents()) {
            ComponentMetadata<?> metadata = componentLibrary.getMetadata(component);
            if (!removedComponents.contains(metadata)) {
                componentMap.put(component.getClass(), componentLibrary.copy(component));
            }
        }
        componentMap.put(EntityInfoComponent.class, new EntityInfoComponent(prefab, true, prefab.isAlwaysRelevant()));
    }
    return componentMap;
}
Also used : ComponentMetadata(org.terasology.engine.entitySystem.metadata.ComponentMetadata) EntityInfoComponent(org.terasology.engine.entitySystem.entity.internal.EntityInfoComponent) Component(org.terasology.gestalt.entitysystem.component.Component) Prefab(org.terasology.engine.entitySystem.prefab.Prefab) EntityInfoComponent(org.terasology.engine.entitySystem.entity.internal.EntityInfoComponent)

Aggregations

EntityInfoComponent (org.terasology.engine.entitySystem.entity.internal.EntityInfoComponent)1 ComponentMetadata (org.terasology.engine.entitySystem.metadata.ComponentMetadata)1 Prefab (org.terasology.engine.entitySystem.prefab.Prefab)1 Component (org.terasology.gestalt.entitysystem.component.Component)1