public Settings(string file, Arguments args) { settingsFile = file; Sections = new Dictionary <string, object>() { { "Player", Player }, { "Game", Game }, { "Sound", Sound }, { "Graphics", Graphics }, { "Server", Server }, { "Debug", Debug }, { "Keys", Keys }, { "Chat", Chat } }; // Override fieldloader to ignore invalid entries var err1 = FieldLoader.UnknownFieldAction; var err2 = FieldLoader.InvalidValueAction; try { FieldLoader.UnknownFieldAction = (s, f) => Console.WriteLine("Ignoring unknown field `{0}` on `{1}`".F(s, f.Name)); if (File.Exists(settingsFile)) { var yaml = MiniYaml.DictFromFile(settingsFile); foreach (var kv in Sections) { if (yaml.ContainsKey(kv.Key)) { LoadSectionYaml(yaml[kv.Key], kv.Value); } } } // Override with commandline args foreach (var kv in Sections) { foreach (var f in kv.Value.GetType().GetFields()) { if (args.Contains(kv.Key + "." + f.Name)) { FieldLoader.LoadField(kv.Value, f.Name, args.GetValue(kv.Key + "." + f.Name, "")); } } } } finally { FieldLoader.UnknownFieldAction = err1; FieldLoader.InvalidValueAction = err2; } }
public TileSet(ModData modData, string filepath) { var yaml = MiniYaml.DictFromFile(filepath); // General info FieldLoader.Load(this, yaml["General"]); // TerrainTypes Terrain = yaml["Terrain"].NodesDict.Values .Select(y => new TerrainTypeInfo(y)).ToDictionary(t => t.Type); // Templates Templates = yaml["Templates"].NodesDict.Values .Select(y => new TileTemplate(y)).ToDictionary(t => t.Id); }
public TileSet(ModData modData, string filepath) { var yaml = MiniYaml.DictFromFile(filepath); // General info FieldLoader.Load(this, yaml["General"]); // TerrainTypes TerrainInfo = yaml["Terrain"].ToDictionary().Values .Select(y => new TerrainTypeInfo(y)) .OrderBy(tt => tt.Type) .ToArray(); if (TerrainInfo.Length >= byte.MaxValue) { throw new InvalidDataException("Too many terrain types."); } for (byte i = 0; i < TerrainInfo.Length; i++) { var tt = TerrainInfo[i].Type; if (terrainIndexByType.ContainsKey(tt)) { throw new InvalidDataException("Duplicate terrain type '{0}' in '{1}'.".F(tt, filepath)); } terrainIndexByType.Add(tt, i); } defaultWalkableTerrainIndex = GetTerrainIndex("Clear"); // Templates Templates = yaml["Templates"].ToDictionary().Values .Select(y => new TerrainTemplateInfo(this, y)).ToDictionary(t => t.Id); }