// public void Splice(int index, int deleteCount, JArray insertItems) { lock ((object)this) { // Delete given item count starting at given index for (int delI = index + deleteCount - 1; delI >= index; delI -= 1) { if (delI > Count - 1) { continue; } Del(delI); this[delI].Remove(); } // Insert given items starting at given index for (var addI = 0; addI < insertItems.Count; addI += 1) { int insertI = index + addI; Insert(insertI, Tome.Conjure(insertItems[addI])); if (OnAdd != null) { OnAdd.Invoke(insertI); } } } }
// public void UnShift(JToken item) { lock ((object)this) { AddFirst(Tome.Conjure(item, root)); if (OnAdd != null) { OnAdd.Invoke(0); } } }
// public void Set(int index, JToken value) { lock ((object)this) { // Make sure the property exists, filling in missing indexes if (Count <= index) { while (Count < index) { Add(Tome.Conjure(JValue.CreateNull(), root)); } Add(Tome.Conjure(value, root)); if (OnAdd != null) { OnAdd.Invoke(index); } return; } // Assign the property JToken property = this[index]; switch (property.Type) { case JTokenType.Array: ((TomeArray)property).Assign(value); break; case JTokenType.Object: ((TomeObject)property).Assign(value); break; default: var tomeValue = property as TomeValue; if (tomeValue == null) { Mage.Instance.Logger("Tomes").Data(property).Error("property is not a tome value: " + index.ToString()); UnityEngine.Debug.Log(this); } else { tomeValue.Assign(value); } break; } } }
// public void Set(string propertyName, JToken value) { lock ((object)this) { // Make sure the property exists if (this[propertyName] == null) { Add(propertyName, Tome.Conjure(value, root)); if (OnAdd != null) { OnAdd.Invoke(propertyName); } return; } // Assign the property JToken property = this[propertyName]; switch (property.Type) { case JTokenType.Array: ((TomeArray)property).Assign(value); break; case JTokenType.Object: ((TomeObject)property).Assign(value); break; default: var tomeValue = property as TomeValue; if (tomeValue == null) { Mage.Instance.Logger("Tomes").Data(property).Error("property is not a tome value: " + propertyName); UnityEngine.Debug.Log(this); } else { tomeValue.Assign(value); } break; } } }
// public TomeArray(JArray data, JToken root) { // this.root = root; if (this.root == null) { this.root = this; } // for (var i = 0; i < data.Count; i += 1) { Add(Tome.Conjure(data[i], this.root)); } // OnChanged += EmitToParents; OnAdd += EmitChanged; OnDel += EmitChanged; }
// public TomeObject(JObject data, JToken root) { // this.root = root; if (this.root == null) { this.root = this; } // foreach (JProperty property in data.Properties()) { Add(property.Name, Tome.Conjure(property.Value, this.root)); } // OnChanged += EmitToParents; OnAdd += EmitChanged; OnDel += EmitChanged; }