Esempio n. 1
0
        private Def InitFormGuk(Guk entityData, string entityType, bool isSub = false)
        {
            if (!entityType.Exist())
            {
                entityType = entityData.Type;
            }
            if (!isSub)
            {
                isSub = entityData.HasAttr("isSub");
            }
            if (defs.ContainsKey(entityType))
            {
                throw new EntityDefExpection(string.Format("CreateDef Error: The type {0} is already exist. ", entityData.Type));
            }

            Init(entityType, entityData.SubNodes.Count);

            //不是sub的情况下Entry第一位为id
            if (!isSub)
            {
                AddEntry(Entry.Species.Attr, 1, "uuid", "ID", -1);
            }

            for (int i = 0; i < entityData.SubNodes.Count; i++)
            {
                Guk entryData = entityData.SubNodes[i];

                Entry.Species species = entryData.Type.TryConvertToEnum(Entry.Species.Attr);

                int index = entryData.Name.TryConvertToInt();

                string name     = entryData.GetAttr("name");
                string type     = entryData.GetAttr("type");
                int    indexing = entryData.GetAttr("indexing").TryConvertToInt(0);


                int limit = (species == Entry.Species.Attr ? 10 : 100);
                if (index < limit)
                {
                    throw new EntityDefExpection(string.Format("Entry Def {0} Parse Error: The Index {0} of entry <{1}:{2}> must be larger than {3} (1 for uuid, 2 for type id, 11+ for attr, 101+ for list). ", entityType, species, index, limit));
                }
                if (Indexes.Contains(index))
                {
                    throw new EntityDefExpection(string.Format("Entry Def {0} Parse Error: The index {1} of <{1}:{2}> is alreadyExist. ", entityType, species, index));
                }
                if (!name.Exist())
                {
                    throw new EntityDefExpection(string.Format("Entry Def {0} Parse Error: The entry <{1}:{2}> must have name. ", entityType, species, index));
                }
                if (!type.Exist())
                {
                    throw new EntityDefExpection(string.Format("Entry Def {0} Parse Error: The entry <{1}:{2}> must have type. ", entityType, species, index));
                }
                if (species == Entry.Species.List && indexing <= 0)
                {
                    throw new EntityDefExpection(string.Format("Entry Def {0} Parse Error: The {1} <{1}:{2}> must be indexed('indexing'='colIndex'). ", entityType, species, index));
                }

                Entry entry = AddEntry(species, index, name, type, indexing);
                if (entryData.SubNodes.Count > 0)
                {
                    Create(entryData, type, true);
                }

                foreach (var key in entryData.Attributes.Keys)
                {
                    if (key != "name" && key != "type" && key != "indexing")
                    {
                        entry.Flags.Add(key, entityData.GetAttr(key));
                    }
                }
            }
            return(this);
        }