public static List <TileData> LoadTileData(string filePath)
        {
            List <TileData> tilesData = new List <TileData>();

            TydFile file = LoadTilesConfiguration(filePath);

            TileData data;
            TydTable tydTable;

            foreach (TydNode node in file.DocumentNode.Nodes)
            {
                tydTable = node as TydTable;

                // Only read the data if the node is a table and is not abstract
                if (tydTable != null &&
                    !tydTable.AttributeAbstract)
                {
                    data = new TileData();

                    data.ReadData(tydTable);

                    tilesData.Add(data);
                }
            }

            return(tilesData);
        }
Esempio n. 2
0
        private static void WriteSettingsToFile()
        {
            // Build a TydDocument from all settings nodes and write.
            foreach (var key in _settings.Keys)
            {
                var tydString = _settingsNodes[key] as TydString;
                if (tydString != null)
                {
                    tydString.Value = _settings[key];
                }
            }
            var doc = new TydDocument(_settingsNodes.Values);

            TydFile.FromDocument(doc).Save(Application.streamingAssetsPath + "/Settings/Settings.tyd");
        }
        public static TydFile LoadTilesConfiguration(string filePath)
        {
            // Load the file
            TydFile file = TydFile.FromFile(filePath);

            // Resolve inheritance
            Inheritance.Initialize();
            try
            {
                TydDocument doc = file.DocumentNode;

                Inheritance.RegisterAllFrom(doc);

                Inheritance.ResolveAll();
            }
            finally
            {
                Inheritance.Complete();
            }

            return(file);
        }
Esempio n. 4
0
        public static void LoadSettings()
        {
            // Visits a node to add it to the defs dictionary.
            void AddSetting(string parentKey, TydNode node, int index = 0)
            {
                if (node == null)
                {
                    return;
                }

                // Add self.
                string nodeKey = parentKey;

                if (node as TydDocument == null)
                {
                    nodeKey += ".";
                    nodeKey += node.Name != null ? node.Name : index.ToString();
                    _settingsNodes[nodeKey] = node;
                }
                InGameDebug.Log("<color=green>\t\t\tLoaded setting: " + nodeKey + "</color>");
                // Also add this to settings if it is an end point.
                var tydString = node as TydString;

                if (tydString != null)
                {
                    _settings.Add(nodeKey, tydString.Value);
                }

                // Visit child nodes if this is a collection.
                var table = node as TydTable;

                if (table != null)
                {
                    for (int i = 0; i < table.Nodes.Count; i++)
                    {
                        AddSetting(nodeKey, table.Nodes[i], i);
                    }
                    return;
                }
                var list = node as TydList;

                if (list != null)
                {
                    for (int i = 0; i < list.Nodes.Count; i++)
                    {
                        AddSetting(nodeKey, list.Nodes[i], i);
                    }
                    return;
                }
            }

            InGameDebug.Log("Loading settings...");
            var file = Application.streamingAssetsPath + "/Settings/Settings.tyd";

            Directory.CreateDirectory(Path.GetDirectoryName(file));
            if (!File.Exists(file))
            {
                File.WriteAllText(file, "musicVolume 0.5\neffectsVolume 0.5");
            }
            var tydFile = TydFile.FromFile(file);

            AddSetting("Settings", tydFile.DocumentNode);
            InGameDebug.Log("Settings loaded.");
        }