use of org.terasology.gestalt.assets.ResourceUrn in project Terasology by MovingBlocks.
the class AbstractEditorScreen method loadAutosave.
/**
* Resets the editor based on the state of the autosave file.
*/
protected void loadAutosave() {
if (!disableAutosave) {
try (JsonReader reader = new JsonReader(new InputStreamReader(Files.newInputStream(getAutosaveFile())))) {
reader.setLenient(true);
String autosaveString = new JsonParser().parse(reader).toString();
JsonObject autosaveObject = new JsonParser().parse(autosaveString).getAsJsonObject();
String selectedAsset = autosaveObject.get("selectedAsset").getAsString();
setSelectedAsset(selectedAsset);
try {
ResourceUrn urn = new ResourceUrn(selectedAsset);
setSelectedAssetPath(urn);
} catch (InvalidUrnException ignored) {
}
JsonTree editorContents = JsonTreeConverter.serialize(autosaveObject.get("editorContents"));
resetState(editorContents);
setUnsavedChangesPresent(true);
} catch (NoSuchFileException ignored) {
} catch (IOException e) {
logger.warn("Could not load autosaved info", e);
}
}
}
use of org.terasology.gestalt.assets.ResourceUrn in project Terasology by MovingBlocks.
the class EntitySerializerTest method testComponentWithDoNotPersistIsNotPersisted.
@Test
public void testComponentWithDoNotPersistIsNotPersisted() {
componentLibrary.register(new ResourceUrn("test", "nonpersisted"), NonpersistedComponent.class);
EntityRef entity = entityManager.create();
entity.addComponent(new NonpersistedComponent());
entitySerializer.setComponentSerializeCheck(new PersistenceComponentSerializeCheck());
EntityData.Entity entityData = entitySerializer.serialize(entity);
long nextId = entityManager.getNextId();
entityManager.clear();
entityManager.setNextId(nextId);
EntityRef loadedEntity = entitySerializer.deserialize(entityData);
assertTrue(loadedEntity.exists());
assertFalse(loadedEntity.hasComponent(NonpersistedComponent.class));
}
use of org.terasology.gestalt.assets.ResourceUrn in project Terasology by MovingBlocks.
the class EntitySerializerTest method testComponentWithDoNotPersistIsIgnoredUponDeserialization.
@Test
public void testComponentWithDoNotPersistIsIgnoredUponDeserialization() {
componentLibrary.register(new ResourceUrn("test", "nonpersisted"), NonpersistedComponent.class);
EntityRef entity = entityManager.create();
entity.addComponent(new NonpersistedComponent());
entitySerializer.setComponentSerializeCheck(metadata -> true);
EntityData.Entity entityData = entitySerializer.serialize(entity);
long nextId = entityManager.getNextId();
entityManager.clear();
entityManager.setNextId(nextId);
entitySerializer.setComponentSerializeCheck(new PersistenceComponentSerializeCheck());
EntityRef loadedEntity = entitySerializer.deserialize(entityData);
assertTrue(loadedEntity.exists());
assertFalse(loadedEntity.hasComponent(NonpersistedComponent.class));
}
use of org.terasology.gestalt.assets.ResourceUrn in project Terasology by MovingBlocks.
the class EntitySerializerTest method testMappedTypeHandling.
@Test
public void testMappedTypeHandling() throws Exception {
componentLibrary.register(new ResourceUrn("test", "mappedtype"), MappedTypeComponent.class);
EntityRef entity = entityManager.create();
entity.addComponent(new MappedTypeComponent());
EntityData.Entity entityData = entitySerializer.serialize(entity);
long nextId = entityManager.getNextId();
entityManager.clear();
entityManager.setNextId(nextId);
EntityRef loadedEntity = entitySerializer.deserialize(entityData);
assertTrue(loadedEntity.exists());
assertTrue(loadedEntity.hasComponent(MappedTypeComponent.class));
}
use of org.terasology.gestalt.assets.ResourceUrn in project Terasology by MovingBlocks.
the class ComponentSerializerTest method setup.
@BeforeEach
public void setup() {
context = new ContextImpl();
context.put(RecordAndReplayCurrentStatus.class, new RecordAndReplayCurrentStatus());
context.put(ModuleManager.class, moduleManager);
CoreRegistry.setContext(context);
Reflections reflections = new Reflections(getClass().getClassLoader());
TypeHandlerLibrary serializationLibrary = new TypeHandlerLibraryImpl(reflections);
serializationLibrary.addTypeHandler(Vector3f.class, new Vector3fTypeHandler());
serializationLibrary.addTypeHandler(Quaternionf.class, new QuaternionfTypeHandler());
NetworkSystem networkSystem = mock(NetworkSystem.class);
when(networkSystem.getMode()).thenReturn(NetworkMode.NONE);
context.put(NetworkSystem.class, networkSystem);
EntitySystemSetupUtil.addReflectionBasedLibraries(context);
EntitySystemSetupUtil.addEntityManagementRelatedClasses(context);
EngineEntityManager entityManager = context.get(EngineEntityManager.class);
entityManager.getComponentLibrary().register(new ResourceUrn("test", "gettersetter"), GetterSetterComponent.class);
entityManager.getComponentLibrary().register(new ResourceUrn("test", "string"), StringComponent.class);
entityManager.getComponentLibrary().register(new ResourceUrn("test", "integer"), IntegerComponent.class);
ComponentLibrary componentLibrary = entityManager.getComponentLibrary();
componentSerializer = new ComponentSerializer(componentLibrary, serializationLibrary);
}
Aggregations