Search in sources :

Example 11 with TypeHandlerLibrary

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);
}
Also used : GsonPersistedDataSerializer(org.terasology.engine.persistence.typeHandling.gson.GsonPersistedDataSerializer) AutoConfigTypeHandlerFactory(org.terasology.engine.config.flexible.AutoConfigTypeHandlerFactory) GsonPersistedDataWriter(org.terasology.engine.persistence.typeHandling.gson.GsonPersistedDataWriter) GsonBuilder(com.google.gson.GsonBuilder) GsonPersistedData(org.terasology.engine.persistence.typeHandling.gson.GsonPersistedData) TypeHandlerLibrary(org.terasology.persistence.typeHandling.TypeHandlerLibrary) GsonPersistedDataReader(org.terasology.engine.persistence.typeHandling.gson.GsonPersistedDataReader) Gson(com.google.gson.Gson) AutoConfigManager(org.terasology.engine.config.flexible.AutoConfigManager) GsonPersistedDataSerializer(org.terasology.engine.persistence.typeHandling.gson.GsonPersistedDataSerializer) Serializer(org.terasology.persistence.serializers.Serializer)

Example 12 with TypeHandlerLibrary

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());
}
Also used : ReflectionReflectFactory(org.terasology.reflection.reflect.ReflectionReflectFactory) TypeHandlerLibrary(org.terasology.persistence.typeHandling.TypeHandlerLibrary) EntitySystemLibrary(org.terasology.engine.entitySystem.metadata.EntitySystemLibrary) CopyStrategyLibrary(org.terasology.reflection.copy.CopyStrategyLibrary) ModuleManager(org.terasology.engine.core.module.ModuleManager) TypeRegistry(org.terasology.reflection.TypeRegistry)

Example 13 with TypeHandlerLibrary

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);
    }
}
Also used : OwnershipHelper(org.terasology.engine.entitySystem.entity.internal.OwnershipHelper) BlockManager(org.terasology.engine.world.block.BlockManager) TypeHandlerLibrary(org.terasology.persistence.typeHandling.TypeHandlerLibrary) StorageManager(org.terasology.engine.persistence.StorageManager) NetworkEntitySerializer(org.terasology.engine.persistence.serializers.NetworkEntitySerializer) NetComponentSerializeCheck(org.terasology.engine.network.serialization.NetComponentSerializeCheck) NetEntityRefTypeHandler(org.terasology.engine.network.serialization.NetEntityRefTypeHandler) ComponentSystemManager(org.terasology.engine.core.ComponentSystemManager) EventSerializer(org.terasology.engine.persistence.serializers.EventSerializer)

Example 14 with TypeHandlerLibrary

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;
}
Also used : TypeHandlerLibrary(org.terasology.persistence.typeHandling.TypeHandlerLibrary)

Aggregations

TypeHandlerLibrary (org.terasology.persistence.typeHandling.TypeHandlerLibrary)14 ModuleManager (org.terasology.engine.core.module.ModuleManager)6 EntitySystemLibrary (org.terasology.engine.entitySystem.metadata.EntitySystemLibrary)6 BeforeEach (org.junit.jupiter.api.BeforeEach)5 ContextImpl (org.terasology.engine.context.internal.ContextImpl)5 PojoPrefabManager (org.terasology.engine.entitySystem.prefab.internal.PojoPrefabManager)4 NetworkSystem (org.terasology.engine.network.NetworkSystem)4 Reflections (org.reflections.Reflections)3 PojoEntityManager (org.terasology.engine.entitySystem.entity.internal.PojoEntityManager)3 ComponentLibrary (org.terasology.engine.entitySystem.metadata.ComponentLibrary)3 TypeHandlerLibraryImpl (org.terasology.engine.persistence.typeHandling.TypeHandlerLibraryImpl)3 RecordAndReplayCurrentStatus (org.terasology.engine.recording.RecordAndReplayCurrentStatus)3 ModuleEnvironment (org.terasology.gestalt.module.ModuleEnvironment)3 TypeRegistry (org.terasology.reflection.TypeRegistry)3 Gson (com.google.gson.Gson)2 GsonBuilder (com.google.gson.GsonBuilder)2 AutoConfigManager (org.terasology.engine.config.flexible.AutoConfigManager)2 Prefab (org.terasology.engine.entitySystem.prefab.Prefab)2 PrefabFormat (org.terasology.engine.entitySystem.prefab.internal.PrefabFormat)2 EventSerializer (org.terasology.engine.persistence.serializers.EventSerializer)2