NBTExplorer/Model/CompoundTagContainer.cs

66 lines
1.4 KiB
C#
Raw Normal View History

2012-08-31 05:29:32 +00:00
using System;
using System.Collections.Generic;
using Substrate.Nbt;
namespace NBTExplorer.Model
{
public class CompoundTagContainer : INamedTagContainer
{
private TagNodeCompound _tag;
public CompoundTagContainer (TagNodeCompound tag)
{
_tag = tag;
}
public int TagCount
{
get { return _tag.Count; }
}
public IEnumerable<string> TagNamesInUse
{
get { return _tag.Keys; }
}
public string GetTagName (TagNode tag)
{
foreach (String name in _tag.Keys)
if (_tag[name] == tag)
return name;
return null;
}
public bool AddTag (TagNode tag, string name)
{
if (_tag.ContainsKey(name))
return false;
_tag.Add(name, tag);
return true;
}
public bool RenameTag (TagNode tag, string name)
{
if (_tag.ContainsKey(name))
return false;
string oldName = GetTagName(tag);
_tag.Remove(oldName);
_tag.Add(name, tag);
return true;
}
public bool DeleteTag (TagNode tag)
{
foreach (String name in _tag.Keys)
if (_tag[name] == tag)
return _tag.Remove(name);
return false;
}
}
}