-Added "-d" parameter to "/region info". Use to display the given region's boundaries as wires.

This commit is contained in:
CoderCow 2013-07-01 20:06:17 +02:00
parent 8c23d68727
commit 33b1ca969b
2 changed files with 69 additions and 5 deletions

View file

@ -24,7 +24,7 @@ using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading;
using System.Threading;
using TShockAPI.PluginUpdater;
using Terraria;
using TShockAPI.DB;
@ -2845,16 +2845,27 @@ namespace TShockAPI
{
if (args.Parameters.Count > 1)
{
if (args.Parameters.Count > 4)
{
args.Player.SendErrorMessage("Invalid syntax! Proper syntax: /region info [region] [-d] [page]");
break;
}
string regionName = args.Parameters[1];
bool displayBoundaries = args.Parameters.Skip(2).Any(
p => p.Equals("-d", StringComparison.InvariantCultureIgnoreCase)
);
Region region = TShock.Regions.GetRegionByName(regionName);
if (region == null)
{
args.Player.SendErrorMessage("Region {0} does not exist.", regionName);
args.Player.SendErrorMessage("Region \"{0}\" does not exist.", regionName);
break;
}
int pageNumberIndex = displayBoundaries ? 3 : 2;
int pageNumber;
if (!PaginationTools.TryParsePageNumber(args.Parameters, 2, args.Player, out pageNumber))
if (!PaginationTools.TryParsePageNumber(args.Parameters, pageNumberIndex, args.Player, out pageNumber))
break;
List<string> lines = new List<string>
@ -2901,6 +2912,38 @@ namespace TShockAPI
FooterFormat = "Type /region info {0} for more information."
}
);
if (displayBoundaries)
{
Rectangle regionArea = region.Area;
foreach (Point boundaryPoint in Utils.Instance.EnumerateRegionBoundaries(regionArea))
{
// Preferring dotted lines as those should easily be distinguishable from actual wires.
if ((boundaryPoint.X + boundaryPoint.Y & 1) == 0)
{
// Could be improved by sending raw tile data to the client instead but not really
// worth the effort as chances are very low that overwriting the wire for a few
// nanoseconds will cause much trouble.
Tile tile = Main.tile[boundaryPoint.X, boundaryPoint.Y];
bool oldWireState = tile.wire;
tile.wire = true;
try {
args.Player.SendTileSquare(boundaryPoint.X, boundaryPoint.Y, 1);
} finally {
tile.wire = oldWireState;
}
}
}
new Timer((dummy) => {
foreach (Point boundaryPoint in Utils.Instance.EnumerateRegionBoundaries(regionArea))
if ((boundaryPoint.X + boundaryPoint.Y & 1) == 0)
args.Player.SendTileSquare(boundaryPoint.X, boundaryPoint.Y, 1);
},
null, 5000, Timeout.Infinite
);
}
}
else
{
@ -3034,7 +3077,7 @@ namespace TShockAPI
"remove [user] [region] - Removes a user from a region.",
"allowg [group] [region] - Allows a user group to a region.",
"removeg [group] [region] - Removes a user group from a region.",
"info [region] - Displays several information about the given region.",
"info [region] [-d] - Displays several information about the given region.",
"protect [name] [true/false] - Sets whether the tiles inside the region are protected or not.",
"z [name] [#] - Sets the z-order of the region.",
};

View file

@ -22,7 +22,8 @@ using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Security.Cryptography;
using System.Text;
using System.Text;
using TShockAPI.DB;
using Terraria;
namespace TShockAPI
@ -841,5 +842,25 @@ namespace TShockAPI
}
return new string(returnstr);
}
/// <summary>
/// Enumerates boundary points of the given region's rectangle.
/// </summary>
/// <param name="regionArea">The region's area to enumerate through.</param>
/// <returns>The enumerated boundary points.</returns>
public IEnumerable<Point> EnumerateRegionBoundaries(Rectangle regionArea)
{
for (int x = 0; x < regionArea.Width + 1; x++)
{
yield return new Point(regionArea.Left + x, regionArea.Top);
yield return new Point(regionArea.Left + x, regionArea.Bottom);
}
for (int y = 1; y < regionArea.Height; y++)
{
yield return new Point(regionArea.Left, regionArea.Top + y);
yield return new Point(regionArea.Right, regionArea.Top + y);
}
}
}
}