summaryrefslogtreecommitdiffstats
path: root/src/view
diff options
context:
space:
mode:
Diffstat (limited to 'src/view')
-rw-r--r--src/view/map.ts21
1 files changed, 16 insertions, 5 deletions
diff --git a/src/view/map.ts b/src/view/map.ts
index f5d6eba..4e7fb20 100644
--- a/src/view/map.ts
+++ b/src/view/map.ts
@@ -2,7 +2,7 @@ import { Renderer } from './renderer/renderer';
import { SpriteCoords, SpriteView, SpriteViewBuilder } from './sprite';
import { loadImage, mkTexture } from './util/image';
-import { MapData, MapLayer } from '../model/data/map';
+import { MapData } from '../model/data/map';
import { nextPowerOf2 } from '../util';
@@ -68,9 +68,20 @@ function buildMapLayer(r: Renderer, tileset: Tileset, layer: number[][]): Sprite
return builder.build();
}
-export async function loadMap(r: Renderer, map: MapData): Promise<SpriteView[]> {
- const tiles = await loadTiles(map.tiles);
- const tileset = mkTileset(r, tiles);
+export class MapView {
+ public static async load(r: Renderer, map: MapData): Promise<MapView> {
+ const tiles = await loadTiles(map.tiles);
+ const tileset = mkTileset(r, tiles);
- return map.layers.map((layer) => buildMapLayer(r, tileset, layer.tiles));
+ const layers = map.layers.map((layer) => buildMapLayer(r, tileset, layer.tiles));
+ return new MapView(layers);
+ }
+
+ private constructor(private layers: SpriteView[]) {
+ }
+
+ public render(time: number) {
+ for (const layer of this.layers)
+ layer.render();
+ }
}