use of org.terasology.persistence.typeHandling.TypeHandlerLibrary in project Terasology by MovingBlocks.
the class ConfigurationSubsystem method initialise.
@Override
public void initialise(GameEngine engine, Context rootContext) {
// TODO: Put here because of TypeHandlerLibrary dependency,
// might need to move to preInitialise or elsewhere
TypeHandlerLibrary typeHandlerLibrary = rootContext.get(TypeHandlerLibrary.class);
Gson gson = new GsonBuilder().setPrettyPrinting().create();
Serializer<GsonPersistedData> serializer = new Serializer<>(typeHandlerLibrary, new GsonPersistedDataSerializer(), new GsonPersistedDataWriter(gson), new GsonPersistedDataReader(gson));
autoConfigManager = new AutoConfigManager(serializer);
typeHandlerLibrary.addTypeHandlerFactory(new AutoConfigTypeHandlerFactory(typeHandlerLibrary));
rootContext.put(AutoConfigManager.class, autoConfigManager);
autoConfigManager.loadConfigsIn(rootContext);
}
use of org.terasology.persistence.typeHandling.TypeHandlerLibrary 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.persistence.typeHandling.TypeHandlerLibrary in project Terasology by MovingBlocks.
the class NetworkSystemImpl method connectToEntitySystem.
@Override
public void connectToEntitySystem(EngineEntityManager newEntityManager, EventLibrary newEventLibrary, BlockEntityRegistry blockEntityRegistry) {
if (this.entityManager != null) {
this.entityManager.unsubscribe(this);
}
this.entityManager = newEntityManager;
this.entityManager.subscribeForChanges(this);
this.blockManager = context.get(BlockManager.class);
this.ownershipHelper = new OwnershipHelper(newEntityManager.getComponentLibrary());
this.storageManager = context.get(StorageManager.class);
this.eventLibrary = newEventLibrary;
this.componentLibrary = entityManager.getComponentLibrary();
context.get(ComponentSystemManager.class).register(new NetworkEntitySystem(this), "engine:networkEntitySystem");
TypeHandlerLibrary typeHandlerLibrary = entityManager.getTypeSerializerLibrary().copy();
typeHandlerLibrary.addTypeHandler(EntityRef.class, new NetEntityRefTypeHandler(this, blockEntityRegistry));
// TODO: Add network override types here (that use id lookup tables)
eventSerializer = new EventSerializer(eventLibrary, typeHandlerLibrary);
entitySerializer = new NetworkEntitySerializer(newEntityManager, entityManager.getComponentLibrary(), typeHandlerLibrary);
entitySerializer.setComponentSerializeCheck(new NetComponentSerializeCheck());
if (mode == NetworkMode.CLIENT) {
entityManager.setEntityRefStrategy(new NetworkClientRefStrategy(this));
applySerializationTables();
}
if (server != null) {
server.connectToEntitySystem(newEntityManager, entitySerializer, eventSerializer, blockEntityRegistry);
}
}
use of org.terasology.persistence.typeHandling.TypeHandlerLibrary in project Terasology by MovingBlocks.
the class TypeHandlerLibraryImpl method withReflections.
public static TypeHandlerLibrary withReflections(Reflections reflections) {
TypeHandlerLibrary library = new TypeHandlerLibraryImpl(reflections);
populateWithDefaultHandlers(library);
return library;
}
Aggregations