예제 #1
0
        public static bool TryFindDitherMask <TTile>(out TTile ditherMask,
                                                     ITileRegistry <TTile> tileRegistry,
                                                     string ditherTileName = null)
        {
            var ditherTileNameResolved = ditherTileName ?? "t.dither_tile";

            return(tileRegistry.TryFind(ditherTileNameResolved, out ditherMask));
        }
예제 #2
0
 public BasicTileSelector(GridMatcher matcher,
                          IMapNavigator <GridDirection> gridNavigator,
                          ITileRegistry <TRenderTile> registry,
                          string tag,
                          Func <int, int, TContext> contextProvider = null) : base(matcher, gridNavigator,
                                                                                   contextProvider)
 {
     tileExists = registry.TryFind(tag, out tile);
 }
예제 #3
0
        ITileMatcher <TTile, Nothing> CreateFloorMatcher(ITileRegistry <TTile> tiles)
        {
            bool Mapper(IFloorType floor, out TTile x, out Nothing context)
            {
                context = default(Nothing);
                return(tiles.TryFind(floor.Name, out x));
            }

            var map = GameData.Map.FloorLayer;

            return(new DirectMappingTileMatcher <IFloorType, TTile, Nothing>((x, y) => map[x, y], Mapper));
        }
예제 #4
0
        public bool TryGenerate(string tag, CardinalIndex direction, out TTile tile)
        {
            var etag = $"{prefix}{tag}_{direction}";

            if (tileRegistry.TryFind(etag, out var predefined))
            {
                tile = predefined;
                return(true);
            }

            var sourceArea = textureOperations.TileAreaForCardinalDirection(tileSize, direction);

            if (!TryFindSourceMask(direction, out var effectiveMask, out var anchor))
            {
                tile = default;
                return(false);
            }

            if (!tileRegistry.TryFind(tag, out var terrain) ||
                !terrain.HasTexture)
            {
                tile = default;
                return(false);
            }

            var data   = textureOperations.ExtractData(terrain.Texture, sourceArea);
            var result = textureOperations.CombineMask(data, effectiveMask);

            var wrappedTextureSize = new IntDimension(tileSize.Width, tileSize.Height);
            var wrappedTexture     = textureOperations.CreateTexture(etag, wrappedTextureSize);

            textureOperations.ApplyTextureData(wrappedTexture, result, sourceArea.Origin);

            tile = tileProducer.Produce(tileSize, anchor, etag, wrappedTexture);
            return(true);
        }
예제 #5
0
        public static bool FindFirstTile <TRenderTile>(this ITileRegistry <TRenderTile> tileSet,
                                                       IRuleElement t,
                                                       out TRenderTile result)
        {
            foreach (var tg in t.AllGraphicTags())
            {
                if (tileSet.TryFind(tg, out TRenderTile g))
                {
                    result = g;
                    return(true);
                }
            }

            result = default(TRenderTile);
            return(false);
        }
예제 #6
0
        public bool Match(int x, int y, TileResultCollector <TTile, IItem> onMatchFound)
        {
            bool matched = false;

            foreach (var item in gd.QueryItems(x, y))
            {
                var name = item.ItemType.Name;
                if (tiles.TryFind(name, out TTile tile))
                {
                    matched = true;
                    onMatchFound(SpritePosition.Whole, tile, item);
                }
            }

            return(matched);
        }
예제 #7
0
        public bool TryBuildBlendLayer(out ITileMatcher <TTile, Nothing> result)
        {
            var blendSelf     = new bool[GameData.Rules.TerrainTypes.Count];
            var blendGraphics = new string[GameData.Rules.TerrainTypes.Count];

            // Precompute the blending information ..
            //
            // This locates the declared blend texture for all terrain types and
            foreach (var t in GameData.Rules.TerrainTypes)
            {
                var graphic  = mappingHelper.Find(t);
                var tilename = graphic.GetBlendGraphicFor(tileSet.BlendLayer);

                if (tilename == null || !tileRegistry.TryFind(tilename, out var _))
                {
                    continue;
                }

                var indexOf = GameData.Rules.TerrainTypes.IndexOf(t);
                blendGraphics[indexOf] = tilename;
                blendSelf[indexOf]     = graphic.DrawInBlendLayer;
            }

            var terrain = GameData.Terrain;

            string MapQuery(int x, int y) => blendGraphics[terrain[x, y].TerrainIdx];
            bool IsBlending(int x, int y) => blendSelf[terrain[x, y].TerrainIdx];

            if (BlendingTileGeneratorRegistry.TryCreate(out var reg,
                                                        tileRegistry,
                                                        tileSet.RenderType,
                                                        textureOperations,
                                                        tileProducer,
                                                        tileSet.TileSize))
            {
                var p = reg.Populate(blendGraphics);
                result = new BlendNeighboursSelector2 <TTile, Nothing>(p,
                                                                       renderingConfig.MatcherNavigator,
                                                                       MapQuery,
                                                                       IsBlending);
                return(true);
            }

            result = default;
            return(false);
        }
예제 #8
0
        public bool TryFind(string tag, CardinalTileSelectorKey selector, out TRenderTile tile)
        {
            var format = suffixMapping[selector.LinearIndex];

            return(baseRegistry.TryFind(string.Format(format, tag), out tile));
        }
예제 #9
0
 public bool TryFind(string tag, NeighbourMatchPosition selector, out TRenderTile tile)
 {
     return(baseRegistry.TryFind(string.Format(format, tag, suffixMapping.Lookup(selector).Tag), out tile));
 }
예제 #10
0
 public bool TryFind(string tag, CellMapTileSelectorKey selector, out TRenderTile tile)
 {
     return(baseRegistry.TryFind(selector.Format(tag, format), out tile));
 }
예제 #11
0
 public bool TryFind(string tag, CardinalIndex selector, out TRenderTile tile)
 {
     return(baseRegistry.TryFind(string.Format(CultureInfo.InvariantCulture, format, tag, suffixMapping.Lookup(selector).Tag), out tile));
 }