Пример #1
0
        public Json ToJson(bool withDef = false)
        {
            Json json = Json.Create();

            json.SetValue("__type", def.Type);
            json.SetValue("__id", ID.Exist(entityId) ? entityId : "");
            json.SetValue("__root", root);
            int indexCount = def.Indexes.Count;

            if (withDef)
            {
                json.Add("__def", def.ToJson());
            }

            for (int i = 0; i < indexCount; i++)
            {
                int   ind   = def.Indexes[i];
                var   entry = def.GetEntry(ind);
                VType type  = entry.type.TryConvertToEnum(VType.None);
                switch (entry.species)
                {
                case Def.Entry.Species.Attr:
                    Var attr = GetAttr(entry.name);
                    if (attr.Type != VType.None)
                    {
                        json.Add(ind.ToString(), attr);
                    }
                    else
                    {
                        json.Add(ind.ToString(), ((Entity)attr).ToJson(withDef));
                    }
                    break;

                case Def.Entry.Species.List:
                    VarSeq list  = _lists[ind];
                    Json   listi = json.CreateChild(ind.ToString());
                    if (list.itemType != VType.None)
                    {
                        for (int j = 0; j < list.UsedKeys.Count; j++)
                        {
                            Var key = list.keyIndexMap.GetKey(list.UsedKeys[j]);
                            listi.Add(key.Format(null), list[list.UsedKeys[j]]);
                        }
                    }
                    else
                    {
                        for (int j = 0; j < list.UsedKeys.Count; j++)
                        {
                            Var key = list.keyIndexMap.GetKey(list.UsedKeys[j]);
                            listi.Add(key.Format(null), ((Entity)list[list.UsedKeys[j]]).ToJson());
                        }
                    }
                    break;

                default: break;
                }
            }

            return(json);
        }
Пример #2
0
        public void InitialList(int index, VType type, Def.Entry entry)
        {
            string name    = entry.name;
            VarSeq newList = new VarSeq(type, entry.type);

            _lists[index] = newList;
            newList.ClearEvents();
            newList.OnAdd += (rowId, value) => {
                if (OnListAdd != null)
                {
                    OnListAdd(entityId, name, newList.keyIndexMap.GetKey(rowId));
                }
                if (OnListRowAdd != null)
                {
                    OnListRowAdd(entityId, name, rowId);
                }
                if (value is Entity)
                {
                    Entity item = value as Entity;
                    item._OnAttrChange_Private_List = delegate(ID item_entityID, string item_attrName, Var item_val) {  // 关于 '=', 一个entity最多只能属于一个列表
                        if (OnListItemChange != null)
                        {
                            OnListItemChange(entityId, name, rowId, item_attrName, item_val);
                        }
                        if (OnListRowItemChange != null)
                        {
                            OnListItemChange(entityId, name, rowId, item_attrName, item_val);
                        }
                    };
                }
                //_indexes[index].Add(rowId);
            };
            newList.OnDel += (rowId, value) => {
                if (OnListDel != null)
                {
                    OnListDel(entityId, name, newList.keyIndexMap.GetKey(rowId));
                }
                if (OnListRowDel != null)
                {
                    OnListRowDel(entityId, name, rowId);
                }
                if (value is Entity)
                {
                    Entity item = value as Entity;
                    item._OnAttrChange_Private_List = null;
                }
            };
            newList.OnClear += () => { //其实并不支持Clear
                if (OnListClr != null)
                {
                    OnListClr(entityId, name);
                }
            };
        }
Пример #3
0
        private bool TriggerOnItemListChange(int listInd, string listName, Var rowID, string colName)
        {
            VarSeq list = _lists[listInd];

            if (OnListItemChange != null)
            {
                OnListItemChange(entityId, listName, rowID, colName, GetListItem(listName, rowID, colName));
            }
            if (OnListRowItemChange != null)
            {
                OnListRowItemChange(entityId, listName, list.keyIndexMap.GetValue(rowID), colName, GetListItem(listName, rowID, colName));
            }
            return(true);
        }