コード例 #1
0
        //
        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);
                    }
                }
            }
        }
コード例 #2
0
 //
 public void UnShift(JToken item)
 {
     lock ((object)this)
     {
         AddFirst(Tome.Conjure(item, root));
         if (OnAdd != null)
         {
             OnAdd.Invoke(0);
         }
     }
 }
コード例 #3
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;
                }
            }
        }
コード例 #4
0
ファイル: TomeObject.cs プロジェクト: zsarette/mage-sdk-unity
        //
        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;
                }
            }
        }
コード例 #5
0
        //
        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;
        }
コード例 #6
0
ファイル: TomeObject.cs プロジェクト: zsarette/mage-sdk-unity
        //
        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;
        }