void MergeAndPrint(Map map, string key, MiniYaml value) { var nodes = new List <MiniYamlNode>(); var includes = new List <string>(); if (value != null && value.Value != null) { // The order of the included files matter, so we can defer to system files // only as long as they are included first. var include = false; var files = FieldLoader.GetValue <string[]>("value", value.Value); foreach (var f in files) { include |= map.Package.Contains(f); if (include) { nodes.AddRange(MiniYaml.FromStream(map.Open(f), f, false)); } else { includes.Add(f); } } } if (value != null) { nodes.AddRange(value.Nodes); } var output = new MiniYaml(includes.JoinWith(", "), nodes); Console.WriteLine(output.ToLines(key).JoinWith("\n")); }
public override IEnumerable <string> AfterUpdate(ModData modData) { if (resourceLayer.Nodes.Any()) { yield return("Add the following definitions to your ResourceLayer and EditorResourceLayer definitions:\n\t" + "RecalculateResourceDensity: true\n\t" + resourceLayer.ToLines("ResourceTypes").JoinWith("\n\t")); } if (resourceLayer.Nodes.Any()) { yield return("Add the following definitions to your ResourceRenderer definition:\n\t" + resourceRenderer.ToLines("ResourceTypes").JoinWith("\n\t")); } if (values.Nodes.Any()) { yield return("Add the following definition to your ^BasePlayer definition:\n\t" + "PlayerResources:\n\t\t" + values.ToLines("ResourceValues").JoinWith("\n\t\t")); } if (resourceLayer.Nodes.Any()) { yield return("Support for AllowUnderActors, AllowUnderBuildings, and AllowOnRamps have been removed.\n" + "You must define a custom ResourceLayer subclass if you want to customize the default behaviour."); } }
void MergeAndPrint(Map map, string key, MiniYaml value) { var nodes = new List<MiniYamlNode>(); var includes = new List<string>(); if (value != null && value.Value != null) { // The order of the included files matter, so we can defer to system files // only as long as they are included first. var include = false; var files = FieldLoader.GetValue<string[]>("value", value.Value); foreach (var f in files) { include |= map.Package.Contains(f); if (include) nodes.AddRange(MiniYaml.FromStream(map.Open(f))); else includes.Add(f); } } if (value != null) nodes.AddRange(value.Nodes); var output = new MiniYaml(includes.JoinWith(", "), nodes); Console.WriteLine(output.ToLines(key).JoinWith("\n")); }
void TestMixedMerge(MiniYaml result) { Console.WriteLine(result.ToLines("result").JoinWith("\n")); Assert.That(result.Nodes.Any(n => n.Key == "FromA"), Is.True, "Node from A"); Assert.That(result.Nodes.Any(n => n.Key == "FromB"), Is.True, "Node from B"); Assert.That(result.Nodes.Any(n => n.Key == "FromARemovedA"), Is.Not.True, "Node from A removed by A"); Assert.That(result.Nodes.Any(n => n.Key == "FromARemovedB"), Is.Not.True, "Node from A removed by B"); Assert.That(result.Nodes.Any(n => n.Key == "FromBRemovedA"), Is.Not.True, "Node from B removed by A"); Assert.That(result.Nodes.Any(n => n.Key == "FromBRemovedB"), Is.Not.True, "Node from B removed by B"); }
void TestMixedMerge(MiniYaml result) { Console.WriteLine(result.ToLines("result").JoinWith("\n")); Assert.That(result.Nodes.Any(n => n.Key == "FromA"), Is.True, "Node from A"); Assert.That(result.Nodes.Any(n => n.Key == "FromB"), Is.True, "Node from B"); Assert.That(result.Nodes.Any(n => n.Key == "FromARemovedA"), Is.Not.True, "Node from A removed by A"); Assert.That(result.Nodes.Any(n => n.Key == "FromARemovedB"), Is.Not.True, "Node from A removed by B"); Assert.That(result.Nodes.Any(n => n.Key == "FromBRemovedA"), Is.Not.True, "Node from B removed by A"); Assert.That(result.Nodes.Any(n => n.Key == "FromBRemovedB"), Is.Not.True, "Node from B removed by B"); }
public void Run(Utility utility, string[] args) { var modData = utility.ModData; var localizationName = args[1]; var localizationFile = localizationName + ".yaml"; if (File.Exists(localizationFile)) { File.Delete(localizationFile); } using (StreamWriter writer = new StreamWriter(File.Create(localizationName + ".yaml"))) { List <MiniYamlNode> subNodes = new List <MiniYamlNode>(); List <MiniYamlNode> ruleNodes = new List <MiniYamlNode>(); foreach (var f in modData.Manifest.Rules) { var actors = MiniYaml.FromStream(modData.DefaultFileSystem.Open(f), f); // TODO: maybe can export actorInfos foreach (var actor in actors) { foreach (var trait in actor.Value.Nodes) { // TODO: export the string which has translation attribute if (trait.Key == "Tooltip") { ruleNodes.Add(new MiniYamlNode(actor.Key, new MiniYaml(trait.Value.Nodes[0].Value.Value))); } } } } subNodes.Add(new MiniYamlNode("Rules", new MiniYaml(null, ruleNodes))); List <MiniYamlNode> nodes = new List <MiniYamlNode>(); MiniYamlNode node = new MiniYamlNode(localizationName, new MiniYaml(localizationName.SetFirstLetterUpper(), subNodes)); nodes.Add(node); MiniYaml tranlsation = new MiniYaml(null, nodes); foreach (var line in tranlsation.ToLines(localizationName)) { writer.WriteLine(line); } } }