Initial commit: OpenRA game engine
Fork from OpenRA/OpenRA with one-click launch script (start-ra.cmd) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
53
OpenRA.Mods.Common/UtilityCommands/UtiliyHelpers.cs
Normal file
53
OpenRA.Mods.Common/UtilityCommands/UtiliyHelpers.cs
Normal file
@@ -0,0 +1,53 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright (c) The OpenRA Developers and Contributors
|
||||
* 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.Collections.Immutable;
|
||||
using System.IO;
|
||||
using OpenRA.FileSystem;
|
||||
|
||||
namespace OpenRA.Mods.Common.UtilityCommands
|
||||
{
|
||||
public static class UtiliyHelpers
|
||||
{
|
||||
public static MiniYamlNode GetTopLevelNodeByKey(ModData modData, string key,
|
||||
Func<Manifest, ImmutableArray<string>> manifestPropertySelector,
|
||||
Func<Map, MiniYaml> mapPropertySelector = null,
|
||||
string mapPath = null)
|
||||
{
|
||||
if (manifestPropertySelector == null)
|
||||
throw new ArgumentNullException(nameof(manifestPropertySelector), "Must pass a non-null manifestPropertySelector");
|
||||
|
||||
Map map = null;
|
||||
if (mapPath != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
map = new Map(modData, new Folder(Platform.EngineDir).OpenPackage(mapPath, modData.ModFiles));
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user