/// <summary>
        /// Converts a <see cref="LevelEntity"/> data object into <see cref="Level"/> domain model.
        /// </summary>
        /// <returns>The <see cref="Level"/> domain model.</returns>
        /// <param name="levelEntity">The <see cref="LevelEntity"/> data object.</param>
        internal static Level ToDomainModel(this LevelEntity levelEntity)
        {
            Level level = new Level
            {
                Id               = levelEntity.Id,
                Name             = levelEntity.Name,
                Description      = levelEntity.Description,
                Size             = new Size2D(levelEntity.Width, levelEntity.Height),
                BackgroundColour = ColourTranslator.FromHexadecimal(levelEntity.BackgroundColour),
                Tiles            = new WorldTile[levelEntity.Width, levelEntity.Height]
            };

            foreach (TerrainInstanceEntity terrainInstance in levelEntity.Terrain)
            {
                if (level.Tiles[terrainInstance.LocationX, terrainInstance.LocationY] == null)
                {
                    level.Tiles[terrainInstance.LocationX, terrainInstance.LocationY] = new WorldTile();
                }

                level.Tiles[terrainInstance.LocationX, terrainInstance.LocationY].TerrainId = terrainInstance.TerrainId;
            }

            foreach (WorldObjectInstanceEntity worldObjectInstance in levelEntity.WorldObjects)
            {
                if (level.Tiles[worldObjectInstance.LocationX, worldObjectInstance.LocationY] == null)
                {
                    level.Tiles[worldObjectInstance.LocationX, worldObjectInstance.LocationY] = new WorldTile();
                }

                level.Tiles[worldObjectInstance.LocationX, worldObjectInstance.LocationY].WorldObjectId = worldObjectInstance.WorldObjectId;
            }

            return(level);
        }
Example #2
0
        /// <summary>
        /// Converts the entity into a domain model.
        /// </summary>
        /// <returns>The domain model.</returns>
        /// <param name="worldObjectEntity">WorldObject entity.</param>
        internal static WorldObject ToDomainModel(this WorldObjectEntity worldObjectEntity)
        {
            WorldObject worldObject = new WorldObject
            {
                Id            = worldObjectEntity.Id,
                Name          = worldObjectEntity.Name,
                Description   = worldObjectEntity.Description,
                MinimapColour = ColourTranslator.FromHexadecimal(worldObjectEntity.MinimapColour)
            };

            return(worldObject);
        }
Example #3
0
        /// <summary>
        /// Converts the entity into a domain model.
        /// </summary>
        /// <returns>The domain model.</returns>
        /// <param name="textureEntity">Texture entity.</param>
        internal static Terrain ToDomainModel(this TerrainEntity textureEntity)
        {
            Terrain terrain = new Terrain
            {
                Id          = textureEntity.Id,
                Name        = textureEntity.Name,
                Description = textureEntity.Description,
                Colour      = ColourTranslator.FromHexadecimal(textureEntity.ColourHexadecimal)
            };

            return(terrain);
        }
Example #4
0
 /// <summary>
 /// Creates a colour from a hexadecimal code.
 /// </summary>
 /// <returns>The colour.</returns>
 /// <param name="hexa">Hexadecimal code.</param>
 public static Colour FromHexadecimal(string hexa) => ColourTranslator.FromHexadecimal(hexa);