Example #1
0
    public void TestFromNestedJson()
    {
        var json = "{\"nested\":{\"test\":100.01}}";
        var t    = Piekson.FromJson <TestMainClass>(json);

        Assert.AreEqual(new TestMainClass(new TestNestedClass()), t);
    }
Example #2
0
    public void TestFromEnum()
    {
        var json = "{\"TestDirection\":\"DOWN\"}";
        var t    = Piekson.FromJson <TestClassWithEnum>(json);

        Assert.AreEqual(new TestClassWithEnum(TestDirection.DOWN).TestDirection, t.TestDirection);
    }
Example #3
0
    public void TestToJson()
    {
        TestClass t    = new TestClass(3.14f, true, 123, "hel\\\"lo");
        var       json = Piekson.ToJson(t);

        Assert.AreEqual("{\"a\":123,\"b\":\"hel\\\\\\\"lo\",\"d\":3.14,\"state\":true}", json);
    }
Example #4
0
    public void TestNullValue()
    {
        var t    = new TestMainClass();
        var json = Piekson.ToJson(t);

        Assert.AreEqual("{}", json);
    }
Example #5
0
    public void TestNegativeValueFromJson()
    {
        var json = "{\"a\":-123,\"b\":\"hel\\\\\\\"lo\",\"d\":-3.14,\"state\":true}";
        var t    = Piekson.FromJson <TestClass>(json);

        Assert.AreEqual(new TestClass(-3.14f, true, -123, "hel\\\"lo"), t);
    }
Example #6
0
    public void TestEnum()
    {
        var t    = new TestClassWithEnum(TestDirection.DOWN);
        var json = Piekson.ToJson(t);

        Assert.AreEqual("{\"TestDirection\":\"DOWN\"}", json);
    }
Example #7
0
    public void TestNestedToJson()
    {
        TestMainClass t    = new TestMainClass(new TestNestedClass());
        var           json = Piekson.ToJson(t);

        Assert.AreEqual("{\"nested\":{\"test\":100.01}}", json);
    }
Example #8
0
    public void TestType()
    {
        var t    = new TestClassWithType(typeof(TestClassWithType));
        var json = Piekson.ToJson(t);

        Assert.AreEqual("{\"type\":\"TestNamespace.TestClassWithType, Assembly-CSharp-Editor, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null\"}", json);
    }
Example #9
0
    public void TestLoopToJson()
    {
        var t    = new TestLoop(10);
        var json = Piekson.ToJson(t);

        Assert.AreEqual("{\"a\":10}", json);
    }
Example #10
0
    public void TestFromType()
    {
        var json = "{\"type\":\"TestNamespace.TestClassWithType, Assembly-CSharp-Editor, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null\"}";
        var t    = Piekson.FromJson <TestClassWithType>(json);

        Assert.AreEqual(typeof(TestClassWithType), t.type);
    }
Example #11
0
    public void TestNestedGenericCollectionToJson()
    {
        var t = new TestNestedCollection(new List <string> {
            "Arnold", "Marian", "Fedrynand"
        });
        var json = Piekson.ToJson(t);

        Assert.AreEqual("{\"names\":[\"Arnold\",\"Marian\",\"Fedrynand\"]}", json);
    }
Example #12
0
    public void TestGenericCollectionToJson()
    {
        List <int> list = new List <int> {
            1, 2, 3, 4, 5
        };
        var json = Piekson.ToJson(list);

        Assert.AreEqual("[1,2,3,4,5]", json);
    }
Example #13
0
    public void TestFromStringListJson()
    {
        var json = "[\"a\",\"b\",\"c\",\"d\"]";
        var t    = Piekson.FromJson <List <string> >(json);

        Assert.AreEqual(new List <string> {
            "a", "b", "c", "d"
        }, t);
    }
Example #14
0
    public void TestFromListInObjectJson()
    {
        var json = "{\"names\":[\"Arnold\",\"Marian\",\"Fedrynand\"]}";
        var t    = Piekson.FromJson <TestNestedCollection>(json);

        Assert.AreEqual(new TestNestedCollection(new List <string> {
            "Arnold", "Marian", "Fedrynand"
        }), t);
    }
Example #15
0
    public void TestFromObjectInListJson()
    {
        var json = "[{\"test\":1},{\"test\":2}]";
        var t    = Piekson.FromJson <List <TestSimpleClass> >(json);

        Assert.AreEqual(new List <TestSimpleClass> {
            new TestSimpleClass(1), new TestSimpleClass(2)
        }, t);
    }
Example #16
0
    public void TestFromIntListJson()
    {
        var json = "[1,2,3,4,5,6]";
        var t    = Piekson.FromJson <List <int> >(json);

        Assert.AreEqual(new List <int> {
            1, 2, 3, 4, 5, 6
        }, t);
    }
Example #17
0
    public void TestFromDictionaryJson()
    {
        var json = "{\"a\":1,\"b\":2,\"c\":3,\"d\":4}";
        var t    = Piekson.FromJson <Dictionary <string, int> >(json);

        CollectionAssert.AreEquivalent(new Dictionary <string, int>()
        {
            { "a", 1 }, { "b", 2 }, { "c", 3 }, { "d", 4 },
        }, t);
    }
Example #18
0
    public void TestFromDictionaryInObjectJson()
    {
        var json = "{\"test\":{\"a\":1, \"b\":3}}";
        var t    = Piekson.FromJson <TestDictionaryInObject>(json);

        CollectionAssert.AreEquivalent(new Dictionary <string, int>()
        {
            { "a", 1 }, { "b", 3 }
        }, t.test);
    }
Example #19
0
    public void TestFromObjectInDictionaryJson()
    {
        var json = "{\"testObj1\":{\"test\":1}, \"testObj2\":{\"test\":2}}";
        var t    = Piekson.FromJson <Dictionary <string, TestSimpleClass> >(json);

        CollectionAssert.AreEquivalent(
            new Dictionary <string, TestSimpleClass>()
        {
            { "testObj1", new TestSimpleClass(1) }, { "testObj2", new TestSimpleClass(2) }
        }, t);
    }
Example #20
0
    public void TestDictionaryToJson()
    {
        var t = new Dictionary <string, int>()
        {
            { "a", 1 },
            { "b", 2 },
            { "c", 3 },
            { "d", 4 },
        };
        var json = Piekson.ToJson(t);

        Assert.AreEqual("{\"a\":1,\"b\":2,\"c\":3,\"d\":4}", json);
    }
Example #21
0
    void Awake()
    {
        var levelData = Piekson.FromJson <LevelDto>(Level.Json);

        spawnSprites(levelData);
        spawnSpriteShapes(levelData);
        var carWasSpawned = spawnPrefabs(levelData);

        if (carWasSpawned)
        {
            SEventSystem.FireEvent(EventNames.LEVEL_INSTANTIATED);
        }
        else
        {
            Debug.Log("Car was not instantiated!");
        }
    }
Example #22
0
    public void Serialize()
    {
        var carSerialized = false;
        var levelDto      = new LevelDto();

        for (int i = 0; i < transform.childCount; i++)
        {
            var spriteRenderer        = transform.GetChild(i).GetComponent <SpriteRenderer>();
            var spriteShapeController = transform.GetChild(i).GetComponent <SpriteShapeController>();
            var prefab = transform.GetChild(i).GetComponent <ImPrefabSerializeMe>();

            if (spriteRenderer != null)
            {
                levelDto.sprites.Add(new SpriteDto(spriteRenderer));
            }

            if (spriteShapeController != null)
            {
                levelDto.SpriteShapeControllers.Add(new SpriteShapeControllerDto(spriteShapeController));
            }

            if (prefab != null)
            {
                if (prefab.GetComponent <Car>() != null)
                {
                    carSerialized = true;
                }
                levelDto.Prefabs.Add(new Prefab(prefab));
            }
        }

        if (carSerialized)
        {
            var level = ScriptableObject.CreateInstance <Level>();
            level.Json = Piekson.ToJson(levelDto);
            AssetDatabase.CreateAsset(level,
                                      "Assets/Levels/" + WorldType + "/" + SceneManager.GetActiveScene().name + ".asset");
            Debug.Log(Piekson.ToJson(levelDto));
        }
        else
        {
            Debug.Log("Car is missing!");
        }
    }