Search in sources :

Example 1 with PrefabSerializer

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"));
}
Also used : EngineEntityManager(org.terasology.entitySystem.entity.internal.EngineEntityManager) WorldDumper(org.terasology.persistence.WorldDumper) PrefabSerializer(org.terasology.persistence.serializers.PrefabSerializer) Command(org.terasology.logic.console.commandSystem.annotations.Command) ConsoleCommand(org.terasology.logic.console.commandSystem.ConsoleCommand)

Example 2 with PrefabSerializer

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 + "'");
        }
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) EntityData(org.terasology.protobuf.EntityData) IOException(java.io.IOException) PrefabSerializer(org.terasology.persistence.serializers.PrefabSerializer)

Example 3 with PrefabSerializer

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());
}
Also used : EngineEntityManager(org.terasology.entitySystem.entity.internal.EngineEntityManager) EntityData(org.terasology.protobuf.EntityData) EntityBuilder(org.terasology.entitySystem.entity.EntityBuilder) WorldSerializerImpl(org.terasology.persistence.serializers.WorldSerializerImpl) WorldSerializer(org.terasology.persistence.serializers.WorldSerializer) EntityRef(org.terasology.entitySystem.entity.EntityRef) PrefabSerializer(org.terasology.persistence.serializers.PrefabSerializer) Test(org.junit.Test)

Example 4 with PrefabSerializer

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);
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) EntityData(org.terasology.protobuf.EntityData) PrefabSerializer(org.terasology.persistence.serializers.PrefabSerializer)

Aggregations

PrefabSerializer (org.terasology.persistence.serializers.PrefabSerializer)4 EntityData (org.terasology.protobuf.EntityData)3 BufferedReader (java.io.BufferedReader)2 InputStreamReader (java.io.InputStreamReader)2 EngineEntityManager (org.terasology.entitySystem.entity.internal.EngineEntityManager)2 IOException (java.io.IOException)1 Test (org.junit.Test)1 EntityBuilder (org.terasology.entitySystem.entity.EntityBuilder)1 EntityRef (org.terasology.entitySystem.entity.EntityRef)1 ConsoleCommand (org.terasology.logic.console.commandSystem.ConsoleCommand)1 Command (org.terasology.logic.console.commandSystem.annotations.Command)1 WorldDumper (org.terasology.persistence.WorldDumper)1 WorldSerializer (org.terasology.persistence.serializers.WorldSerializer)1 WorldSerializerImpl (org.terasology.persistence.serializers.WorldSerializerImpl)1