Esempio n. 1
0
        public void JsonDeserializeEntityInstance()
        {
            TextAsset jsonProject = TestJsonLoader.LoadJson(TestJsonLoader.MOCK_ENTITY_INSTANCE);

            //try deserializing entity
            EntityInstance entity = JsonConvert.DeserializeObject <EntityInstance>(jsonProject.text);
        }
        private void DeserializeField(string key, Type type)
        {
            TextAsset fieldAsset = TestJsonLoader.LoadJson($"/LDtkMockField_Project.json");

            //try deserializing field
            LdtkJson field = JsonConvert.DeserializeObject <LdtkJson>(fieldAsset.text);

            FieldInstance[] fieldInstances = field.Levels[0].LayerInstances[0].EntityInstances[0].FieldInstances;

            FieldInstance instance = fieldInstances.First(p => p.Type.Contains(key));



            if (instance.Type.Contains("Array"))
            {
                object[] objs = ((IEnumerable)instance.Value).Cast <object>()
                                .Select(x => x == null ? x : x.ToString())
                                .ToArray();
                foreach (object o in objs)
                {
                    object obj = GetObject(type, instance, o);
                    Debug.Log(obj);
                }
            }
            else
            {
                object obj = GetObject(type, instance, instance.Value);
                Debug.Log(obj);
            }
        }
Esempio n. 3
0
        public void JsonDeserializeSchemaProject()
        {
            TextAsset jsonProject = TestJsonLoader.LoadJson(BASIC_PROJECT);

            Assert.NotNull(jsonProject, "Unsuccessful acquirement of json text asset");

            //attempt deserializing entire project
            LdtkJson project = LdtkJson.FromJson(jsonProject.text);
        }
Esempio n. 4
0
        public void GetCorrectTileBits()
        {
            TextAsset mockTest = TestJsonLoader.LoadJson(MOCK_TILE);

            TileInstance[] tiles = JsonConvert.DeserializeObject <TileInstance[]>(mockTest.text);

            foreach (TileInstance tile in tiles)
            {
                Debug.Log($"Tile: {tile.FlipX}, {tile.FlipY}");
            }

            Assert.IsTrue(tiles[0].FlipX == false && tiles[0].FlipY == false);
            Assert.IsTrue(tiles[1].FlipX == true && tiles[1].FlipY == false);
            Assert.IsTrue(tiles[2].FlipX == false && tiles[2].FlipY == true);
            Assert.IsTrue(tiles[3].FlipX == true && tiles[3].FlipY == true);
        }