40 lines
1.1 KiB
TypeScript
40 lines
1.1 KiB
TypeScript
import {Vec2} from "./common.js";
|
|
import {Graphics, Texture, Spritesheet} from "./graphics.js";
|
|
|
|
export type Color = [number, number, number, number]
|
|
|
|
export const Colors = {
|
|
Red : [1, 0, 0, 1] as Color,
|
|
Green : [0, 1, 0, 1] as Color,
|
|
Blue : [0, 0, 1, 1] as Color,
|
|
Brown : [0.341, 0.337, 0.204, 1] as Color,
|
|
Gray : [0.66, 0.66, 0.66, 1] as Color,
|
|
}
|
|
|
|
export type Asset = Texture | Spritesheet;
|
|
|
|
export class Assets {
|
|
assets: Map<string, Asset> = new Map();
|
|
|
|
push(name: string, asset: Asset) {
|
|
if (this.assets.get(name) !== undefined)
|
|
throw new Error("Asset name occupied!");
|
|
|
|
this.assets.set(name, asset);
|
|
}
|
|
|
|
get(name: string): Asset {
|
|
let a = this.assets.get(name);
|
|
if (a === undefined)
|
|
throw new Error("Couldn't find asset: " + name);
|
|
|
|
return a;
|
|
}
|
|
|
|
async load(gfx: Graphics) {
|
|
assets.push("sprites", new Spritesheet(await Texture.load(gfx, "../../assets/sprites.png"), new Vec2(16, 16)));
|
|
}
|
|
}
|
|
|
|
export const assets = new Assets();
|