/// <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); }
public static void Main(string[] args) { Console.WriteLine("Starting"); var terrainTypes = new TerrainTypes(); var map = TerrainMap.CreateMap(terrainTypes); var renderType = RenderType.Grid; var navigator = new LimitedRangeNavigator <GridDirection>(GridNavigation.CreateNavigator(renderType), map.Width, map.Height); var desert = new TextTile("Desert", '.', ConsoleColor.DarkYellow); var tileRegistry = new BasicTileRegistry <TextTile>() { { "terrain.grasland", new TextTile("Gras", 'g', ConsoleColor.DarkGreen) }, { "terrain.desert", desert }, { "terrain.hills", new TextTile("Hills", 'h', ConsoleColor.Gray) }, { "terrain.plains", new TextTile("Plains", '_', ConsoleColor.Green) } }; var list = new List <ITileMatcher <TextTile, Nothing> > { new BasicTileSelector <TextTile, Nothing>( (x, y) => map[x, y].Terrain == terrainTypes.Desert, navigator, tileRegistry, "terrain.desert"), new BasicTileSelector <TextTile, Nothing>( (x, y) => map[x, y].Terrain == terrainTypes.Grasland, navigator, tileRegistry, "terrain.grasland"), new BasicTileSelector <TextTile, Nothing>( (x, y) => map[x, y].Terrain == terrainTypes.Hills, navigator, tileRegistry, "terrain.hills"), new BasicTileSelector <TextTile, Nothing>( (x, y) => map[x, y].Terrain == terrainTypes.Plains, navigator, tileRegistry, "terrain.plains") }; var bMatcher = new AggregateTileMatcher <TextTile, Nothing>(list); var viewport = new MapViewport(renderType) { SizeInTiles = new IntDimension(20, 20), CenterPoint = new ContinuousViewportCoordinates(0, 0) }; var consoleRenderer = new ViewportRenderer <TextTile, Nothing>(viewport) { RenderTarget = new ConsoleRenderer() }; var plotOp = new PlotOperation <TextTile, Nothing>(bMatcher, renderType, consoleRenderer); var t = new GridPlotter(viewport, navigator); do { t.Draw(plotOp); var consoleKeyInfo = Console.ReadKey(true); if (consoleKeyInfo.Key == ConsoleKey.Escape || consoleKeyInfo.Key == ConsoleKey.Enter) { break; } var center = viewport.CenterPoint; if (consoleKeyInfo.Key == ConsoleKey.LeftArrow) { center += new ContinuousViewportCoordinates(-1, 0); } if (consoleKeyInfo.Key == ConsoleKey.RightArrow) { center += new ContinuousViewportCoordinates(+1, 0); } if (consoleKeyInfo.Key == ConsoleKey.UpArrow) { center += new ContinuousViewportCoordinates(0, -1); } if (consoleKeyInfo.Key == ConsoleKey.DownArrow) { center += new ContinuousViewportCoordinates(0, +1); } viewport.CenterPoint = center; } while (true); }