use of org.terasology.reflection.reflect.ReflectionReflectFactory in project Terasology by MovingBlocks.
the class PojoPrefabManagerTest method setup.
@Before
public void setup() throws Exception {
ContextImpl context = new ContextImpl();
CoreRegistry.setContext(context);
ModuleManager moduleManager = ModuleManagerFactory.create();
ReflectFactory reflectFactory = new ReflectionReflectFactory();
CopyStrategyLibrary copyStrategyLibrary = new CopyStrategyLibrary(reflectFactory);
TypeSerializationLibrary lib = new TypeSerializationLibrary(reflectFactory, copyStrategyLibrary);
lib.add(Vector3f.class, new Vector3fTypeHandler());
lib.add(Quat4f.class, new Quat4fTypeHandler());
entitySystemLibrary = new EntitySystemLibrary(context, lib);
componentLibrary = entitySystemLibrary.getComponentLibrary();
ModuleAwareAssetTypeManager assetTypeManager = new ModuleAwareAssetTypeManager();
assetTypeManager.registerCoreAssetType(Prefab.class, (AssetFactory<Prefab, PrefabData>) PojoPrefab::new, "prefabs");
assetTypeManager.switchEnvironment(moduleManager.getEnvironment());
context.put(AssetManager.class, assetTypeManager.getAssetManager());
prefabManager = new PojoPrefabManager(context);
}
use of org.terasology.reflection.reflect.ReflectionReflectFactory in project Terasology by MovingBlocks.
the class EntitySystemSetupUtil method addReflectionBasedLibraries.
public static void addReflectionBasedLibraries(Context context) {
ReflectionReflectFactory reflectFactory = new ReflectionReflectFactory();
context.put(ReflectFactory.class, reflectFactory);
CopyStrategyLibrary copyStrategyLibrary = new CopyStrategyLibrary(reflectFactory);
context.put(CopyStrategyLibrary.class, copyStrategyLibrary);
ModuleManager moduleManager = context.get(ModuleManager.class);
TypeRegistry typeRegistry = context.get(TypeRegistry.class);
TypeHandlerLibrary typeHandlerLibrary = TypeHandlerLibraryImpl.forModuleEnvironment(moduleManager, typeRegistry);
context.put(TypeHandlerLibrary.class, typeHandlerLibrary);
EntitySystemLibrary library = new EntitySystemLibrary(context, typeHandlerLibrary);
context.put(EntitySystemLibrary.class, library);
context.put(ComponentLibrary.class, library.getComponentLibrary());
context.put(EventLibrary.class, library.getEventLibrary());
}
use of org.terasology.reflection.reflect.ReflectionReflectFactory in project Terasology by MovingBlocks.
the class UniverseSetupScreen method setEnvironment.
/**
* This method switches the environment of the game to a temporary one needed for
* creating a game. It creates a new {@link Context} and only puts the minimum classes
* needed for successful game creation.
* @param wrapper takes the {@link AdvancedGameSetupScreen} and pushes it into the new context.
*/
public void setEnvironment(UniverseWrapper wrapper) {
context = new ContextImpl();
CoreRegistry.setContext(context);
ReflectFactory reflectFactory = new ReflectionReflectFactory();
context.put(ReflectFactory.class, reflectFactory);
CopyStrategyLibrary copyStrategyLibrary = new CopyStrategyLibrary(reflectFactory);
context.put(CopyStrategyLibrary.class, copyStrategyLibrary);
context.put(NUIManager.class, getManager());
context.put(UniverseSetupScreen.class, this);
assetTypeManager = new AutoReloadAssetTypeManager();
context.put(AssetManager.class, assetTypeManager.getAssetManager());
context.put(ModuleAwareAssetTypeManager.class, assetTypeManager);
context.put(ModuleManager.class, moduleManager);
context.put(UniverseWrapper.class, wrapper);
DependencyResolver resolver = new DependencyResolver(moduleManager.getRegistry());
ResolutionResult result = resolver.resolve(config.getDefaultModSelection().listModules());
if (result.isSuccess()) {
environment = moduleManager.loadEnvironment(result.getModules(), false);
context.put(ModuleEnvironment.class, environment);
context.put(WorldGeneratorPluginLibrary.class, new TempWorldGeneratorPluginLibrary(environment, context));
initAssets();
EnvironmentSwitchHandler environmentSwitcher = new EnvironmentSwitchHandler();
context.put(EnvironmentSwitchHandler.class, environmentSwitcher);
environmentSwitcher.handleSwitchToPreviewEnvironment(context, environment);
}
}
Aggregations