Exemplo n.º 1
0
        ITileMatcher <TTile, Nothing> CreateDecoMatcher(ITileRegistry <TTile> tiles)
        {
            var gd      = GameData;
            var map     = gd.Map.DecorationLayer;
            var wallMap = gd.Map.WallLayer;

            bool IsNeitherWallOrPassageFn(int x, int y)
            {
                var tile = wallMap[x, y];

                return(!gd.Rules.Walls.Stone.Equals(tile) && !gd.Rules.Walls.Passage.Equals(tile));
            }

            var wallsAsCardinals = new CardinalTileRegistry <TTile>(tiles);

            var wallTypeSelector =
                new DistinctTileMatcher <IDecorationType, TTile, Nothing>((x, y) => map[x, y]);

            foreach (var decorationType in gd.Rules.DecorationTypes.Skip(1))
            {
                var target = decorationType;
                wallTypeSelector.Add(decorationType,
                                     new CardinalTileSelector <TTile, Nothing>(IsNeitherWallOrPassageFn,
                                                                               CreateMatcher(map, target),
                                                                               RenderingConfig.MatcherNavigator,
                                                                               wallsAsCardinals, target.Name));
            }

            return(wallTypeSelector);
        }
Exemplo n.º 2
0
 public CardinalTileRegistry(ITileRegistry <TRenderTile> baseRegistry,
                             ITileTagEntrySelectionFactory <bool> tags = null,
                             string tagFormat = null)
 {
     this.baseRegistry  = baseRegistry ?? throw new ArgumentNullException(nameof(baseRegistry));
     this.suffixMapping = CardinalTileSelectorKey.Values.Select(e => Format(e, tags, tagFormat)).ToArray();
 }
Exemplo n.º 3
0
 public CornerTileRegistry(ITileRegistry <TRenderTile> baseRegistry,
                           ITileTagEntrySelectionFactory <bool> booleanFormats,
                           ITileTagEntrySelectionFactory <Direction> directions,
                           string suffixFormat,
                           string format) : this(baseRegistry, booleanFormats, directions,
                                                 ProduceCombinedFormatString(suffixFormat, format))
 {
 }
Exemplo n.º 4
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));
        }
Exemplo n.º 5
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);
 }
Exemplo n.º 6
0
        public DiagonalTileRegistry(ITileRegistry <TRenderTile> baseRegistry,
                                    ITileTagEntrySelectionFactory <bool> tags = null,
                                    string tagFormat = null)
        {
            this.baseRegistry = baseRegistry ?? throw new ArgumentNullException(nameof(baseRegistry));
            var tagProvider  = tags ?? TileTagEntries.CreateFlagTagEntries();
            var formatString = tagFormat ?? "{{0}}_nw{0}ne{1}se{2}sw{3}";

            this.suffixMapping = DiagonalTileSelectionKey.Values.Select(e => Format(e, tagProvider, formatString)).ToArray();
        }
Exemplo n.º 7
0
 public CornerTileRegistry(ITileRegistry <TRenderTile> baseRegistry,
                           ITileTagEntrySelectionFactory <bool> booleanFormats  = null,
                           ITileTagEntrySelectionFactory <Direction> directions = null,
                           string format = null)
 {
     this.baseRegistry  = baseRegistry;
     this.suffixMapping = GenerateSuffixes(booleanFormats ?? TileTagEntries.CreateFlagTagEntries(),
                                           directions ?? TileTagEntries.CreateDirectionTagEntries(),
                                           format ?? "{{0}}_{0}{1}{2}{3}");
 }
Exemplo n.º 8
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));
        }
Exemplo n.º 9
0
 public NeighbourIndexTileRegistry(ITileRegistry <TRenderTile> baseRegistry,
                                   ITileTagEntrySelectionFactory <NeighbourMatchPosition> suffixMapping,
                                   string format = null)
 {
     this.format        = format ?? "{0}_{1}";
     this.baseRegistry  = baseRegistry ?? throw new ArgumentNullException();
     this.suffixMapping = suffixMapping ?? throw new ArgumentNullException();
     if (suffixMapping.Count != 9)
     {
         throw new ArgumentException();
     }
 }
Exemplo n.º 10
0
 public CardinalIndexTileRegistry(ITileRegistry <TRenderTile> baseRegistry,
                                  ITileTagEntrySelectionFactory <CardinalIndex> suffixMapping,
                                  string format = null)
 {
     this.format        = format ?? DefaultFormat;
     this.baseRegistry  = baseRegistry ?? throw new ArgumentNullException();
     this.suffixMapping = suffixMapping ?? throw new ArgumentNullException();
     if (suffixMapping.Count != 4)
     {
         throw new ArgumentException();
     }
 }
Exemplo n.º 11
0
 public RoadParityTileSelector(GridMatcher matcher,
                               GridMatcher selfMatcher,
                               IMapNavigator <GridDirection> gridNavigator,
                               ITileRegistry <TRenderTile> isolatedRegistry,
                               ITileRegistryEx <CardinalTileSelectorKey, TRenderTile> cardinalRegistry,
                               ITileRegistryEx <DiagonalTileSelectionKey, TRenderTile> diagonalRegistry,
                               string tag)
 {
     isolatedTileMatcher  = new BasicTileSelector <TRenderTile, TContext>(selfMatcher, gridNavigator, isolatedRegistry, tag);
     diagonalTileSelector =
         new DiagonalTileSelector <TRenderTile, TContext>(matcher, selfMatcher, gridNavigator, diagonalRegistry, tag);
     cardinalTileSelector =
         new CardinalTileSelector <TRenderTile, TContext>(matcher, selfMatcher, gridNavigator, cardinalRegistry, tag);
 }
Exemplo n.º 12
0
 public StrategyGameBlendLayerBuilder(GameRenderingConfig renderingConfig,
                                      IDerivedTileProducer <TTile, TTexture> tileProducer,
                                      ITextureOperations <TTexture, TColor> textureOperations,
                                      StrategyGameData gameData,
                                      IStrategyGameTileSet tileSet,
                                      ITileRegistry <TTile> tileRegistry)
 {
     this.renderingConfig   = renderingConfig;
     this.tileProducer      = tileProducer;
     this.textureOperations = textureOperations;
     this.tileSet           = tileSet;
     this.tileRegistry      = tileRegistry;
     GameData      = gameData;
     mappingHelper = new TerrainToGraphicTagMapping(gameData.Rules.TerrainTypes, tileSet);
 }
Exemplo n.º 13
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);
        }
Exemplo n.º 14
0
        public BlendingTileGenerator(ITileRegistry <TTile> tileRegistry,
                                     ITextureOperations <TTexture, TColor> textureOperations,
                                     IDerivedTileProducer <TTile, TTexture> tileProducer,
                                     RenderType renderType,
                                     IntDimension tileSize,
                                     TTile ditherMask,
                                     string prefix = "t.blend.gen.")
        {
            this.tileRegistry      = tileRegistry ?? throw new ArgumentNullException(nameof(tileRegistry));
            this.tileProducer      = tileProducer;
            this.renderType        = renderType;
            this.tileSize          = tileSize;
            this.ditherMask        = ditherMask;
            this.prefix            = prefix ?? "t.blend.gen";
            this.textureOperations = textureOperations ?? throw new ArgumentNullException(nameof(textureOperations));

            cardinalMaskRegistry = CardinalIndexTileRegistry <TTile> .CreateLong(tileRegistry);

            this.maskCache = PopulateCache();
        }
Exemplo n.º 15
0
        /// <summary>
        ///  Produces the rendering pipeline for rendering the wall and item layer.
        ///
        ///  This operation consists of three tile renderer operations per map
        ///  coordinate. Each operation must be executed as a single batch for each
        ///  map coordinate  so that later tiles can correctly paint over these
        ///  tiles if needed.
        /// </summary>
        /// <returns></returns>
        IPlotOperation CreateItemLayerPlotOperation <TRenderParameter>(IRenderCallbackFactory <TRenderParameter, TTile> rendererFactory,
                                                                       ITileRegistry <TTile> tiles,
                                                                       TRenderParameter sortingLayer)
        {
            IRenderPlotOperation <TTile, Nothing> CreateWallPlotter()
            {
                var matcher = new AggregateTileMatcher <TTile, Nothing>
                                  (CreateWallMatcher(tiles), CreateDecoMatcher(tiles));

                return(PlotOperations.FromContext(RenderingConfig)
                       .Create(matcher)
                       .WithCache()
                       .ForViewport()
                       .Build());
            }

            IRenderPlotOperation <TTile, Nothing> CreateItemPlotter()
            {
                // Selects all items stored at a give map location.
                // The item will be passed through to the renderer layer as context for post processing.
                var itemMatcher = new ItemListMatcher <TTile>(GameData, tiles);

                // Take the item context and update the rendered position of the item based on the item's location.
                // This converts the context from IItem to Nothing after adjusting the coordinates.
                var conv = new DungeonGameItemLocationResolver <TTile, Nothing>(GameData.ItemService,
                                                                                RenderingConfig.Viewport);

                return(PlotOperations.FromContext(RenderingConfig)
                       .Create(itemMatcher)
                       .ForViewport()
                       .WithConversion(conv)
                       .Build());
            }

            var renderer = new BatchedPositionedSpriteRenderer <TTile, Nothing>(rendererFactory.CreateRenderer <Nothing>(this, sortingLayer));
            var batch    = new BatchedPlotOperation <TTile, Nothing>(renderer, CreateWallPlotter(), CreateItemPlotter());

            return(batch);
        }
Exemplo n.º 16
0
        public static bool TryCreate <TTile, TTexture, TColor>(
            out BlendingTileGeneratorRegistry <TTile, TTexture, TColor> result,
            ITileRegistry <TTile> tileRegistry,
            RenderType renderType,
            ITextureOperations <TTexture, TColor> textureOperations,
            IDerivedTileProducer <TTile, TTexture> tileProducer,
            IntDimension tileSize,
            string prefix         = null,
            string ditherMaskName = null)
            where TTile : ITexturedTile <TTexture>
            where TTexture : ITexture
        {
            if (!TryFindDitherMask(out var ditherMask, tileRegistry, ditherMaskName))
            {
                result = default;
                return(false);
            }

            var generator = new BlendingTileGenerator <TTile, TTexture, TColor>(tileRegistry,
                                                                                textureOperations, tileProducer, renderType, tileSize, ditherMask, prefix);

            result = new BlendingTileGeneratorRegistry <TTile, TTexture, TColor>(generator);
            return(true);
        }
Exemplo n.º 17
0
        ITileMatcher <TTile, Nothing> CreateWallMatcher(ITileRegistry <TTile> tiles)
        {
            var gd  = GameData;
            var map = gd.Map.WallLayer;

            bool IsWallOrPassageFn(int x, int y)
            {
                var tile = map[x, y];

                return(gd.Rules.Walls.Stone.Equals(tile) || gd.Rules.Walls.Passage.Equals(tile));
            }

            var wallsAsCardinals = new CardinalTileRegistry <TTile>(tiles);

            var wallTypeSelector = new DistinctTileMatcher <IWallType, TTile, Nothing>((x, y) => map[x, y]);

            wallTypeSelector.Add(gd.Rules.Walls.Stone,
                                 new CardinalTileSelector <TTile, Nothing>(IsWallOrPassageFn,
                                                                           CreateMatcher(map, gd.Rules.Walls.Stone),
                                                                           RenderingConfig.MatcherNavigator,
                                                                           wallsAsCardinals,
                                                                           gd.Rules.Walls.Stone.Name));
            return(wallTypeSelector);
        }
Exemplo n.º 18
0
 public CardinalTileRegistry(ITileRegistry <TRenderTile> baseRegistry,
                             ITileTagEntrySelectionFactory <bool> tags,
                             string tagFormat,
                             string format) : this(baseRegistry, tags, ProduceCombinedFormatString(tagFormat, format))
 {
 }
Exemplo n.º 19
0
 public static NeighbourIndexTileRegistry <TRenderTile> CreateShort(ITileRegistry <TRenderTile> baseRegistry)
 {
     return(new NeighbourIndexTileRegistry <TRenderTile>(baseRegistry, ShortSelector()));
 }
Exemplo n.º 20
0
 public static CardinalIndexTileRegistry <TRenderTile> CreateShort(ITileRegistry <TRenderTile> baseRegistry)
 {
     return(new CardinalIndexTileRegistry <TRenderTile>(baseRegistry,
                                                        TileTagEntries.CreateShortCardinalIndexTagEntries()));
 }
Exemplo n.º 21
0
 public ItemListMatcher(DungeonGameData gd, ITileRegistry <TTile> tiles)
 {
     this.gd    = gd;
     this.tiles = tiles;
 }
Exemplo n.º 22
0
 public CellMapTileRegistry(ITileRegistry <TRenderTile> baseRegistry, string format = null)
 {
     this.baseRegistry = baseRegistry;
     this.format       = format;
 }