diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2018-10-26 21:59:46 +0200 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2018-10-26 21:59:46 +0200 |
commit | bc6d79b088154e2fca56b9c18ee5ea0bf17875f8 (patch) | |
tree | 680f5b4ea26a874fa4f52f178681ef234688480f /src/view | |
parent | ebc56db63c054702ad910987aa666d7cfb52d5cc (diff) | |
download | rpgedit-bc6d79b088154e2fca56b9c18ee5ea0bf17875f8.tar rpgedit-bc6d79b088154e2fca56b9c18ee5ea0bf17875f8.zip |
model: add mutable MapState (empty for now)
Diffstat (limited to 'src/view')
-rw-r--r-- | src/view/MapLoader.ts | 8 | ||||
-rw-r--r-- | src/view/MapView.ts | 18 |
2 files changed, 13 insertions, 13 deletions
diff --git a/src/view/MapLoader.ts b/src/view/MapLoader.ts index 31e6484..290f095 100644 --- a/src/view/MapLoader.ts +++ b/src/view/MapLoader.ts @@ -1,6 +1,6 @@ import {mapValues, mapValuesAsync, nextPowerOf2} from '../util'; -import MapData from '../model/MapData'; +import MapState from '../model/state/MapState'; import MapView from './MapView'; import Renderer from './renderer/Renderer'; @@ -54,9 +54,9 @@ function mkTileTexture(gl: WebGLRenderingContext, tiles: Map<string, HTMLImageEl return [mkTexture(gl, canvas), ret]; } -export async function loadMap(r: Renderer, mapData: MapData): Promise<MapView> { - const tiles = await loadTiles(mapData.tiles); +export async function loadMap(r: Renderer, map: MapState): Promise<MapView> { + const tiles = await loadTiles(map.data.tiles); const [tileTexture, tileMap] = mkTileTexture(r.getContext(), tiles); - return new MapView(r, mapData, tileTexture, tileMap); + return new MapView(r, map, tileTexture, tileMap); } diff --git a/src/view/MapView.ts b/src/view/MapView.ts index edcbfbb..92784b7 100644 --- a/src/view/MapView.ts +++ b/src/view/MapView.ts @@ -1,6 +1,6 @@ import {nextPowerOf2} from '../util'; -import MapData from '../model/MapData'; +import MapState from '../model/state/MapState'; import Renderer from './renderer/Renderer'; export default class MapView { @@ -13,7 +13,7 @@ export default class MapView { constructor( private readonly r: Renderer, - private readonly map: MapData, + private readonly map: MapState, private readonly tileTexture: WebGLTexture, private readonly tileMap: Map<string, number>, ) { @@ -22,9 +22,9 @@ export default class MapView { const tileCount = nextPowerOf2(tileMap.size); - for (let x = 0; x < map.width; x++) - for (let y = 0; y < map.height; y++) - this.addTile(vertexData, textureData, x, y, map.layers[0][y][x], tileCount); + for (let x = 0; x < map.data.width; x++) + for (let y = 0; y < map.data.height; y++) + this.addTile(vertexData, textureData, x, y, map.data.layers[0][y][x], tileCount); const gl = r.getContext(); @@ -52,7 +52,7 @@ export default class MapView { gl.bindBuffer(gl.ARRAY_BUFFER, this.textureBuffer); gl.vertexAttribPointer(this.r.getTextureCoordLoc(), 2, gl.FLOAT, false, 0, 0); - gl.drawArrays(gl.TRIANGLES, 0, 6 * this.map.width * this.map.height); + gl.drawArrays(gl.TRIANGLES, 0, 6 * this.map.data.width * this.map.data.height); } private addTile(vertexData: number[], textureData: number[], x: number, y: number, tile: string, tileCount: number) { @@ -68,11 +68,11 @@ export default class MapView { vertexData.push(x + 1); vertexData.push(y); vertexData.push(x + 1); vertexData.push(y + 1); - textureData.push((tileID) / tileCount); textureData.push(0); + textureData.push(tileID / tileCount); textureData.push(0); textureData.push((tileID + 1) / tileCount); textureData.push(0); - textureData.push((tileID) / tileCount); textureData.push(1); + textureData.push(tileID / tileCount); textureData.push(1); - textureData.push((tileID) / tileCount); textureData.push(1); + textureData.push(tileID / tileCount); textureData.push(1); textureData.push((tileID + 1) / tileCount); textureData.push(0); textureData.push((tileID + 1) / tileCount); textureData.push(1); } |