Completely rewrite miniyaml tree outputting utility commands

Rename --actor-yaml to --resolved-rules <actor name>
Implement --resolved-sequences <image name>
Implement --resolved-weapons <weapon name>
This commit is contained in:
Taryn Hill
2016-11-12 15:27:40 -06:00
committed by Taryn Hill
parent ddb22ec2bd
commit 213e5532f5
6 changed files with 196 additions and 55 deletions

View File

@@ -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
{
/// <exception cref="ArgumentNullException">Thrown if manifestPropertySelector is null.</exception>
public static MiniYamlNode GetTopLevelNodeByKey(ModData modData, string key,
Func<Manifest, string[]> manifestPropertySelector,
Func<Map, MiniYaml> 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);
}
}
}