コード例 #1
0
ファイル: Project.cs プロジェクト: 1144822034/sc2.2mobile
        public List <Entity> LoadEntities(EntityDataList entityDataList)
        {
            List <Entity>            list          = new List <Entity>(entityDataList.EntitiesData.Count);
            Dictionary <int, Entity> dictionary    = new Dictionary <int, Entity>();
            IdToEntityMap            idToEntityMap = new IdToEntityMap(dictionary);

            foreach (EntityData entitiesDatum in entityDataList.EntitiesData)
            {
                try
                {
                    Entity entity = new Entity(this, entitiesDatum.ValuesDictionary);
                    list.Add(entity);
                    if (entitiesDatum.Id != 0)
                    {
                        dictionary.Add(entitiesDatum.Id, entity);
                    }
                }
                catch (Exception innerException)
                {
                    throw new Exception($"Error creating entity from template \"{entitiesDatum.ValuesDictionary.DatabaseObject.Name}\".", innerException);
                }
            }
            int num = 0;

            foreach (EntityData entitiesDatum2 in entityDataList.EntitiesData)
            {
                list[num].publicLoadEntity(entitiesDatum2.ValuesDictionary, idToEntityMap);
                num++;
            }
            return(list);
        }
コード例 #2
0
ファイル: Project.cs プロジェクト: 1144822034/sc2.2mobile
        public EntityDataList SaveEntities(IEnumerable <Entity> entities)
        {
            Dictionary <Entity, bool> dictionary = DetermineNotOwnedEntities(entities);
            int num = 1;
            Dictionary <Entity, int> dictionary2   = new Dictionary <Entity, int>();
            EntityToIdMap            entityToIdMap = new EntityToIdMap(dictionary2);

            foreach (Entity key in dictionary.Keys)
            {
                dictionary2.Add(key, num);
                num++;
            }
            EntityDataList entityDataList = new EntityDataList();

            entityDataList.EntitiesData = new List <EntityData>(dictionary.Keys.Count);
            foreach (Entity key2 in dictionary.Keys)
            {
                EntityData entityData = new EntityData();
                entityData.Id = entityToIdMap.FindId(key2);
                entityData.ValuesDictionary = new ValuesDictionary();
                entityData.ValuesDictionary.DatabaseObject = key2.ValuesDictionary.DatabaseObject;
                key2.publicSaveEntity(entityData.ValuesDictionary, entityToIdMap);
                entityDataList.EntitiesData.Add(entityData);
            }
            return(entityDataList);
        }
コード例 #3
0
        public ProjectData(GameDatabase gameDatabase, XElement projectNode, ValuesDictionary overrides, bool ignoreInvalidEntities)
        {
            Guid           attributeValue  = XmlUtils.GetAttributeValue(projectNode, "Guid", Guid.Empty);
            string         attributeValue2 = XmlUtils.GetAttributeValue(projectNode, "Name", string.Empty);
            DatabaseObject databaseObject;

            if (attributeValue != Guid.Empty)
            {
                databaseObject = gameDatabase.Database.FindDatabaseObject(attributeValue, gameDatabase.ProjectTemplateType, throwIfNotFound: true);
            }
            else
            {
                if (string.IsNullOrEmpty(attributeValue2))
                {
                    throw new InvalidOperationException("Project template guid or name must be specified.");
                }
                databaseObject = gameDatabase.Database.FindDatabaseObject(attributeValue2, gameDatabase.ProjectTemplateType, throwIfNotFound: true);
            }
            ValuesDictionary = new ValuesDictionary();
            ValuesDictionary.PopulateFromDatabaseObject(databaseObject);
            XElement xElement = XmlUtils.FindChildElement(projectNode, "Subsystems", throwIfNotFound: false);

            if (xElement != null)
            {
                ValuesDictionary.ApplyOverrides(xElement);
            }
            if (overrides != null)
            {
                ValuesDictionary.ApplyOverrides(overrides);
            }
            XElement xElement2 = XmlUtils.FindChildElement(projectNode, "Entities", throwIfNotFound: false);

            if (xElement2 != null)
            {
                EntityDataList = new EntityDataList(gameDatabase, xElement2, ignoreInvalidEntities);
            }
        }