diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2018-11-11 20:31:22 +0100 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2018-11-11 20:31:22 +0100 |
commit | ec0e51231f95b4d847e4e94eb7146d3a0c159512 (patch) | |
tree | 8f14cdd4790b4fefe78d1f1db41cc7d9bb263520 /src/view | |
parent | e77b54f01b86f095363ee5217f7179a38b324c63 (diff) | |
download | rpgedit-ec0e51231f95b4d847e4e94eb7146d3a0c159512.tar rpgedit-ec0e51231f95b4d847e4e94eb7146d3a0c159512.zip |
Prepare support for adding extra elements to map layers
Diffstat (limited to 'src/view')
-rw-r--r-- | src/view/map.ts | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/src/view/map.ts b/src/view/map.ts index 9bdbd30..f5d6eba 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 } from '../model/data/map'; +import { MapData, MapLayer } from '../model/data/map'; import { nextPowerOf2 } from '../util'; @@ -58,16 +58,19 @@ function addSprite(builder: SpriteViewBuilder, tileset: Tileset, x: number, y: n builder.addSprite([x, y, x + 1, y + 1], tilePos); } -export async function loadMap(r: Renderer, map: MapData): Promise<SpriteView> { - const tiles = await loadTiles(map.tiles); - const tileset = mkTileset(r, tiles); - +function buildMapLayer(r: Renderer, tileset: Tileset, layer: number[][]): SpriteView { const builder = new SpriteViewBuilder(r, tileset.texture); - for (const layer of map.layers) - for (let x = 0; x < map.width; x++) - for (let y = 0; y < map.height; y++) - addSprite(builder, tileset, x, y, layer[y][x]); + 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(); } + +export async function loadMap(r: Renderer, map: MapData): Promise<SpriteView[]> { + const tiles = await loadTiles(map.tiles); + const tileset = mkTileset(r, tiles); + + return map.layers.map((layer) => buildMapLayer(r, tileset, layer.tiles)); +} |