public static Dictionary <string, ModMetadata> ValidateMods(string[] mods) { var ret = new Dictionary <string, ModMetadata>(); foreach (var m in mods) { var yamlPath = new[] { "mods", m, "mod.yaml" }.Aggregate(Path.Combine); if (!File.Exists(yamlPath)) { continue; } var yaml = new MiniYaml(null, MiniYaml.FromFile(yamlPath)); var nd = yaml.ToDictionary(); if (!nd.ContainsKey("Metadata")) { continue; } var mod = FieldLoader.Load <ModMetadata>(nd["Metadata"]); mod.Id = m; ret.Add(m, mod); } return(ret); }
static Dictionary <string, T> LoadYamlRules <T>(string[] files, List <MiniYamlNode> dict, Func <MiniYamlNode, Dictionary <string, MiniYaml>, T> f) { var y = files.Select(a => MiniYaml.FromFile(a)).Aggregate(dict, MiniYaml.MergeLiberal); var yy = y.ToDictionary(x => x.Key, x => x.Value); return(y.ToDictionary(kv => kv.Key.ToLowerInvariant(), kv => f(kv, yy))); }
static Dictionary <string, ModMetadata> ValidateMods() { var basePath = Platform.ResolvePath(".", "mods"); var mods = Directory.GetDirectories(basePath) .Select(x => x.Substring(basePath.Length + 1)); var ret = new Dictionary <string, ModMetadata>(); foreach (var m in mods) { var yamlPath = Platform.ResolvePath(".", "mods", m, "mod.yaml"); if (!File.Exists(yamlPath)) { continue; } var yaml = new MiniYaml(null, MiniYaml.FromFile(yamlPath)); var nd = yaml.ToDictionary(); if (!nd.ContainsKey("Metadata")) { continue; } var mod = FieldLoader.Load <ModMetadata>(nd["Metadata"]); mod.Id = m; ret.Add(m, mod); } return(ret); }
Dictionary <string, T> LoadYamlRules <T>( Dictionary <string, T> itemCache, string[] files, List <MiniYamlNode> nodes, Func <MiniYamlNode, Dictionary <string, MiniYaml>, T> f) { RaiseProgress(); var inputKey = string.Concat(string.Join("|", files), "|", nodes.WriteToString()); var partial = files .Select(s => MiniYaml.FromFile(s)) .Aggregate(nodes, MiniYaml.MergePartial); Func <MiniYamlNode, Dictionary <string, MiniYaml>, T> wrap = (wkv, wyy) => { var key = inputKey + wkv.Value.ToLines(wkv.Key).JoinWith("|"); T t; if (itemCache.TryGetValue(key, out t)) { return(t); } t = f(wkv, wyy); itemCache.Add(key, t); RaiseProgress(); return(t); }; var yy = partial.ToDictionary(x => x.Key, x => x.Value); var itemSet = partial.ToDictionaryWithConflictLog(kv => kv.Key.ToLowerInvariant(), kv => wrap(kv, yy), "LoadYamlRules", null, null); RaiseProgress(); return(itemSet); }
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)) { yamlCache = MiniYaml.FromFile(settingsFile); foreach (var yamlSection in yamlCache) { object settingsSection; if (Sections.TryGetValue(yamlSection.Key, out settingsSection)) { LoadSectionYaml(yamlSection.Value, settingsSection); } } } // 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 WidgetLoader(ModData modData) { foreach (var file in modData.Manifest.ChromeLayout.Select(a => MiniYaml.FromFile(a))) { foreach (var w in file) { var key = w.Key.Substring(w.Key.IndexOf('@') + 1); if (widgets.ContainsKey(key)) { throw new InvalidDataException("Widget has duplicate Key `{0}`".F(w.Key)); } widgets.Add(key, w); } } }
static Dictionary <string, ModMetadata> ValidateMods() { var basePath = Platform.ResolvePath(".", "mods"); var mods = Directory.GetDirectories(basePath) .Select(x => x.Substring(basePath.Length + 1)); var ret = new Dictionary <string, ModMetadata>(); foreach (var m in mods) { try { var yamlPath = Platform.ResolvePath(".", "mods", m, "mod.yaml"); if (!File.Exists(yamlPath)) { continue; } var yaml = new MiniYaml(null, MiniYaml.FromFile(yamlPath)); var nd = yaml.ToDictionary(); if (!nd.ContainsKey("Metadata")) { continue; } var mod = FieldLoader.Load <ModMetadata>(nd["Metadata"]); mod.Id = m; if (nd.ContainsKey("ContentInstaller")) { mod.Content = FieldLoader.Load <ContentInstaller>(nd["ContentInstaller"]); } ret.Add(m, mod); } catch (Exception ex) { Console.WriteLine("An exception occurred when trying to load ModMetadata for `{0}`:".F(m)); Console.WriteLine(ex.Message); } } return(ret); }
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 }, }; // Override fieldloader to ignore invalid entries var err1 = FieldLoader.UnknownFieldAction; var err2 = FieldLoader.InvalidValueAction; try { FieldLoader.UnknownFieldAction = (s, f) => Console.WriteLine($"Ignoring unknown field `{s}` on `{f.Name}`"); if (File.Exists(settingsFile)) { yamlCache = MiniYaml.FromFile(settingsFile, false); foreach (var yamlSection in yamlCache) { if (yamlSection.Key != null && Sections.TryGetValue(yamlSection.Key, out var settingsSection)) { LoadSectionYaml(yamlSection.Value, settingsSection); } } var keysNode = yamlCache.FirstOrDefault(n => n.Key == "Keys"); if (keysNode != null) { foreach (var node in keysNode.Value.Nodes) { if (node.Key != null) { Keys[node.Key] = FieldLoader.GetValue <Hotkey>(node.Key, node.Value.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 Manifest(string mod) { var path = Platform.ResolvePath(".", "mods", mod, "mod.yaml"); yaml = new MiniYaml(null, MiniYaml.FromFile(path)).ToDictionary(); Mod = FieldLoader.Load <ModMetadata>(yaml["Metadata"]); Mod.Id = mod; // TODO: Use fieldloader Folders = YamlList(yaml, "Folders", true); MapFolders = YamlDictionary(yaml, "MapFolders", true); Packages = YamlDictionary(yaml, "Packages", true); Rules = YamlList(yaml, "Rules", true); Sequences = YamlList(yaml, "Sequences", true); VoxelSequences = YamlList(yaml, "VoxelSequences", true); Cursors = YamlList(yaml, "Cursors", true); Chrome = YamlList(yaml, "Chrome", true); Assemblies = YamlList(yaml, "Assemblies", true); ChromeLayout = YamlList(yaml, "ChromeLayout", true); Weapons = YamlList(yaml, "Weapons", true); Voices = YamlList(yaml, "Voices", true); Notifications = YamlList(yaml, "Notifications", true); Music = YamlList(yaml, "Music", true); Translations = YamlList(yaml, "Translations", true); TileSets = YamlList(yaml, "TileSets", true); ChromeMetrics = YamlList(yaml, "ChromeMetrics", true); Missions = YamlList(yaml, "Missions", true); ServerTraits = YamlList(yaml, "ServerTraits"); if (!yaml.TryGetValue("LoadScreen", out LoadScreen)) { throw new InvalidDataException("`LoadScreen` section is not defined."); } if (!yaml.TryGetValue("LobbyDefaults", out LobbyDefaults)) { throw new InvalidDataException("`LobbyDefaults` section is not defined."); } Fonts = yaml["Fonts"].ToDictionary(my => { var nd = my.ToDictionary(); return(Pair.New(nd["Font"].Value, Exts.ParseIntegerInvariant(nd["Size"].Value))); }); // Allow inherited mods to import parent maps. var compat = new List <string>(); compat.Add(mod); if (yaml.ContainsKey("SupportsMapsFrom")) { foreach (var c in yaml["SupportsMapsFrom"].Value.Split(',')) { compat.Add(c.Trim()); } } MapCompatibility = compat.ToArray(); if (yaml.ContainsKey("SpriteFormats")) { SpriteFormats = FieldLoader.GetValue <string[]>("SpriteFormats", yaml["SpriteFormats"].Value); } }
public Manifest(string mod) { var path = Platform.ResolvePath(".", "mods", mod, "mod.yaml"); yaml = new MiniYaml(null, MiniYaml.FromFile(path)).ToDictionary(); Mod = FieldLoader.Load <ModMetadata>(yaml["Metadata"]); Mod.Id = mod; // TODO: Use fieldloader Folders = YamlList(yaml, "Folders", true); MapFolders = YamlDictionary(yaml, "MapFolders", true); Packages = YamlDictionary(yaml, "Packages", true); Rules = YamlList(yaml, "Rules", true); Sequences = YamlList(yaml, "Sequences", true); VoxelSequences = YamlList(yaml, "VoxelSequences", true); Cursors = YamlList(yaml, "Cursors", true); Chrome = YamlList(yaml, "Chrome", true); Assemblies = YamlList(yaml, "Assemblies", true); ChromeLayout = YamlList(yaml, "ChromeLayout", true); Weapons = YamlList(yaml, "Weapons", true); Voices = YamlList(yaml, "Voices", true); Notifications = YamlList(yaml, "Notifications", true); Music = YamlList(yaml, "Music", true); Translations = YamlList(yaml, "Translations", true); TileSets = YamlList(yaml, "TileSets", true); ChromeMetrics = YamlList(yaml, "ChromeMetrics", true); Missions = YamlList(yaml, "Missions", true); ServerTraits = YamlList(yaml, "ServerTraits"); if (!yaml.TryGetValue("LoadScreen", out LoadScreen)) { throw new InvalidDataException("`LoadScreen` section is not defined."); } if (!yaml.TryGetValue("LobbyDefaults", out LobbyDefaults)) { throw new InvalidDataException("`LobbyDefaults` section is not defined."); } Fonts = yaml["Fonts"].ToDictionary(my => { var nd = my.ToDictionary(); return(Pair.New(nd["Font"].Value, Exts.ParseIntegerInvariant(nd["Size"].Value))); }); if (yaml.ContainsKey("TileSize")) { TileSize = FieldLoader.GetValue <Size>("TileSize", yaml["TileSize"].Value); } if (yaml.ContainsKey("TileShape")) { TileShape = FieldLoader.GetValue <TileShape>("TileShape", yaml["TileShape"].Value); } if (yaml.ContainsKey("MaximumTerrainHeight")) { MaximumTerrainHeight = FieldLoader.GetValue <byte>("MaximumTerrainHeight", yaml["MaximumTerrainHeight"].Value); } if (yaml.ContainsKey("SubCells")) { var subcells = yaml["SubCells"].ToDictionary(); // Read (x,y,z) offset (relative to cell center) pairs for positioning subcells if (subcells.ContainsKey("Offsets")) { SubCellOffsets = FieldLoader.GetValue <WVec[]>("Offsets", subcells["Offsets"].Value); } if (subcells.ContainsKey("DefaultIndex")) { SubCellDefaultIndex = FieldLoader.GetValue <int>("DefaultIndex", subcells["DefaultIndex"].Value); } else // Otherwise set the default subcell index to the middle subcell entry { SubCellDefaultIndex = SubCellOffsets.Length / 2; } } // Validate default index - 0 for no subcells, otherwise > 1 & <= subcell count (offset triples count - 1) if (SubCellDefaultIndex < (SubCellOffsets.Length > 1 ? 1 : 0) || SubCellDefaultIndex >= SubCellOffsets.Length) { throw new InvalidDataException("Subcell default index must be a valid index into the offset triples and must be greater than 0 for mods with subcells"); } // Allow inherited mods to import parent maps. var compat = new List <string>(); compat.Add(mod); if (yaml.ContainsKey("SupportsMapsFrom")) { foreach (var c in yaml["SupportsMapsFrom"].Value.Split(',')) { compat.Add(c.Trim()); } } MapCompatibility = compat.ToArray(); if (yaml.ContainsKey("SpriteFormats")) { SpriteFormats = FieldLoader.GetValue <string[]>("SpriteFormats", yaml["SpriteFormats"].Value); } }
public Manifest(string mod) { var path = new[] { "mods", mod, "mod.yaml" }.Aggregate(Path.Combine); var yaml = new MiniYaml(null, MiniYaml.FromFile(path)).ToDictionary(); Mod = FieldLoader.Load <ModMetadata>(yaml["Metadata"]); Mod.Id = mod; // TODO: Use fieldloader Folders = YamlList(yaml, "Folders"); MapFolders = YamlDictionary(yaml, "MapFolders"); Packages = YamlDictionary(yaml, "Packages"); Rules = YamlList(yaml, "Rules"); ServerTraits = YamlList(yaml, "ServerTraits"); Sequences = YamlList(yaml, "Sequences"); VoxelSequences = YamlList(yaml, "VoxelSequences"); Cursors = YamlList(yaml, "Cursors"); Chrome = YamlList(yaml, "Chrome"); Assemblies = YamlList(yaml, "Assemblies"); ChromeLayout = YamlList(yaml, "ChromeLayout"); Weapons = YamlList(yaml, "Weapons"); Voices = YamlList(yaml, "Voices"); Notifications = YamlList(yaml, "Notifications"); Music = YamlList(yaml, "Music"); Movies = YamlList(yaml, "Movies"); Translations = YamlList(yaml, "Translations"); TileSets = YamlList(yaml, "TileSets"); ChromeMetrics = YamlList(yaml, "ChromeMetrics"); PackageContents = YamlList(yaml, "PackageContents"); LuaScripts = YamlList(yaml, "LuaScripts"); Missions = YamlList(yaml, "Missions"); LoadScreen = yaml["LoadScreen"]; LobbyDefaults = yaml["LobbyDefaults"]; if (yaml.ContainsKey("ContentInstaller")) { ContentInstaller = FieldLoader.Load <InstallData>(yaml["ContentInstaller"]); } Fonts = yaml["Fonts"].ToDictionary(my => { var nd = my.ToDictionary(); return(Pair.New(nd["Font"].Value, Exts.ParseIntegerInvariant(nd["Size"].Value))); }); if (yaml.ContainsKey("TileSize")) { TileSize = FieldLoader.GetValue <Size>("TileSize", yaml["TileSize"].Value); } if (yaml.ContainsKey("TileShape")) { TileShape = FieldLoader.GetValue <TileShape>("TileShape", yaml["TileShape"].Value); } // Allow inherited mods to import parent maps. var compat = new List <string>(); compat.Add(mod); if (yaml.ContainsKey("SupportsMapsFrom")) { foreach (var c in yaml["SupportsMapsFrom"].Value.Split(',')) { compat.Add(c.Trim()); } } MapCompatibility = compat.ToArray(); }