forked from mirrors/NBTExplorer
Allow deleting chunks from region files.
This commit is contained in:
parent
5d456cf743
commit
27110539a8
3 changed files with 44 additions and 9 deletions
|
@ -31,13 +31,19 @@ namespace NBTExplorer.Model
|
|||
get { return _z; }
|
||||
}
|
||||
|
||||
protected RegionFileDataNode RegionParent
|
||||
{
|
||||
get { return Parent as RegionFileDataNode; }
|
||||
}
|
||||
|
||||
protected override NodeCapabilities Capabilities
|
||||
{
|
||||
get
|
||||
{
|
||||
return NodeCapabilities.CreateTag
|
||||
| NodeCapabilities.PasteInto
|
||||
| NodeCapabilities.Search;
|
||||
| NodeCapabilities.Search
|
||||
| NodeCapabilities.Delete;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -99,6 +105,17 @@ namespace NBTExplorer.Model
|
|||
get { return true; }
|
||||
}
|
||||
|
||||
public override bool DeleteNode ()
|
||||
{
|
||||
if (CanDeleteNode && _regionFile.HasChunk(_x, _z)) {
|
||||
RegionParent.QueueDeleteChunk(_x, _z);
|
||||
IsParentModified = true;
|
||||
return Parent.Nodes.Remove(this);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool IsNamedContainer
|
||||
{
|
||||
get { return true; }
|
||||
|
|
|
@ -10,6 +10,7 @@ namespace NBTExplorer.Model
|
|||
{
|
||||
private string _path;
|
||||
private RegionFile _region;
|
||||
private List<RegionKey> _deleteQueue = new List<RegionKey>();
|
||||
|
||||
private static Regex _namePattern = new Regex(@"^r\.(-?\d+)\.(-?\d+)\.(mcr|mca)$");
|
||||
|
||||
|
@ -100,6 +101,16 @@ namespace NBTExplorer.Model
|
|||
Nodes.Clear();
|
||||
}
|
||||
|
||||
protected override void SaveCore ()
|
||||
{
|
||||
foreach (RegionKey key in _deleteQueue) {
|
||||
if (_region.HasChunk(key.X, key.Z))
|
||||
_region.DeleteChunk(key.X, key.Z);
|
||||
}
|
||||
|
||||
_deleteQueue.Clear();
|
||||
}
|
||||
|
||||
public override bool RefreshNode ()
|
||||
{
|
||||
Dictionary<string, object> expandSet = BuildExpandSet(this);
|
||||
|
@ -108,5 +119,12 @@ namespace NBTExplorer.Model
|
|||
|
||||
return expandSet != null;
|
||||
}
|
||||
|
||||
public void QueueDeleteChunk (int rx, int rz)
|
||||
{
|
||||
RegionKey key = new RegionKey(rx, rz);
|
||||
if (!_deleteQueue.Contains(key))
|
||||
_deleteQueue.Add(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue