summaryrefslogtreecommitdiffstats
path: root/src/view
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2018-10-31 15:10:40 +0100
committerMatthias Schiffer <mschiffer@universe-factory.net>2018-10-31 15:10:40 +0100
commit68ff0cb4b1f5e8d354282ef988fcb42240e34d1b (patch)
tree6032ede2a673fa7d58f9fd58817cf282a727237f /src/view
parent60f03e3c5e5d19a27eff0bb02b5995352767492b (diff)
downloadrpgedit-68ff0cb4b1f5e8d354282ef988fcb42240e34d1b.tar
rpgedit-68ff0cb4b1f5e8d354282ef988fcb42240e34d1b.zip
Get rid of MapView and MapState
Diffstat (limited to 'src/view')
-rw-r--r--src/view/MapView.ts38
-rw-r--r--src/view/map.ts (renamed from src/view/MapLoader.ts)34
2 files changed, 25 insertions, 47 deletions
diff --git a/src/view/MapView.ts b/src/view/MapView.ts
deleted file mode 100644
index a5af8f7..0000000
--- a/src/view/MapView.ts
+++ /dev/null
@@ -1,38 +0,0 @@
-import MapState from '../model/state/MapState';
-import { TileMap } from './MapLoader';
-import Renderer from './renderer/Renderer';
-import { TileView, TileViewBuilder } from './tile';
-
-export default class MapView {
- private static addTile(builder: TileViewBuilder, tileMap: TileMap, x: number, y: number, tile: string) {
- if (tile === ' ')
- return;
-
- const tilePos = tileMap.tiles.get(tile);
- if (!tilePos)
- throw new Error('invalid tile specifier in map data');
-
- builder.addTile([x, y, x + 1, y + 1], tilePos);
- }
-
- private readonly tileView: TileView;
-
- constructor(
- r: Renderer,
- map: MapState,
- tileMap: TileMap,
- ) {
- const builder = new TileViewBuilder(r, tileMap.texture);
-
- for (let x = 0; x < map.data.width; x++)
- for (let y = 0; y < map.data.height; y++)
- for (const layer of map.data.layers)
- MapView.addTile(builder, tileMap, x, y, layer[y][x]);
-
- this.tileView = builder.build();
- }
-
- public render(): void {
- this.tileView.render();
- }
-}
diff --git a/src/view/MapLoader.ts b/src/view/map.ts
index c3504e3..954e39e 100644
--- a/src/view/MapLoader.ts
+++ b/src/view/map.ts
@@ -1,13 +1,11 @@
-import { loadImages, mkTexture } from 'util/image';
+import MapData from '../model/data/MapData';
import { mapValues, nextPowerOf2 } from '../util';
-import { TileCoords } from './tile';
-
-import MapState from '../model/state/MapState';
-import MapView from './MapView';
import Renderer from './renderer/Renderer';
+import { TileCoords, TileView, TileViewBuilder } from './tile';
+import { loadImages, mkTexture } from './util/image';
-export interface TileMap {
+interface TileMap {
texture: WebGLTexture;
tiles: Map<string, TileCoords>;
}
@@ -49,9 +47,27 @@ function mkTileMap(
};
}
-export async function loadMap(r: Renderer, map: MapState): Promise<MapView> {
- const tiles = await loadTiles(map.data.tiles);
+function addTile(builder: TileViewBuilder, tileMap: TileMap, x: number, y: number, tile: string) {
+ if (tile === ' ')
+ return;
+
+ const tilePos = tileMap.tiles.get(tile);
+ if (!tilePos)
+ throw new Error('invalid tile specifier in map data');
+
+ builder.addTile([x, y, x + 1, y + 1], tilePos);
+}
+
+export async function loadMap(r: Renderer, map: MapData): Promise<TileView> {
+ const tiles = await loadTiles(map.tiles);
const tileMap = mkTileMap(r.getContext(), tiles);
- return new MapView(r, map, tileMap);
+ const builder = new TileViewBuilder(r, tileMap.texture);
+
+ for (const layer of map.layers)
+ for (let x = 0; x < map.width; x++)
+ for (let y = 0; y < map.height; y++)
+ addTile(builder, tileMap, x, y, layer[y][x]);
+
+ return builder.build();
}