summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2018-10-31 14:40:20 +0100
committerMatthias Schiffer <mschiffer@universe-factory.net>2018-10-31 14:40:20 +0100
commitda3e93a942f7e01d3d26b48d403ba091667d1404 (patch)
tree81a6b64628cdb09f90fa7865734890fd8c9f494b /src
parentaf04cbe3592656cf6981232550a460f1b10e2560 (diff)
downloadrpgedit-da3e93a942f7e01d3d26b48d403ba091667d1404.tar
rpgedit-da3e93a942f7e01d3d26b48d403ba091667d1404.zip
view: more refactoring
Diffstat (limited to 'src')
-rw-r--r--src/view/MapLoader.ts31
-rw-r--r--src/view/util/image.ts29
2 files changed, 31 insertions, 29 deletions
diff --git a/src/view/MapLoader.ts b/src/view/MapLoader.ts
index a35eeec..c3504e3 100644
--- a/src/view/MapLoader.ts
+++ b/src/view/MapLoader.ts
@@ -1,4 +1,5 @@
-import { mapValues, mapValuesAsync, nextPowerOf2 } from '../util';
+import { loadImages, mkTexture } from 'util/image';
+import { mapValues, nextPowerOf2 } from '../util';
import { TileCoords } from './tile';
@@ -11,38 +12,10 @@ export interface TileMap {
tiles: Map<string, TileCoords>;
}
-function loadImage(url: string): Promise<HTMLImageElement> {
- return new Promise((resolve, reject) => {
- const img = new Image();
- img.addEventListener('load', () => { resolve(img); });
- img.addEventListener('error', () => { reject(Error('failed to load ' + url)); });
- img.src = url;
- });
-}
-
-function loadImages(urls: Map<string, string>): Promise<Map<string, HTMLImageElement>> {
- return mapValuesAsync(loadImage, urls);
-}
-
function loadTiles(tiles: Map<string, string>): Promise<Map<string, HTMLImageElement>> {
return loadImages(mapValues((t) => `resources/sprite/tile/${t}.png`, tiles));
}
-function mkTexture(gl: WebGLRenderingContext, src: HTMLCanvasElement|HTMLImageElement): WebGLTexture {
- const texture = gl.createTexture();
- if (!texture)
- throw new Error('unable to create texture');
-
- gl.bindTexture(gl.TEXTURE_2D, texture);
- gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, src);
- gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
- gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
- gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
- gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
-
- return texture;
-}
-
function mkTileMap(
gl: WebGLRenderingContext,
tiles: Map<string, HTMLImageElement>,
diff --git a/src/view/util/image.ts b/src/view/util/image.ts
new file mode 100644
index 0000000..50debde
--- /dev/null
+++ b/src/view/util/image.ts
@@ -0,0 +1,29 @@
+import { mapValuesAsync } from '../../util';
+
+export function loadImage(url: string): Promise<HTMLImageElement> {
+ return new Promise((resolve, reject) => {
+ const img = new Image();
+ img.addEventListener('load', () => { resolve(img); });
+ img.addEventListener('error', () => { reject(new Error('failed to load ' + url)); });
+ img.src = url;
+ });
+}
+
+export function loadImages(urls: Map<string, string>): Promise<Map<string, HTMLImageElement>> {
+ return mapValuesAsync(loadImage, urls);
+}
+
+export function mkTexture(gl: WebGLRenderingContext, src: HTMLCanvasElement|HTMLImageElement): WebGLTexture {
+ const texture = gl.createTexture();
+ if (!texture)
+ throw new Error('unable to create texture');
+
+ gl.bindTexture(gl.TEXTURE_2D, texture);
+ gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, src);
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
+
+ return texture;
+}