use of org.terasology.entitySystem.metadata.EntitySystemLibrary in project Terasology by MovingBlocks.
the class EnvironmentSwitchHandler method handleSwitchToGameEnvironment.
@SuppressWarnings("unchecked")
public void handleSwitchToGameEnvironment(Context context) {
ModuleManager moduleManager = context.get(ModuleManager.class);
CopyStrategyLibrary copyStrategyLibrary = context.get(CopyStrategyLibrary.class);
copyStrategyLibrary.clear();
for (Class<? extends CopyStrategy> copyStrategy : moduleManager.getEnvironment().getSubtypesOf(CopyStrategy.class)) {
if (copyStrategy.getAnnotation(RegisterCopyStrategy.class) == null) {
continue;
}
Class<?> targetType = ReflectionUtil.getTypeParameterForSuper(copyStrategy, CopyStrategy.class, 0);
if (targetType != null) {
registerCopyStrategy(copyStrategyLibrary, targetType, copyStrategy);
} else {
logger.error("Cannot register CopyStrategy '{}' - unable to determine target type", copyStrategy);
}
}
ReflectFactory reflectFactory = context.get(ReflectFactory.class);
TypeSerializationLibrary typeSerializationLibrary = TypeSerializationLibrary.createDefaultLibrary(reflectFactory, copyStrategyLibrary);
typeSerializationLibrary.add(CollisionGroup.class, new CollisionGroupTypeHandler(context.get(CollisionGroupManager.class)));
context.put(TypeSerializationLibrary.class, typeSerializationLibrary);
// Entity System Library
EntitySystemLibrary library = new EntitySystemLibrary(context, typeSerializationLibrary);
context.put(EntitySystemLibrary.class, library);
ComponentLibrary componentLibrary = library.getComponentLibrary();
context.put(ComponentLibrary.class, componentLibrary);
context.put(EventLibrary.class, library.getEventLibrary());
context.put(ClassMetaLibrary.class, new ClassMetaLibraryImpl(context));
registerComponents(componentLibrary, moduleManager.getEnvironment());
registerTypeHandlers(context, typeSerializationLibrary, moduleManager.getEnvironment());
BlockFamilyFactoryRegistry blockFamilyFactoryRegistry = context.get(BlockFamilyFactoryRegistry.class);
loadFamilies((DefaultBlockFamilyFactoryRegistry) blockFamilyFactoryRegistry, moduleManager.getEnvironment());
ModuleAwareAssetTypeManager assetTypeManager = context.get(ModuleAwareAssetTypeManager.class);
/*
* The registering of the prefab formats is done in this method, because it needs to be done before
* the environment of the asset manager gets changed.
*
* It can't be done before this method gets called because the ComponentLibrary isn't
* existing then yet.
*/
unregisterPrefabFormats(assetTypeManager);
registeredPrefabFormat = new PrefabFormat(componentLibrary, typeSerializationLibrary);
assetTypeManager.registerCoreFormat(Prefab.class, registeredPrefabFormat);
registeredPrefabDeltaFormat = new PrefabDeltaFormat(componentLibrary, typeSerializationLibrary);
assetTypeManager.registerCoreDeltaFormat(Prefab.class, registeredPrefabDeltaFormat);
assetTypeManager.switchEnvironment(moduleManager.getEnvironment());
}
use of org.terasology.entitySystem.metadata.EntitySystemLibrary 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);
TypeSerializationLibrary typeSerializationLibrary = TypeSerializationLibrary.createDefaultLibrary(reflectFactory, copyStrategyLibrary);
context.put(TypeSerializationLibrary.class, typeSerializationLibrary);
EntitySystemLibrary library = new EntitySystemLibrary(context, typeSerializationLibrary);
context.put(EntitySystemLibrary.class, library);
context.put(ComponentLibrary.class, library.getComponentLibrary());
context.put(EventLibrary.class, library.getEventLibrary());
}
use of org.terasology.entitySystem.metadata.EntitySystemLibrary in project Terasology by MovingBlocks.
the class EntitySystemSetupUtil method addEntityManagementRelatedClasses.
/**
* Objects for the following classes must be available in the context:
* <ul>
* <li>{@link ModuleEnvironment}</li>
* <li>{@link NetworkSystem}</li>
* <li>{@link ReflectFactory}</li>
* <li>{@link CopyStrategyLibrary}</li>
* <li>{@link org.terasology.persistence.typeHandling.TypeSerializationLibrary}</li>
* </ul>
* <p>
* The method will make objects for the following classes available in the context:
* <ul>
* <li>{@link EngineEntityManager}</li>
* <li>{@link ComponentLibrary}</li>
* <li>{@link EventLibrary}</li>
* <li>{@link PrefabManager}</li>
* <li>{@link EventSystem}</li>
* </ul>
*/
public static void addEntityManagementRelatedClasses(Context context) {
ModuleEnvironment environment = context.get(ModuleManager.class).getEnvironment();
NetworkSystem networkSystem = context.get(NetworkSystem.class);
// Entity Manager
PojoEntityManager entityManager = new PojoEntityManager();
context.put(EntityManager.class, entityManager);
context.put(EngineEntityManager.class, entityManager);
// Standard serialization library
TypeSerializationLibrary typeSerializationLibrary = context.get(TypeSerializationLibrary.class);
typeSerializationLibrary.add(EntityRef.class, new EntityRefTypeHandler(entityManager));
entityManager.setTypeSerializerLibrary(typeSerializationLibrary);
// Prefab Manager
PrefabManager prefabManager = new PojoPrefabManager(context);
entityManager.setPrefabManager(prefabManager);
context.put(PrefabManager.class, prefabManager);
EntitySystemLibrary library = context.get(EntitySystemLibrary.class);
entityManager.setComponentLibrary(library.getComponentLibrary());
// Event System
EventSystem eventSystem = new EventSystemImpl(library.getEventLibrary(), networkSystem);
entityManager.setEventSystem(eventSystem);
context.put(EventSystem.class, eventSystem);
// TODO: Review - NodeClassLibrary related to the UI for behaviours. Should not be here and probably not even in the CoreRegistry
context.put(OneOfProviderFactory.class, new OneOfProviderFactory());
registerComponents(library.getComponentLibrary(), environment);
registerEvents(entityManager.getEventSystem(), environment);
}
use of org.terasology.entitySystem.metadata.EntitySystemLibrary 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.entitySystem.metadata.EntitySystemLibrary 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);
}
Aggregations