use of org.terasology.entitySystem.prefab.PrefabData in project Terasology by MovingBlocks.
the class PrefabSerializer method deserialize.
/**
* Deserializes a prefab
*
* @param prefabData
* @param deltas
* @return The deserialized prefab
*/
public PrefabData deserialize(EntityData.Prefab prefabData, List<EntityData.Prefab> deltas) {
Module context = ModuleContext.getContext();
PrefabData result = new PrefabData();
deserializeCommonData(prefabData, result);
for (EntityData.Prefab delta : deltas) {
applyCommonDataDelta(delta, result);
}
addInheritedComponents(result);
applyComponentChanges(context, prefabData, result);
for (EntityData.Prefab delta : deltas) {
applyComponentChanges(context, delta, result);
}
return result;
}
use of org.terasology.entitySystem.prefab.PrefabData in project Terasology by MovingBlocks.
the class WorldSerializerImpl method createPrefab.
private void createPrefab(EntityData.Prefab prefabData) {
SimpleUri uri = new SimpleUri(prefabData.getName());
try (ModuleContext.ContextSpan ignored = ModuleContext.setContext(moduleManager.getEnvironment().get(uri.getModuleName()))) {
PrefabData protoPrefab = prefabSerializer.deserialize(prefabData);
Assets.generateAsset(new ResourceUrn(prefabData.getName()), protoPrefab, Prefab.class);
} catch (Exception e) {
logger.error("Failed to create prefab {}", prefabData.getName());
}
}
use of org.terasology.entitySystem.prefab.PrefabData in project Terasology by MovingBlocks.
the class EntitySerializerTest method setup.
@Before
public void setup() {
context.put(NetworkSystem.class, mock(NetworkSystem.class));
EntitySystemSetupUtil.addReflectionBasedLibraries(context);
EntitySystemSetupUtil.addEntityManagementRelatedClasses(context);
entityManager = context.get(EngineEntityManager.class);
entityManager.getComponentLibrary().register(new SimpleUri("test", "gettersetter"), GetterSetterComponent.class);
entityManager.getComponentLibrary().register(new SimpleUri("test", "string"), StringComponent.class);
entityManager.getComponentLibrary().register(new SimpleUri("test", "integer"), IntegerComponent.class);
entitySerializer = new EntitySerializer(entityManager);
componentLibrary = entityManager.getComponentLibrary();
PrefabData prefabData = new PrefabData();
prefabData.addComponent(new StringComponent("Value"));
prefab = Assets.generateAsset(new ResourceUrn("test:Test"), prefabData, Prefab.class);
}
use of org.terasology.entitySystem.prefab.PrefabData in project Terasology by MovingBlocks.
the class EntityAwareWorldProviderTest method createPrefabWithString.
private Prefab createPrefabWithString(String urn, String text, AssetManager assetManager) {
PrefabData prefabData = new PrefabData();
prefabData.addComponent(new StringComponent(text));
return assetManager.loadAsset(new ResourceUrn(urn), prefabData, Prefab.class);
}
use of org.terasology.entitySystem.prefab.PrefabData in project Terasology by MovingBlocks.
the class PojoEntityManagerTest method setupClass.
@BeforeClass
public static void setupClass() throws Exception {
context = new ContextImpl();
ModuleManager moduleManager = ModuleManagerFactory.create();
context.put(ModuleManager.class, moduleManager);
ModuleAwareAssetTypeManager assetTypeManager = new ModuleAwareAssetTypeManager();
assetTypeManager.registerCoreAssetType(Prefab.class, (AssetFactory<Prefab, PrefabData>) PojoPrefab::new, "prefabs");
assetTypeManager.switchEnvironment(moduleManager.getEnvironment());
context.put(AssetManager.class, assetTypeManager.getAssetManager());
CoreRegistry.setContext(context);
}
Aggregations