Exemple #1
0
    public void MergedDict()
    {
        CreateFile("globals.yaml", "Beetles: 12\nBirdName: Shabazz\nVersion: 1.2");
        CreateFile("items.yaml", "Treehouse: true");
        CreateFile("rooms.yaml", "Version: 1.3\nrooms:\n  - Overthorax\n  - Chirpinghouse\n  - Antennagate\n  - Subchitin");

        Configs.Preload();

        DocNode MixedDict = null;

        // load all files from the DictDir into one dict
        Configs.LoadFilesAsMergedDict("*", d => {
            MixedDict = d;
            return(true);
        });

        Assert.IsNotNull(MixedDict);

        Assert.AreEqual(5, MixedDict.Count);
        Assert.AreEqual(12, MixedDict["Beetles"].As <int>());
        Assert.AreEqual(1.3f, MixedDict["Version"].As <float>());
        Assert.True(MixedDict["Treehouse"].As <bool>());

        // Overwrite file contents
        CreateFile("items.yaml", "Chitin: 1000");

        // force a reload
        Configs.Update(1.0f);

        Assert.AreEqual(5, MixedDict.Count);
        Assert.False(MixedDict.ContainsKey("Treehouse"));
        Assert.AreEqual(1000, MixedDict["Chitin"].As <int>());
    }
Exemple #2
0
    public void Reify_DocNode()
    {
        var doc = Config.LoadDocFromString(@"---
            ugh: bugh
        ", "ConfigReifier_DocNode_TestFilename");

        DocNode d = null;

        ConfigReifier.Reify(ref d, doc);
        Assert.True(d.ContainsKey("ugh"));
        Assert.AreEqual(d["ugh"].AsString(), "bugh");
    }
Exemple #3
0
    IEnumerator MergedDictTestsCoro()
    {
        yield return(null);

        bool loaded = true;

        // load all files from the DictDir into one dict
        Config.LoadFilesAsMergedDict("DictDir/*", (d) => {
            Assert(d.Count == 5, "Expecting 5 properties in merged Dict, was", d.Count);
            MixedDict = d;
            loaded    = true;
            return(true);
        });

        Assert(MixedDict.Count == 5, "Expecting 5 properties in merged Dict, was", MixedDict.Count);
        Assert(MixedDict["Beetles"].AsInt() == 12, "Expected 12 beetles, was", MixedDict["Beetles"].AsInt());
        Assert(MixedDict["Version"].AsFloat() == 1.3f, "Version should be overwritten to 1.3, was", MixedDict["Version"].AsFloat());
        Assert(MixedDict["Treehouse"].AsBool(), "Treehouse should be true, was", MixedDict["Treehouse"].AsBool());


        yield return(new WaitForSeconds(0.25f));

        // force a reload
        var itemsPath = Application.dataPath + "/TestScenes/Resources/TestComposedConfigs/DictDir/items.bytes";
        var writer    = new StreamWriter(itemsPath, false);

        writer.Write(@"Chitin: 1000");
        writer.Flush();
        writer.Close();
        RefreshAssetDatabase();  // needed so that when the file is next loaded it has the new contents

        // wait for that reload to happen
        loaded = false;
        Debug.Log("DictComposingTest waiting for reload");
        while (!loaded)
        {
            yield return(new WaitForSeconds(0.1f));
        }

        Assert(MixedDict.Count == 5, "Should load all 5 items, got", MixedDict.Count);
        Assert(!MixedDict.ContainsKey("Treehouse"), "Treehouse should not be present");
        Assert(MixedDict["Chitin"].AsInt() == 1000, "Chitin should be 1000, is", MixedDict["Chitin"].AsInt());

        // restore the old content
        writer = new StreamWriter(itemsPath, false);
        writer.Write(@"Treehouse: true");
        writer.Flush();
        writer.Close();
        RefreshAssetDatabase();

        Finish();
    }