Class TreeAttribute
- Namespace
- Vintagestory.API.Datastructures
- Assembly
- VintagestoryAPI.dll
A datastructure to hold generic data for most primitives (int, string, float, etc.). But can also hold generic data using the ByteArrayAttribute + class serialization
public class TreeAttribute : ITreeAttribute, IAttribute, IEnumerable<KeyValuePair<string, IAttribute>>, IEnumerable
- Inheritance
-
TreeAttribute
- Implements
- Derived
- Inherited Members
- Extension Methods
Constructors
TreeAttribute()
public TreeAttribute()
Fields
AttributeIdMapping
public static Dictionary<int, Type> AttributeIdMapping
Field Value
depth
protected int depth
Field Value
Properties
Count
Amount of elements in this Tree attribute
public int Count { get; }
Property Value
this[string]
Will return null if given attribute does not exist
public IAttribute this[string key] { get; set; }
Parameters
key
string
Property Value
Keys
public string[] Keys { get; }
Property Value
- string[]
Values
Returns all values inside this tree attributes
public IAttribute[] Values { get; }
Property Value
Methods
Clone()
Creates a deep copy of the attribute tree
public virtual ITreeAttribute Clone()
Returns
CreateFromBytes(byte[])
public static TreeAttribute CreateFromBytes(byte[] blockEntityData)
Parameters
blockEntityData
byte[]
Returns
DeleteAttributeByPath(string)
public void DeleteAttributeByPath(string path)
Parameters
path
string
Equals(IWorldAccessor, IAttribute)
Returns true if given tree exactly matches this one
public bool Equals(IWorldAccessor worldForResolve, IAttribute other)
Parameters
worldForResolve
IWorldAccessorother
IAttribute
Returns
Equals(IWorldAccessor, IAttribute, string, params string[])
public bool Equals(IWorldAccessor worldForResolve, IAttribute other, string currentPath, params string[] ignorePaths)
Parameters
worldForResolve
IWorldAccessorother
IAttributecurrentPath
stringignorePaths
string[]
Returns
Equals(IWorldAccessor, IAttribute, params string[])
public bool Equals(IWorldAccessor worldForResolve, IAttribute other, params string[] ignorePaths)
Parameters
worldForResolve
IWorldAccessorother
IAttributeignorePaths
string[]
Returns
FromBytes(byte[])
public virtual void FromBytes(byte[] data)
Parameters
data
byte[]
FromBytes(BinaryReader)
public virtual void FromBytes(BinaryReader stream)
Parameters
stream
BinaryReader
FromJson(string)
public static IAttribute FromJson(string json)
Parameters
json
string
Returns
GetAsBool(string, bool)
Returns true/false, for whatever type of attribute is found for given key
public virtual bool GetAsBool(string key, bool defaultValue = false)
Parameters
Returns
GetAsInt(string, int)
Same as (int)GetDecimal(key, defValue);
public virtual int GetAsInt(string key, int defaultValue = 0)
Parameters
Returns
GetAsString(string, string)
Retrieves the value of given attribute, independent of attribute type
public virtual string GetAsString(string key, string defaultValue = null)
Parameters
Returns
GetAttribute(string)
public IAttribute GetAttribute(string key)
Parameters
key
string
Returns
GetAttributeByPath(string)
public IAttribute GetAttributeByPath(string path)
Parameters
path
string
Returns
GetAttributeId()
public int GetAttributeId()
Returns
GetBool(string, bool)
Retrieves a bool or default value if key is not found
public virtual bool GetBool(string key, bool defaultValue = false)
Parameters
Returns
GetBytes(string, byte[])
Retrieves a byte array or defaultValue if key is not found
public virtual byte[] GetBytes(string key, byte[] defaultValue = null)
Parameters
Returns
- byte[]
GetDecimal(string, double)
Retrieves an int, float, long or double value. Whatever attribute is found for given key, in aformentioned order. If its a string its converted to double
public virtual double GetDecimal(string key, double defaultValue = 0)
Parameters
Returns
GetDouble(string, double)
Retrieves a double or defaultValue if key is not found
public virtual double GetDouble(string key, double defaultValue = 0)
Parameters
Returns
GetEnumerator()
public IEnumerator<KeyValuePair<string, IAttribute>> GetEnumerator()
Returns
GetFloat(string, float)
Retrieves a float or defaultvalue if key is not found
public virtual float GetFloat(string key, float defaultValue = 0)
Parameters
Returns
GetHashCode()
Serves as the default hash function.
public override int GetHashCode()
Returns
- int
A hash code for the current object.
GetHashCode(string[])
public int GetHashCode(string[] ignoredAttributes)
Parameters
ignoredAttributes
string[]
Returns
GetInt(string, int)
Retrieves an int or default value if key is not found
public virtual int GetInt(string key, int defaultValue = 0)
Parameters
Returns
GetItemstack(string, ItemStack)
Retrieves an itemstack or defaultValue if key is not found. Be sure to call stack.ResolveBlockOrItem() after retrieving it.
public ItemStack GetItemstack(string key, ItemStack defaultValue = null)
Parameters
Returns
GetLong(string, long)
Retrieves a long or default value if key is not found
public virtual long GetLong(string key, long defaultValue = 0)
Parameters
Returns
GetModelTransform(string)
public virtual ModelTransform GetModelTransform(string key)
Parameters
key
string
Returns
GetOrAddTreeAttribute(string)
Retrieves an attribute tree or adds it if key is not found. Throws an exception if the key does exist but is not a tree.
public virtual ITreeAttribute GetOrAddTreeAttribute(string key)
Parameters
key
string
Returns
GetString(string, string)
Retrieves a string attribute or defaultValue if key is not found
public virtual string GetString(string key, string defaultValue = null)
Parameters
Returns
GetStringArray(string, string[])
Retrieves a string or defaultValue if key is not found
public virtual string[] GetStringArray(string key, string[] defaultValue = null)
Parameters
Returns
- string[]
GetTreeAttribute(string)
Retrieves an attribute tree or null if key is not found
public virtual ITreeAttribute GetTreeAttribute(string key)
Parameters
key
string
Returns
GetValue()
public object GetValue()
Returns
HasAttribute(string)
True if this attribute exists
public bool HasAttribute(string key)
Parameters
key
string
Returns
IndexOf(string)
[Obsolete("May not return consistent results if the TreeAttribute changes between calls")]
public int IndexOf(string key)
Parameters
key
string
Returns
IsSubSetOf(IWorldAccessor, IAttribute)
Returns true if given tree contains all of elements of this one, but given tree may contain also more elements. Individual node values are exactly matched.
public bool IsSubSetOf(IWorldAccessor worldForResolve, IAttribute other)
Parameters
worldForResolve
IWorldAccessorother
IAttribute
Returns
MergeAttribute(TreeAttribute, string, IAttribute)
protected static void MergeAttribute(TreeAttribute dstTree, string srcKey, IAttribute srcAttr)
Parameters
dstTree
TreeAttributesrcKey
stringsrcAttr
IAttribute
MergeTree(ITreeAttribute)
Merges the sourceTree into the current one
public virtual void MergeTree(ITreeAttribute sourceTree)
Parameters
sourceTree
ITreeAttribute
MergeTree(TreeAttribute, TreeAttribute)
protected static void MergeTree(TreeAttribute dstTree, TreeAttribute srcTree)
Parameters
dstTree
TreeAttributesrcTree
TreeAttribute
RegisterAttribute(int, Type)
public static void RegisterAttribute(int attrId, Type type)
Parameters
RemoveAttribute(string)
Removes an attribute
public virtual void RemoveAttribute(string key)
Parameters
key
string
Set(string, IAttribute)
Set a value. Returns itself for method chaining
public TreeAttribute Set(string key, IAttribute value)
Parameters
key
stringvalue
IAttribute
Returns
SetAttribute(string, IAttribute)
public virtual void SetAttribute(string key, IAttribute value)
Parameters
key
stringvalue
IAttribute
SetBool(string, bool)
Creates a bool attribute with given key and value
public virtual void SetBool(string key, bool value)
Parameters
SetBytes(string, byte[])
Creates a byte[] attribute with given key and value
public virtual void SetBytes(string key, byte[] value)
Parameters
SetDouble(string, double)
Creates a double attribute with given key and value
public virtual void SetDouble(string key, double value)
Parameters
SetFloat(string, float)
Creates a float attribute with given key and value
Side note: If you need this attribute to be compatible with deserialized json - use SetDouble()
public virtual void SetFloat(string key, float value)
Parameters
SetInt(string, int)
Creates an int attribute with given key and value
Side note: If you need this attribute to be compatible with deserialized json - use SetLong()
public virtual void SetInt(string key, int value)
Parameters
SetItemstack(string, ItemStack)
Sets given item stack with given key
public void SetItemstack(string key, ItemStack itemstack)
Parameters
SetLong(string, long)
Creates a long attribute with given key and value
public virtual void SetLong(string key, long value)
Parameters
SetString(string, string)
Creates a string attribute with given key and value
public virtual void SetString(string key, string value)
Parameters
SetStringArray(string, string[])
public virtual void SetStringArray(string key, string[] values)
Parameters
SortedCopy(bool)
Returns a ITreeAttribute sorted alphabetically by key. Does not modify the existing ITreeAttribute
public OrderedDictionary<string, IAttribute> SortedCopy(bool recursive = false)
Parameters
recursive
bool
Returns
ToBytes()
public virtual byte[] ToBytes()
Returns
- byte[]
ToBytes(BinaryWriter)
public virtual void ToBytes(BinaryWriter stream)
Parameters
stream
BinaryWriter
ToJsonToken()
public string ToJsonToken()
Returns
ToJsonToken(IEnumerable<KeyValuePair<string, IAttribute>>)
public static string ToJsonToken(IEnumerable<KeyValuePair<string, IAttribute>> attributes)
Parameters
attributes
IEnumerable<KeyValuePair<string, IAttribute>>
Returns
TryGetAttribute(string, out IAttribute)
Similar to TryGetValue for a Dictionary
public bool TryGetAttribute(string key, out IAttribute value)
Parameters
key
stringvalue
IAttribute
Returns
TryGetBool(string)
Retrieves a bool or null if the key is not found
public virtual bool? TryGetBool(string key)
Parameters
key
string
Returns
- bool?
TryGetDouble(string)
Retrieves a double or null if key is not found
public virtual double? TryGetDouble(string key)
Parameters
key
string
Returns
TryGetFloat(string)
Retrieves a float or null if the key is not found
public virtual float? TryGetFloat(string key)
Parameters
key
string
Returns
TryGetInt(string)
Retrieves an int or null if the key is not found
public virtual int? TryGetInt(string key)
Parameters
key
string
Returns
- int?
TryGetLong(string)
Retrieves a long or null value if key is not found
public virtual long? TryGetLong(string key)
Parameters
key
string
Returns
- long?