use of org.terasology.persistence.serializers.PrefabSerializer in project Terasology by MovingBlocks.
the class CoreCommands method dumpEntities.
/**
* Writes out information on all entities to a text file for debugging
* @throws IOException thrown when error with saving file occures
*/
@Command(shortDescription = "Writes out information on all entities to a text file for debugging", helpText = "Writes entity information out into a file named \"entityDump.txt\".")
public void dumpEntities() throws IOException {
EngineEntityManager engineEntityManager = (EngineEntityManager) entityManager;
PrefabSerializer prefabSerializer = new PrefabSerializer(engineEntityManager.getComponentLibrary(), engineEntityManager.getTypeSerializerLibrary());
WorldDumper worldDumper = new WorldDumper(engineEntityManager, prefabSerializer);
worldDumper.save(PathManager.getInstance().getHomePath().resolve("entityDump.txt"));
}
use of org.terasology.persistence.serializers.PrefabSerializer in project Terasology by MovingBlocks.
the class PrefabFormat method load.
@Override
public PrefabData load(ResourceUrn resourceUrn, List<AssetDataFile> inputs) throws IOException {
try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputs.get(0).openStream(), Charsets.UTF_8))) {
EntityData.Prefab prefabData = EntityDataJSONFormat.readPrefab(reader);
if (prefabData != null) {
logger.info("Attempting to deserialize prefab {} with inputs {}", resourceUrn, inputs);
PrefabSerializer serializer = new PrefabSerializer(componentLibrary, typeSerializationLibrary);
return serializer.deserialize(prefabData);
} else {
throw new IOException("Failed to read prefab for '" + resourceUrn + "'");
}
}
}
use of org.terasology.persistence.serializers.PrefabSerializer in project Terasology by MovingBlocks.
the class WorldSerializerTest method testNotPersistedIfFlagedOtherwise.
@Test
public void testNotPersistedIfFlagedOtherwise() throws Exception {
EngineEntityManager entityManager = context.get(EngineEntityManager.class);
EntityBuilder entityBuilder = entityManager.newBuilder();
PrefabSerializer prefabSerializer = new PrefabSerializer(entityManager.getComponentLibrary(), entityManager.getTypeSerializerLibrary());
WorldSerializer worldSerializer = new WorldSerializerImpl(entityManager, prefabSerializer);
entityBuilder.setPersistent(false);
// just used to express that an entity got created
@SuppressWarnings("unused") EntityRef entity = entityBuilder.build();
EntityData.GlobalStore worldData = worldSerializer.serializeWorld(false);
assertEquals(0, worldData.getEntityCount());
}
use of org.terasology.persistence.serializers.PrefabSerializer in project Terasology by MovingBlocks.
the class PrefabDeltaFormat method apply.
@Override
public void apply(AssetDataFile assetDataFile, PrefabData assetData) throws IOException {
try (BufferedReader deltaReader = new BufferedReader(new InputStreamReader(assetDataFile.openStream(), Charsets.UTF_8))) {
EntityData.Prefab delta = EntityDataJSONFormat.readPrefab(deltaReader);
PrefabSerializer serializer = new PrefabSerializer(componentLibrary, typeSerializationLibrary);
serializer.deserializeDeltaOnto(delta, assetData);
}
}
Aggregations