Package org.terasology.persistence.typeHandling

Examples of org.terasology.persistence.typeHandling.TypeSerializationLibrary


        this.storageManager = CoreRegistry.get(StorageManager.class);
        this.entitySystemLibrary = library;

        CoreRegistry.get(ComponentSystemManager.class).register(new NetworkEntitySystem(this), "engine:networkEntitySystem");

        TypeSerializationLibrary typeSerializationLibrary = new TypeSerializationLibrary(library.getSerializationLibrary());
        typeSerializationLibrary.add(EntityRef.class, new NetEntityRefTypeHandler(this, blockEntityRegistry));
        // TODO: Add network override types here (that use id lookup tables)

        eventSerializer = new EventSerializer(library.getEventLibrary(), typeSerializationLibrary);
        entitySerializer = new NetworkEntitySerializer(newEntityManager, entityManager.getComponentLibrary(), typeSerializationLibrary);
        entitySerializer.setComponentSerializeCheck(new NetComponentSerializeCheck());
View Full Code Here


        ModuleManager moduleManager = CoreRegistry.putPermanently(ModuleManager.class, new ModuleManager());

        ReflectFactory reflectFactory = CoreRegistry.putPermanently(ReflectFactory.class, new ReflectionReflectFactory());
        CopyStrategyLibrary copyStrategyLibrary = CoreRegistry.putPermanently(CopyStrategyLibrary.class, new CopyStrategyLibrary(reflectFactory));

        CoreRegistry.putPermanently(TypeSerializationLibrary.class, new TypeSerializationLibrary(reflectFactory, copyStrategyLibrary));

        AssetManager assetManager = CoreRegistry.putPermanently(AssetManager.class, new AssetManager(moduleManager.getEnvironment()));
        assetManager.setEnvironment(moduleManager.getEnvironment());
        CoreRegistry.putPermanently(CollisionGroupManager.class, new CollisionGroupManager());
        CoreRegistry.putPermanently(WorldGeneratorManager.class, new WorldGeneratorManager());
View Full Code Here

        // Entity Manager
        PojoEntityManager entityManager = CoreRegistry.put(EntityManager.class, new PojoEntityManager());
        CoreRegistry.put(EngineEntityManager.class, entityManager);

        // Standard serialization library
        TypeSerializationLibrary typeSerializationLibrary = buildTypeLibrary(entityManager, reflectFactory, copyStrategyLibrary);
        entityManager.setTypeSerializerLibrary(typeSerializationLibrary);

        // Entity System Library
        EntitySystemLibrary library = CoreRegistry.put(EntitySystemLibrary.class, new EntitySystemLibrary(reflectFactory, copyStrategyLibrary, typeSerializationLibrary));
        entityManager.setEntitySystemLibrary(library);
View Full Code Here

        registerEvents(entityManager.getEventSystem(), environment);
        return entityManager;
    }

    private TypeSerializationLibrary buildTypeLibrary(PojoEntityManager entityManager, ReflectFactory factory, CopyStrategyLibrary copyStrategies) {
        TypeSerializationLibrary serializationLibrary = new TypeSerializationLibrary(factory, copyStrategies);
        serializationLibrary.add(BlockFamily.class, new BlockFamilyTypeHandler());
        serializationLibrary.add(Block.class, new BlockTypeHandler());
        serializationLibrary.add(Color.class, new ColorTypeHandler());
        serializationLibrary.add(Quat4f.class, new Quat4fTypeHandler());
        serializationLibrary.add(Texture.class, new AssetTypeHandler<>(AssetType.TEXTURE, Texture.class));
        serializationLibrary.add(UIElement.class, new AssetTypeHandler<>(AssetType.UI_ELEMENT, UIElement.class));
        serializationLibrary.add(Mesh.class, new AssetTypeHandler<>(AssetType.MESH, Mesh.class));
        serializationLibrary.add(StaticSound.class, new AssetTypeHandler<>(AssetType.SOUND, StaticSound.class));
        serializationLibrary.add(StreamingSound.class, new AssetTypeHandler<>(AssetType.MUSIC, StreamingSound.class));
        serializationLibrary.add(Material.class, new AssetTypeHandler<>(AssetType.MATERIAL, Material.class));
        serializationLibrary.add(SkeletalMesh.class, new AssetTypeHandler<>(AssetType.SKELETON_MESH, SkeletalMesh.class));
        serializationLibrary.add(MeshAnimation.class, new AssetTypeHandler<>(AssetType.ANIMATION, MeshAnimation.class));
        serializationLibrary.add(TextureRegion.class, new TextureRegionTypeHandler());
        serializationLibrary.add(TextureRegionAsset.class, new TextureRegionTypeHandler());
        serializationLibrary.add(Vector4f.class, new Vector4fTypeHandler());
        serializationLibrary.add(Vector3f.class, new Vector3fTypeHandler());
        serializationLibrary.add(Vector2f.class, new Vector2fTypeHandler());
        serializationLibrary.add(Vector3i.class, new Vector3iTypeHandler());
        serializationLibrary.add(CollisionGroup.class, new CollisionGroupTypeHandler());
        serializationLibrary.add(Region3i.class, new Region3iTypeHandler());
        serializationLibrary.add(EntityRef.class, new EntityRefTypeHandler(entityManager));
        serializationLibrary.add(Prefab.class, new PrefabTypeHandler());
        serializationLibrary.add(BehaviorTree.class, new AssetTypeHandler<>(AssetType.BEHAVIOR, BehaviorTree.class));
        return serializationLibrary;
    }
View Full Code Here

    @Before
    public void setup() {
        ReflectFactory reflectFactory = new ReflectionReflectFactory();
        CopyStrategyLibrary copyStrategies = new CopyStrategyLibrary(reflectFactory);
        TypeSerializationLibrary serializationLibrary = new TypeSerializationLibrary(reflectFactory, copyStrategies);

        EntitySystemLibrary entitySystemLibrary = new EntitySystemLibrary(reflectFactory, copyStrategies, serializationLibrary);
        compLibrary = entitySystemLibrary.getComponentLibrary();
        entityManager = new PojoEntityManager();
        entityManager.setEntitySystemLibrary(entitySystemLibrary);
View Full Code Here

        moduleManager = ModuleManagerFactory.create();
    }

    @Before
    public void setup() {
        TypeSerializationLibrary serializationLibrary = new TypeSerializationLibrary(reflectFactory, copyStrategyLibrary);
        serializationLibrary.add(Vector3f.class, new Vector3fTypeHandler());
        serializationLibrary.add(Quat4f.class, new Quat4fTypeHandler());

        NetworkSystem networkSystem = mock(NetworkSystem.class);
        EntitySystemBuilder builder = new EntitySystemBuilder();
        EngineEntityManager entityManager = builder.build(moduleManager.getEnvironment(), networkSystem, new ReflectionReflectFactory());
        entityManager.getComponentLibrary().register(new SimpleUri("test", "gettersetter"), GetterSetterComponent.class);
View Full Code Here

    @Before
    public void setup() throws Exception {
        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(reflectFactory, copyStrategyLibrary, lib);
        componentLibrary = entitySystemLibrary.getComponentLibrary();
        prefabManager = new PojoPrefabManager();
        AssetManager assetManager = new AssetManager(moduleManager.getEnvironment());
        assetManager.setAssetFactory(AssetType.PREFAB, new AssetFactory<PrefabData, Prefab>() {
View Full Code Here

    private ReflectFactory reflectFactory = new ReflectionReflectFactory();
    private CopyStrategyLibrary copyStrategies = new CopyStrategyLibrary(reflectFactory);

    @Test
    public void staticFieldsIgnored() {
        EntitySystemLibrary entitySystemLibrary = new EntitySystemLibrary(reflectFactory, copyStrategies, new TypeSerializationLibrary(reflectFactory, copyStrategies));
        ComponentLibrary lib = entitySystemLibrary.getComponentLibrary();
        lib.register(new SimpleUri("unittest:string"), StringComponent.class);
        ComponentMetadata<StringComponent> metadata = lib.getMetadata(StringComponent.class);
        assertNull(metadata.getField("STATIC_VALUE"));
    }
View Full Code Here

        assertNull(metadata.getField("STATIC_VALUE"));
    }

    @Test
    public void ownsReferencesPopulated() {
        EntitySystemLibrary entitySystemLibrary = new EntitySystemLibrary(reflectFactory, copyStrategies, new TypeSerializationLibrary(reflectFactory, copyStrategies));
        ComponentLibrary lib = entitySystemLibrary.getComponentLibrary();
        lib.register(new SimpleUri("unittest:owner"), OwnerComponent.class);
        ComponentMetadata<OwnerComponent> metadata = lib.getMetadata(OwnerComponent.class);
        assertTrue(metadata.isReferenceOwner());
    }
View Full Code Here

        NUIManager nuiManager = CoreRegistry.get(NUIManager.class);
        ReflectFactory reflectFactory = CoreRegistry.get(ReflectFactory.class);
        CopyStrategyLibrary copyStrategyLibrary = CoreRegistry.get(CopyStrategyLibrary.class);

        // TODO: Get this library from elsewhere
        TypeSerializationLibrary library = new TypeSerializationLibrary(reflectFactory, copyStrategyLibrary);
        library.add(BlockFamily.class, new BlockFamilyTypeHandler());
        library.add(Block.class, new BlockTypeHandler());
        library.add(Color.class, new ColorTypeHandler());
        library.add(Quat4f.class, new Quat4fTypeHandler());
        library.add(Texture.class, new AssetTypeHandler<>(AssetType.TEXTURE, Texture.class));
        library.add(Mesh.class, new AssetTypeHandler<>(AssetType.MESH, Mesh.class));
        library.add(StaticSound.class, new AssetTypeHandler<>(AssetType.SOUND, StaticSound.class));
        library.add(StreamingSound.class, new AssetTypeHandler<>(AssetType.MUSIC, StreamingSound.class));
        library.add(Material.class, new AssetTypeHandler<>(AssetType.MATERIAL, Material.class));
        library.add(SkeletalMesh.class, new AssetTypeHandler<>(AssetType.SKELETON_MESH, SkeletalMesh.class));
        library.add(MeshAnimation.class, new AssetTypeHandler<>(AssetType.ANIMATION, MeshAnimation.class));
        library.add(UISkin.class, new AssetTypeHandler<>(AssetType.UI_SKIN, UISkin.class));
        library.add(Vector4f.class, new Vector4fTypeHandler());
        library.add(Vector3f.class, new Vector3fTypeHandler());
        library.add(Vector2f.class, new Vector2fTypeHandler());
        library.add(Vector3i.class, new Vector3iTypeHandler());
        library.add(Vector2i.class, new Vector2iTypeHandler());
        library.add(Rect2i.class, new Rect2iTypeHandler());
        library.add(Rect2f.class, new Rect2fTypeHandler());
        library.add(CollisionGroup.class, new CollisionGroupTypeHandler());
        library.add(Region3i.class, new Region3iTypeHandler());
        library.add(Prefab.class, new PrefabTypeHandler());
        library.add(Border.class, new BorderTypeHandler());
        library.add(TextureRegion.class, new TextureRegionTypeHandler());
        library.add(TextureRegionAsset.class, new TextureRegionTypeHandler());

        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)));
        }
        Gson gson = gsonBuilder.create();

        try (JsonReader reader = new JsonReader(new InputStreamReader(stream, Charsets.UTF_8))) {
            reader.setLenient(true);
View Full Code Here

TOP

Related Classes of org.terasology.persistence.typeHandling.TypeSerializationLibrary

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.