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); }
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."); }