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:
96
OpenRA.Mods.Common/UtilityCommands/ExtractMapRules.cs
Normal file
96
OpenRA.Mods.Common/UtilityCommands/ExtractMapRules.cs
Normal file
@@ -0,0 +1,96 @@
|
||||
#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.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using OpenRA.FileSystem;
|
||||
|
||||
namespace OpenRA.Mods.Common.UtilityCommands
|
||||
{
|
||||
public class ExtractMapRules : IUtilityCommand
|
||||
{
|
||||
string IUtilityCommand.Name => "--map-rules";
|
||||
bool IUtilityCommand.ValidateArguments(string[] args) { return args.Length == 2; }
|
||||
|
||||
static 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<ImmutableArray<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"));
|
||||
}
|
||||
|
||||
static void MergeAndPrintFluentMessages(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<ImmutableArray<string>>("value", value.Value);
|
||||
foreach (var f in files)
|
||||
{
|
||||
include |= map.Package.Contains(f);
|
||||
if (include)
|
||||
{
|
||||
nodes.Add(new MiniYamlNode("base64", Convert.ToBase64String(map.Open(f).ReadAllBytes())));
|
||||
}
|
||||
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"));
|
||||
}
|
||||
|
||||
[Desc("MAPFILE", "Merge custom map rules into a form suitable for including in map.yaml.")]
|
||||
void IUtilityCommand.Run(Utility utility, string[] args)
|
||||
{
|
||||
var modData = Game.ModData = utility.ModData;
|
||||
|
||||
var map = new Map(modData, new Folder(Platform.EngineDir).OpenPackage(args[1], modData.ModFiles));
|
||||
MergeAndPrint(map, "Rules", map.RuleDefinitions);
|
||||
MergeAndPrint(map, "Sequences", map.SequenceDefinitions);
|
||||
MergeAndPrint(map, "ModelSequences", map.ModelSequenceDefinitions);
|
||||
MergeAndPrint(map, "Weapons", map.WeaponDefinitions);
|
||||
MergeAndPrint(map, "Voices", map.VoiceDefinitions);
|
||||
MergeAndPrint(map, "Music", map.MusicDefinitions);
|
||||
MergeAndPrint(map, "Notifications", map.NotificationDefinitions);
|
||||
MergeAndPrintFluentMessages(map, "FluentMessages", map.FluentMessageDefinitions);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user