Exemplo n.º 1
0
        WorldGeoLayerEntity ProcessTmxLayer(TmxMap tmxMap, TmxLayer tmxLayer)
        {
            string tilesetName = tmxLayer.Properties["tileset"];

            if (string.IsNullOrWhiteSpace(tilesetName) ||
                tmxMap.Tilesets.ToList().FindIndex(t => t.Name == tilesetName) < 0)
            {
                throw new InvalidEntityFieldException(nameof(WorldGeoLayerEntity.Tileset), tmxLayer.Name, nameof(WorldGeoLayerEntity));
            }

            TmxTileset tmxTileset = tmxMap.Tilesets[tilesetName];

            WorldGeoLayerEntity layer = new WorldGeoLayerEntity
            {
                Name    = tmxLayer.Name,
                Tiles   = new int[tmxMap.Width, tmxMap.Height],
                Tileset = tmxTileset.Name,
                Opacity = (float)tmxLayer.Opacity,
                Visible = tmxLayer.Visible
            };

            Parallel.ForEach(tmxLayer.Tiles, tile => layer.Tiles[tile.X, tile.Y] = Math.Max(-1, tile.Gid - tmxTileset.FirstGid));

            return(layer);
        }
        /// <summary>
        /// Converts the domain model into an entity.
        /// </summary>
        /// <returns>The entity.</returns>
        /// <param name="worldGeoLayer">World geographic layer.</param>
        internal static WorldGeoLayerEntity ToEntity(this WorldGeoLayer worldGeoLayer)
        {
            WorldGeoLayerEntity worldGeoLayerEntity = new WorldGeoLayerEntity
            {
                Name    = worldGeoLayer.Name,
                Tileset = worldGeoLayer.Tileset,
                Tiles   = worldGeoLayer.Tiles,
                Opacity = worldGeoLayer.Opacity,
                Visible = worldGeoLayer.Visible
            };

            return(worldGeoLayerEntity);
        }
        /// <summary>
        /// Converts the entity into a domain model.
        /// </summary>
        /// <returns>The domain model.</returns>
        /// <param name="worldGeoLayerEntity">World geographic layer entity.</param>
        internal static WorldGeoLayer ToDomainModel(this WorldGeoLayerEntity worldGeoLayerEntity)
        {
            WorldGeoLayer worldGeoLayer = new WorldGeoLayer
            {
                Name    = worldGeoLayerEntity.Name,
                Tileset = worldGeoLayerEntity.Tileset,
                Tiles   = worldGeoLayerEntity.Tiles,
                Opacity = worldGeoLayerEntity.Opacity,
                Visible = worldGeoLayerEntity.Visible
            };

            return(worldGeoLayer);
        }