Merge pull request #10353 from Mailaender/resize-map
Added a resize map command
This commit is contained in:
@@ -838,7 +838,7 @@ namespace OpenRA
|
|||||||
return delta.Yaw.Facing;
|
return delta.Yaw.Facing;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Resize(int width, int height) // editor magic.
|
public void Resize(int width, int height)
|
||||||
{
|
{
|
||||||
var oldMapTiles = MapTiles.Value;
|
var oldMapTiles = MapTiles.Value;
|
||||||
var oldMapResources = MapResources.Value;
|
var oldMapResources = MapResources.Value;
|
||||||
@@ -850,9 +850,10 @@ namespace OpenRA
|
|||||||
MapHeight = Exts.Lazy(() => CellLayer.Resize(oldMapHeight, newSize, oldMapHeight[MPos.Zero]));
|
MapHeight = Exts.Lazy(() => CellLayer.Resize(oldMapHeight, newSize, oldMapHeight[MPos.Zero]));
|
||||||
MapSize = new int2(newSize);
|
MapSize = new int2(newSize);
|
||||||
|
|
||||||
var tl = new MPos(0, 0).ToCPos(this);
|
var tl = new MPos(0, 0);
|
||||||
var br = new MPos(MapSize.X - 1, MapSize.Y - 1).ToCPos(this);
|
var br = new MPos(MapSize.X - 1, MapSize.Y - 1);
|
||||||
AllCells = new CellRegion(Grid.Type, tl, br);
|
AllCells = new CellRegion(Grid.Type, tl.ToCPos(this), br.ToCPos(this));
|
||||||
|
SetBounds(new PPos(tl.U + 1, tl.V + 1), new PPos(br.U - 1, br.V - 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetBounds(PPos tl, PPos br)
|
public void SetBounds(PPos tl, PPos br)
|
||||||
|
|||||||
@@ -731,6 +731,7 @@
|
|||||||
<Compile Include="Util.cs" />
|
<Compile Include="Util.cs" />
|
||||||
<Compile Include="Traits\Render\WithGateSpriteBody.cs" />
|
<Compile Include="Traits\Render\WithGateSpriteBody.cs" />
|
||||||
<Compile Include="ColorValidator.cs" />
|
<Compile Include="ColorValidator.cs" />
|
||||||
|
<Compile Include="UtilityCommands\ResizeMapCommand.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
|
|||||||
73
OpenRA.Mods.Common/UtilityCommands/ResizeMapCommand.cs
Normal file
73
OpenRA.Mods.Common/UtilityCommands/ResizeMapCommand.cs
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
#region Copyright & License Information
|
||||||
|
/*
|
||||||
|
* Copyright 2007-2015 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. For more information,
|
||||||
|
* see COPYING.
|
||||||
|
*/
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
|
namespace OpenRA.Mods.Common.UtilityCommands
|
||||||
|
{
|
||||||
|
public class ResizeMapCommand : IUtilityCommand
|
||||||
|
{
|
||||||
|
public string Name { get { return "--resize-map"; } }
|
||||||
|
|
||||||
|
int width;
|
||||||
|
int height;
|
||||||
|
|
||||||
|
Map map;
|
||||||
|
|
||||||
|
public bool 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.")]
|
||||||
|
public void Run(ModData modData, string[] args)
|
||||||
|
{
|
||||||
|
Game.ModData = modData;
|
||||||
|
map = new Map(args[1]);
|
||||||
|
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.ToDictionary());
|
||||||
|
var location = actor.InitDict.Get<LocationInit>().Value(null);
|
||||||
|
if (!map.Contains(location))
|
||||||
|
{
|
||||||
|
Console.WriteLine("Removing actor {0} located at {1} due being outside of the new map boundaries.".F(actor.Type, location));
|
||||||
|
forRemoval.Add(kv);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var kv in forRemoval)
|
||||||
|
map.ActorDefinitions.Remove(kv);
|
||||||
|
|
||||||
|
map.Save(map.Path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user