From 49699eeb453b3ea8b934a6a69795e9db26d523c3 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Sat, 17 Nov 2018 13:38:09 +0100 Subject: MapView: add class for layer rendering --- src/view/map.ts | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/view/map.ts b/src/view/map.ts index 4e7fb20..c796c6f 100644 --- a/src/view/map.ts +++ b/src/view/map.ts @@ -58,14 +58,23 @@ function addSprite(builder: SpriteViewBuilder, tileset: Tileset, x: number, y: n builder.addSprite([x, y, x + 1, y + 1], tilePos); } -function buildMapLayer(r: Renderer, tileset: Tileset, layer: number[][]): SpriteView { +function buildMapLayer(r: Renderer, tileset: Tileset, layer: number[][]): MapLayerView { const builder = new SpriteViewBuilder(r, tileset.texture); for (let x = 0; x < layer[0].length; x++) for (let y = 0; y < layer.length; y++) addSprite(builder, tileset, x, y, layer[y][x]); - return builder.build(); + return new MapLayerView(builder.build()); +} + +class MapLayerView { + public constructor(private sprites: SpriteView) { + } + + public render(time: number): void { + this.sprites.render(); + } } export class MapView { @@ -77,11 +86,11 @@ export class MapView { return new MapView(layers); } - private constructor(private layers: SpriteView[]) { + private constructor(private layers: MapLayerView[]) { } - public render(time: number) { + public render(time: number): void { for (const layer of this.layers) - layer.render(); + layer.render(time); } } -- cgit v1.2.3