use of org.terasology.persistence.typeHandling.TypeSerializationLibrary in project Terasology by MovingBlocks.
the class PojoEventSystemTests method setup.
@Before
public void setup() {
ContextImpl context = new ContextImpl();
CoreRegistry.setContext(context);
ReflectFactory reflectFactory = new ReflectionReflectFactory();
CopyStrategyLibrary copyStrategies = new CopyStrategyLibrary(reflectFactory);
TypeSerializationLibrary serializationLibrary = new TypeSerializationLibrary(reflectFactory, copyStrategies);
EntitySystemLibrary entitySystemLibrary = new EntitySystemLibrary(context, serializationLibrary);
compLibrary = entitySystemLibrary.getComponentLibrary();
entityManager = new PojoEntityManager();
entityManager.setComponentLibrary(entitySystemLibrary.getComponentLibrary());
entityManager.setPrefabManager(new PojoPrefabManager(context));
NetworkSystem networkSystem = mock(NetworkSystem.class);
when(networkSystem.getMode()).thenReturn(NetworkMode.NONE);
eventSystem = new EventSystemImpl(entitySystemLibrary.getEventLibrary(), networkSystem);
entityManager.setEventSystem(eventSystem);
entity = entityManager.create();
}
use of org.terasology.persistence.typeHandling.TypeSerializationLibrary in project Terasology by MovingBlocks.
the class PrefabTest method setup.
@Before
public void setup() throws Exception {
ContextImpl context = new ContextImpl();
CoreRegistry.setContext(context);
ModuleManager moduleManager = ModuleManagerFactory.create();
context.put(ModuleManager.class, moduleManager);
EntitySystemSetupUtil.addReflectionBasedLibraries(context);
ModuleAwareAssetTypeManager assetTypeManager = new ModuleAwareAssetTypeManager();
assetTypeManager.registerCoreAssetType(Prefab.class, (AssetFactory<Prefab, PrefabData>) PojoPrefab::new, "prefabs");
ComponentLibrary componentLibrary = context.get(ComponentLibrary.class);
TypeSerializationLibrary typeSerializationLibrary = context.get(TypeSerializationLibrary.class);
PrefabFormat prefabFormat = new PrefabFormat(componentLibrary, typeSerializationLibrary);
assetTypeManager.registerCoreFormat(Prefab.class, prefabFormat);
assetTypeManager.switchEnvironment(moduleManager.getEnvironment());
context.put(AssetManager.class, assetTypeManager.getAssetManager());
NetworkSystem networkSystem = mock(NetworkSystem.class);
when(networkSystem.getMode()).thenReturn(NetworkMode.NONE);
context.put(NetworkSystem.class, networkSystem);
EntitySystemSetupUtil.addEntityManagementRelatedClasses(context);
prefabManager = new PojoPrefabManager(context);
}
use of org.terasology.persistence.typeHandling.TypeSerializationLibrary in project Terasology by MovingBlocks.
the class HeadlessEnvironment method setupBlockManager.
@Override
protected void setupBlockManager(AssetManager assetManager) {
WorldAtlas worldAtlas = new NullWorldAtlas();
BlockManagerImpl blockManager = new BlockManagerImpl(worldAtlas, assetManager);
context.put(BlockManager.class, blockManager);
TypeSerializationLibrary typeSerializationLibrary = context.get(TypeSerializationLibrary.class);
typeSerializationLibrary.add(BlockFamily.class, new BlockFamilyTypeHandler(blockManager));
typeSerializationLibrary.add(Block.class, new BlockTypeHandler(blockManager));
}
use of org.terasology.persistence.typeHandling.TypeSerializationLibrary in project Terasology by MovingBlocks.
the class UIFormat method load.
public UIData load(JsonElement element, Locale otherLocale) throws IOException {
NUIManager nuiManager = CoreRegistry.get(NUIManager.class);
TranslationSystem translationSystem = CoreRegistry.get(TranslationSystem.class);
TypeSerializationLibrary library = new TypeSerializationLibrary(CoreRegistry.get(TypeSerializationLibrary.class));
library.add(UISkin.class, new AssetTypeHandler<>(UISkin.class));
library.add(Border.class, new BorderTypeHandler());
GsonBuilder gsonBuilder = new GsonBuilder().registerTypeAdapterFactory(new CaseInsensitiveEnumTypeAdapterFactory()).registerTypeAdapter(UIData.class, new UIDataTypeAdapter()).registerTypeHierarchyAdapter(UIWidget.class, new UIWidgetTypeAdapter(nuiManager));
for (Class<?> handledType : library.getCoreTypes()) {
gsonBuilder.registerTypeAdapter(handledType, new JsonTypeHandlerAdapter<>(library.getHandlerFor(handledType)));
}
// override the String TypeAdapter from the serialization library
gsonBuilder.registerTypeAdapter(String.class, new I18nStringTypeAdapter(translationSystem, otherLocale));
Gson gson = gsonBuilder.create();
return gson.fromJson(element, UIData.class);
}
use of org.terasology.persistence.typeHandling.TypeSerializationLibrary in project Terasology by MovingBlocks.
the class TerasologyEngine method initManagers.
private void initManagers() {
changeStatus(TerasologyEngineStatus.INITIALIZING_MODULE_MANAGER);
ModuleManager moduleManager = new ModuleManagerImpl(rootContext.get(Config.class));
rootContext.put(ModuleManager.class, moduleManager);
changeStatus(TerasologyEngineStatus.INITIALIZING_LOWLEVEL_OBJECT_MANIPULATION);
ReflectFactory reflectFactory = new ReflectionReflectFactory();
rootContext.put(ReflectFactory.class, reflectFactory);
CopyStrategyLibrary copyStrategyLibrary = new CopyStrategyLibrary(reflectFactory);
rootContext.put(CopyStrategyLibrary.class, copyStrategyLibrary);
rootContext.put(TypeSerializationLibrary.class, new TypeSerializationLibrary(reflectFactory, copyStrategyLibrary));
changeStatus(TerasologyEngineStatus.INITIALIZING_ASSET_TYPES);
assetTypeManager = new ModuleAwareAssetTypeManager();
rootContext.put(ModuleAwareAssetTypeManager.class, assetTypeManager);
rootContext.put(AssetManager.class, assetTypeManager.getAssetManager());
}
Aggregations