Add absolute world chunk coordinate to chunk names.

This commit is contained in:
Justin Aquadro 2015-02-28 14:50:42 -05:00
parent 975c11d3d8
commit 1fd6ec2680
3 changed files with 30 additions and 2 deletions

View file

@ -1,9 +1,13 @@
using Substrate.Core; using System;
using System.Text.RegularExpressions;
using Substrate.Core;
namespace NBTExplorer.Model namespace NBTExplorer.Model
{ {
public class CubicRegionFile : RegionFile public class CubicRegionFile : RegionFile
{ {
private static Regex _namePattern = new Regex("r2\\.(-?[0-9]+)\\.(-?[0-9]+)\\.(-?[0-9]+)\\.mc[ar]$");
private const int _sectorBytes = 256; private const int _sectorBytes = 256;
private static byte[] _emptySector = new byte[_sectorBytes]; private static byte[] _emptySector = new byte[_sectorBytes];
@ -20,5 +24,21 @@ namespace NBTExplorer.Model
{ {
get { return _emptySector; } get { return _emptySector; }
} }
public override RegionKey parseCoordinatesFromName ()
{
int x = 0;
int z = 0;
Match match = _namePattern.Match(fileName);
if (!match.Success) {
return RegionKey.InvalidRegion;
}
x = Convert.ToInt32(match.Groups[1].Value);
z = Convert.ToInt32(match.Groups[3].Value);
return new RegionKey(x, z);
}
} }
} }

View file

@ -53,7 +53,15 @@ namespace NBTExplorer.Model
public override string NodeDisplay public override string NodeDisplay
{ {
get { return "Chunk [" + _x + ", " + _z + "]"; } get
{
RegionKey key = _regionFile.parseCoordinatesFromName();
string absChunk = "";
if (key != RegionKey.InvalidRegion)
absChunk = " in world at (" + (key.X * 32 + _x) + ", " + (key.Z * 32 + _z) + ")";
return "Chunk [" + _x + ", " + _z + "]" + absChunk;
}
} }
protected override void ExpandCore () protected override void ExpandCore ()

Binary file not shown.