Beispiel #1
0
        /// <summary>
        /// Get the faction with the specified identifier.
        /// </summary>
        /// <returns>The faction.</returns>
        /// <param name="id">Identifier.</param>
        public FactionEntity Get(string id)
        {
            List <FactionEntity> factionEntities = xmlDatabase.LoadEntities().ToList();
            FactionEntity        factionEntity   = factionEntities.FirstOrDefault(x => x.Id == id);

            if (factionEntity == null)
            {
                throw new EntityNotFoundException(id, nameof(BorderEntity).Replace("Entity", ""));
            }

            return(factionEntity);
        }
        //called each time a building's health is updated
        private void OnBuildingHealthUpdated(Building building, int value, FactionEntity source)
        {
            if (building.IsBuilt) //if the building is built then do not proceed
            {
                return;
            }

            if (building.gameObject.GetComponent <BuildingConstructionEffect>())                      //if there's a building construction effect
            {
                building.gameObject.GetComponent <BuildingConstructionEffect>().UpdateTargetHeight(); //update the target height of the construction object
            }
        }
        /// <summary>
        /// Converts the domain model into an entity.
        /// </summary>
        /// <returns>The entity.</returns>
        /// <param name="faction">Faction.</param>
        internal static FactionEntity ToEntity(this Faction faction)
        {
            FactionEntity factionEntity = new FactionEntity
            {
                Id                = faction.Id,
                Name              = faction.Name,
                Description       = faction.Description,
                ColourHexadecimal = ColorTranslator.ToHtml(faction.Colour),
                FlagId            = faction.FlagId,
                CultureId         = faction.CultureId
            };

            return(factionEntity);
        }
        /// <summary>
        /// Converts the entity into a domain model.
        /// </summary>
        /// <returns>The domain model.</returns>
        /// <param name="factionEntity">Faction entity.</param>
        internal static Faction ToDomainModel(this FactionEntity factionEntity)
        {
            Faction faction = new Faction
            {
                Id          = factionEntity.Id,
                Name        = factionEntity.Name,
                Description = factionEntity.Description,
                Colour      = ColorTranslator.FromHtml(factionEntity.ColourHexadecimal),
                FlagId      = factionEntity.FlagId,
                CultureId   = factionEntity.CultureId
            };

            return(faction);
        }
Beispiel #5
0
        /// <summary>
        /// Adds the specified faction.
        /// </summary>
        /// <param name="factionEntity">Faction.</param>
        public void Add(FactionEntity factionEntity)
        {
            List <FactionEntity> factionEntities = xmlDatabase.LoadEntities().ToList();

            factionEntities.Add(factionEntity);

            try
            {
                xmlDatabase.SaveEntities(factionEntities);
            }
            catch
            {
                throw new DuplicateEntityException(factionEntity.Id, nameof(FactionEntity).Replace("Entity", ""));
            }
        }
Beispiel #6
0
        /// <summary>
        /// Updates the specified faction.
        /// </summary>
        /// <param name="factionEntity">Faction.</param>
        public void Update(FactionEntity factionEntity)
        {
            List <FactionEntity> factionEntities       = xmlDatabase.LoadEntities().ToList();
            FactionEntity        factionEntityToUpdate = factionEntities.FirstOrDefault(x => x.Id == factionEntity.Id);

            if (factionEntityToUpdate == null)
            {
                throw new EntityNotFoundException(factionEntity.Id, nameof(BorderEntity).Replace("Entity", ""));
            }

            factionEntityToUpdate.Name              = factionEntity.Name;
            factionEntityToUpdate.Description       = factionEntity.Description;
            factionEntityToUpdate.ColourHexadecimal = factionEntity.ColourHexadecimal;
            factionEntityToUpdate.FlagId            = factionEntity.FlagId;
            factionEntityToUpdate.CultureId         = factionEntity.CultureId;

            xmlDatabase.SaveEntities(factionEntities);
        }