diff --git a/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj b/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj index 3dfe883214..debbc18184 100644 --- a/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj +++ b/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj @@ -756,7 +756,6 @@ - @@ -781,6 +780,10 @@ + + + + diff --git a/OpenRA.Mods.Common/UtilityCommands/OutputActorMiniYamlCommand.cs b/OpenRA.Mods.Common/UtilityCommands/OutputActorMiniYamlCommand.cs deleted file mode 100644 index f1e13fcf92..0000000000 --- a/OpenRA.Mods.Common/UtilityCommands/OutputActorMiniYamlCommand.cs +++ /dev/null @@ -1,54 +0,0 @@ -using System; -using System.IO; -using System.Linq; -using OpenRA.FileSystem; - -namespace OpenRA.Mods.Common.UtilityCommands -{ - public class OutputActorMiniYamlCommand : IUtilityCommand - { - string IUtilityCommand.Name { get { return "--actor-yaml"; } } - - bool IUtilityCommand.ValidateArguments(string[] args) - { - return args.Length == 2 || args.Length == 3; - } - - [Desc("ACTOR-TYPE [PATH/TO/MAP]", "Display the finalized, merged MiniYaml tree for the given actor type. Input values are case-sensitive.")] - void IUtilityCommand.Run(Utility utility, string[] args) - { - // HACK: The engine code assumes that Game.modData is set. - var modData = Game.ModData = utility.ModData; - - var actorType = args[1]; - string mapPath = null; - - Map map = null; - if (args.Length == 3) - { - try - { - mapPath = args[2]; - map = new Map(modData, modData.ModFiles.OpenPackage(mapPath, new Folder("."))); - } - catch (InvalidDataException) - { - Console.WriteLine("Could not load map '{0}'.", mapPath); - Environment.Exit(2); - } - } - - var fs = map ?? modData.DefaultFileSystem; - var topLevelNodes = MiniYaml.Load(fs, modData.Manifest.Rules, map == null ? null : map.RuleDefinitions); - - var result = topLevelNodes.FirstOrDefault(n => n.Key == actorType); - if (result == null) - { - Console.WriteLine("Could not find actor '{0}' (name is case-sensitive).", actorType); - Environment.Exit(1); - } - - Console.WriteLine(result.Value.Nodes.WriteToString()); - } - } -} diff --git a/OpenRA.Mods.Common/UtilityCommands/OutputResolvedRulesCommand.cs b/OpenRA.Mods.Common/UtilityCommands/OutputResolvedRulesCommand.cs new file mode 100644 index 0000000000..cfc55152a7 --- /dev/null +++ b/OpenRA.Mods.Common/UtilityCommands/OutputResolvedRulesCommand.cs @@ -0,0 +1,46 @@ +#region Copyright & License Information +/* + * Copyright 2007-2016 The OpenRA Developers (see AUTHORS) + * This file is part of OpenRA, which is free software. It is made + * available to you under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 of + * the License, or (at your option) any later version. For more + * information, see COPYING. + */ +#endregion + +using System; + +namespace OpenRA.Mods.Common.UtilityCommands +{ + public class OutputResolvedRulesCommand : IUtilityCommand + { + string IUtilityCommand.Name { get { return "--resolved-rules"; } } + + bool IUtilityCommand.ValidateArguments(string[] args) + { + return args.Length == 2 || args.Length == 3; + } + + [Desc("ACTOR [PATH/TO/MAP]", "Display the finalized, merged MiniYaml rules for the given actor. Input values are case-sensitive.")] + void IUtilityCommand.Run(Utility utility, string[] args) + { + // HACK: The engine code assumes that Game.ModData is set. + var modData = Game.ModData = utility.ModData; + + var key = args[1]; + var result = Utilities.GetTopLevelNodeByKey(modData, key, + manifest => manifest.Rules, + map => map.RuleDefinitions, + args.Length == 3 ? args[2] : null); + + if (result == null) + { + Console.WriteLine("Could not find actor '{0}' (name is case-sensitive).", key); + Environment.Exit(1); + } + + Console.WriteLine(result.Value.Nodes.WriteToString()); + } + } +} diff --git a/OpenRA.Mods.Common/UtilityCommands/OutputResolvedSequencesCommand.cs b/OpenRA.Mods.Common/UtilityCommands/OutputResolvedSequencesCommand.cs new file mode 100644 index 0000000000..e0de6df8c1 --- /dev/null +++ b/OpenRA.Mods.Common/UtilityCommands/OutputResolvedSequencesCommand.cs @@ -0,0 +1,46 @@ +#region Copyright & License Information +/* + * Copyright 2007-2016 The OpenRA Developers (see AUTHORS) + * This file is part of OpenRA, which is free software. It is made + * available to you under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 of + * the License, or (at your option) any later version. For more + * information, see COPYING. + */ +#endregion + +using System; + +namespace OpenRA.Mods.Common.UtilityCommands +{ + public class OutputResolvedSequencesCommand : IUtilityCommand + { + string IUtilityCommand.Name { get { return "--resolved-sequences"; } } + + bool IUtilityCommand.ValidateArguments(string[] args) + { + return args.Length == 2 || args.Length == 3; + } + + [Desc("IMAGE-NAME [PATH/TO/MAP]", "Display the finalized, merged MiniYaml sequence tree for the given image. Input values are case-sensitive.")] + void IUtilityCommand.Run(Utility utility, string[] args) + { + // HACK: The engine code assumes that Game.ModData is set. + var modData = Game.ModData = utility.ModData; + + var key = args[1]; + var result = Utilities.GetTopLevelNodeByKey(modData, key, + manifest => manifest.Sequences, + map => map.SequenceDefinitions, + args.Length == 3 ? args[2] : null); + + if (result == null) + { + Console.WriteLine("Could not find image '{0}' (name is case-sensitive).", key); + Environment.Exit(1); + } + + Console.WriteLine(result.Value.Nodes.WriteToString()); + } + } +} diff --git a/OpenRA.Mods.Common/UtilityCommands/OutputResolvedWeaponsCommand.cs b/OpenRA.Mods.Common/UtilityCommands/OutputResolvedWeaponsCommand.cs new file mode 100644 index 0000000000..202ae02736 --- /dev/null +++ b/OpenRA.Mods.Common/UtilityCommands/OutputResolvedWeaponsCommand.cs @@ -0,0 +1,46 @@ +#region Copyright & License Information +/* + * Copyright 2007-2016 The OpenRA Developers (see AUTHORS) + * This file is part of OpenRA, which is free software. It is made + * available to you under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 of + * the License, or (at your option) any later version. For more + * information, see COPYING. + */ +#endregion + +using System; + +namespace OpenRA.Mods.Common.UtilityCommands +{ + public class OutputResolvedWeaponsCommand : IUtilityCommand + { + string IUtilityCommand.Name { get { return "--resolved-weapons"; } } + + bool IUtilityCommand.ValidateArguments(string[] args) + { + return args.Length == 2 || args.Length == 3; + } + + [Desc("WEAPON [PATH/TO/MAP]", "Display the finalized, merged MiniYaml tree for the given weapon. Input values are case-sensitive.")] + void IUtilityCommand.Run(Utility utility, string[] args) + { + // HACK: The engine code assumes that Game.ModData is set. + var modData = Game.ModData = utility.ModData; + + var key = args[1]; + var result = Utilities.GetTopLevelNodeByKey(modData, key, + manifest => manifest.Weapons, + map => map.WeaponDefinitions, + args.Length == 3 ? args[2] : null); + + if (result == null) + { + Console.WriteLine("Could not find weapon '{0}' (name is case-sensitive).", key); + Environment.Exit(1); + } + + Console.WriteLine(result.Value.Nodes.WriteToString()); + } + } +} diff --git a/OpenRA.Mods.Common/UtilityCommands/Utilities.cs b/OpenRA.Mods.Common/UtilityCommands/Utilities.cs new file mode 100644 index 0000000000..0e0a50c20c --- /dev/null +++ b/OpenRA.Mods.Common/UtilityCommands/Utilities.cs @@ -0,0 +1,54 @@ +#region Copyright & License Information +/* + * Copyright 2007-2016 The OpenRA Developers (see AUTHORS) + * This file is part of OpenRA, which is free software. It is made + * available to you under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 of + * the License, or (at your option) any later version. For more + * information, see COPYING. + */ +#endregion + +using System; +using System.IO; +using System.Linq; +using OpenRA.FileSystem; + +namespace OpenRA.Mods.Common.UtilityCommands +{ + public static class Utilities + { + /// Thrown if manifestPropertySelector is null. + public static MiniYamlNode GetTopLevelNodeByKey(ModData modData, string key, + Func manifestPropertySelector, + Func mapPropertySelector = null, + string mapPath = null) + { + if (manifestPropertySelector == null) + throw new ArgumentNullException("manifestPropertySelector", "Must pass a non-null manifestPropertySelector"); + + Map map = null; + if (mapPath != null) + { + try + { + map = new Map(modData, modData.ModFiles.OpenPackage(mapPath, new Folder("."))); + } + catch (InvalidDataException ex) + { + Console.WriteLine("Could not load map '{0}' so this data does not include the map's overrides.", mapPath); + Console.WriteLine(ex); + map = null; + } + } + + var manifestNodes = manifestPropertySelector.Invoke(modData.Manifest); + var mapProperty = map == null || mapPropertySelector == null ? null + : mapPropertySelector.Invoke(map); + + var fs = map ?? modData.DefaultFileSystem; + var topLevelNodes = MiniYaml.Load(fs, manifestNodes, mapProperty); + return topLevelNodes.FirstOrDefault(n => n.Key == key); + } + } +}