Files
OpenRA/OpenRA.Mods.Common/UtilityCommands/ResizeMapCommand.cs
let5sne.win10 9cf6ebb986
Some checks failed
Continuous Integration / Linux (.NET 8.0) (push) Has been cancelled
Continuous Integration / Windows (.NET 8.0) (push) Has been cancelled
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>
2026-01-10 21:46:54 +08:00

78 lines
2.1 KiB
C#

#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.Linq;
using OpenRA.FileSystem;
namespace OpenRA.Mods.Common.UtilityCommands
{
public class ResizeMapCommand : IUtilityCommand
{
string IUtilityCommand.Name => "--resize-map";
int width;
int height;
Map map;
bool IUtilityCommand.ValidateArguments(string[] args)
{
if (args.Length < 4)
return false;
if (!int.TryParse(args[2], out width) && width > 0)
{
Console.WriteLine("Invalid WIDTH");
return false;
}
if (!int.TryParse(args[3], out height) && height > 0)
{
Console.WriteLine("Invalid HEIGHT");
return false;
}
return true;
}
[Desc("MAPFILE", "WIDTH", "HEIGHT", "Resize the map at the bottom corners.")]
void IUtilityCommand.Run(Utility utility, string[] args)
{
var modData = Game.ModData = utility.ModData;
map = new Map(modData, new Folder(Platform.EngineDir).OpenPackage(args[1], modData.ModFiles));
Console.WriteLine("Resizing map {0} from {1} to {2},{3}", map.Title, map.MapSize, width, height);
map.Resize(width, height);
var forRemoval = new List<MiniYamlNode>();
foreach (var kv in map.ActorDefinitions)
{
var actor = new ActorReference(kv.Value.Value, kv.Value);
var locationInit = actor.GetOrDefault<LocationInit>();
if (locationInit == null)
continue;
if (!map.Contains(locationInit.Value))
{
Console.WriteLine($"Removing actor {actor.Type} located at {locationInit.Value} due being outside of the new map boundaries.");
forRemoval.Add(kv);
}
}
map.ActorDefinitions = map.ActorDefinitions.Except(forRemoval).ToArray();
map.Save((IReadWritePackage)map.Package);
}
}
}