summaryrefslogtreecommitdiffstats
path: root/src/view
diff options
context:
space:
mode:
Diffstat (limited to 'src/view')
-rw-r--r--src/view/map.ts16
-rw-r--r--src/view/sprite.ts (renamed from src/view/tile.ts)18
2 files changed, 17 insertions, 17 deletions
diff --git a/src/view/map.ts b/src/view/map.ts
index 954e39e..d75ea98 100644
--- a/src/view/map.ts
+++ b/src/view/map.ts
@@ -2,12 +2,12 @@ import MapData from '../model/data/MapData';
import { mapValues, nextPowerOf2 } from '../util';
import Renderer from './renderer/Renderer';
-import { TileCoords, TileView, TileViewBuilder } from './tile';
+import { SpriteCoords, SpriteView, SpriteViewBuilder } from './sprite';
import { loadImages, mkTexture } from './util/image';
interface TileMap {
texture: WebGLTexture;
- tiles: Map<string, TileCoords>;
+ tiles: Map<string, SpriteCoords>;
}
function loadTiles(tiles: Map<string, string>): Promise<Map<string, HTMLImageElement>> {
@@ -27,7 +27,7 @@ function mkTileMap(
canvas.width = canvas.height = canvasSize;
let x = 0, y = 0;
- const map: Map<string, TileCoords> = new Map();
+ const map: Map<string, SpriteCoords> = new Map();
const ctx = canvas.getContext('2d') as CanvasRenderingContext2D;
for (const [k, tile] of tiles) {
@@ -47,7 +47,7 @@ function mkTileMap(
};
}
-function addTile(builder: TileViewBuilder, tileMap: TileMap, x: number, y: number, tile: string) {
+function addSprite(builder: SpriteViewBuilder, tileMap: TileMap, x: number, y: number, tile: string) {
if (tile === ' ')
return;
@@ -55,19 +55,19 @@ function addTile(builder: TileViewBuilder, tileMap: TileMap, x: number, y: numbe
if (!tilePos)
throw new Error('invalid tile specifier in map data');
- builder.addTile([x, y, x + 1, y + 1], tilePos);
+ builder.addSprite([x, y, x + 1, y + 1], tilePos);
}
-export async function loadMap(r: Renderer, map: MapData): Promise<TileView> {
+export async function loadMap(r: Renderer, map: MapData): Promise<SpriteView> {
const tiles = await loadTiles(map.tiles);
const tileMap = mkTileMap(r.getContext(), tiles);
- const builder = new TileViewBuilder(r, tileMap.texture);
+ const builder = new SpriteViewBuilder(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]);
+ addSprite(builder, tileMap, x, y, layer[y][x]);
return builder.build();
}
diff --git a/src/view/tile.ts b/src/view/sprite.ts
index 3dd7231..18c91c7 100644
--- a/src/view/tile.ts
+++ b/src/view/sprite.ts
@@ -1,9 +1,9 @@
import Renderer from './renderer/Renderer';
-export type TileCoords = [number, number, number, number];
+export type SpriteCoords = [number, number, number, number];
-export class TileViewBuilder {
- private static pushTile(buf: number[], coords: TileCoords): void {
+export class SpriteViewBuilder {
+ private static pushSprite(buf: number[], coords: SpriteCoords): void {
const [x1, y1, x2, y2] = coords;
buf.push(x1); buf.push(y1);
@@ -20,17 +20,17 @@ export class TileViewBuilder {
constructor(private readonly r: Renderer, private readonly texture: WebGLTexture) {}
- public addTile(vertexCoords: TileCoords, texCoords: TileCoords): void {
- TileViewBuilder.pushTile(this.vertexData, vertexCoords);
- TileViewBuilder.pushTile(this.textureData, texCoords);
+ public addSprite(vertexCoords: SpriteCoords, texCoords: SpriteCoords): void {
+ SpriteViewBuilder.pushSprite(this.vertexData, vertexCoords);
+ SpriteViewBuilder.pushSprite(this.textureData, texCoords);
}
- public build(): TileView {
- return new TileView(this.r, this.texture, this.vertexData, this.textureData);
+ public build(): SpriteView {
+ return new SpriteView(this.r, this.texture, this.vertexData, this.textureData);
}
}
-export class TileView {
+export class SpriteView {
private readonly vertexCount: number;
private readonly vertexBuffer: WebGLBuffer;
private readonly textureBuffer: WebGLBuffer;