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