37 lines
1.0 KiB
JavaScript
37 lines
1.0 KiB
JavaScript
import { Texture } 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],
|
|
};
|
|
export function AssetToTileFill(name) {
|
|
let asset = assets.get(name);
|
|
return {
|
|
left: asset,
|
|
top: asset,
|
|
right: asset,
|
|
};
|
|
}
|
|
export class Assets {
|
|
assets = new Map();
|
|
loaded = false;
|
|
push(name, asset) {
|
|
if (this.assets.get(name) !== undefined)
|
|
throw new Error("Asset name occupied!");
|
|
this.assets.set(name, asset);
|
|
}
|
|
get(name) {
|
|
if (!this.loaded)
|
|
throw new Error("Tried to assess assets without loading them!");
|
|
return this.assets.get(name);
|
|
}
|
|
async load(gfx) {
|
|
assets.push("grass", await Texture.load(gfx, "../../assets/grass2.png"));
|
|
assets.push("leaves", await Texture.load(gfx, "../../assets/greenary.png"));
|
|
assets.push("log", await Texture.load(gfx, "../../assets/log.png"));
|
|
this.loaded = true;
|
|
}
|
|
}
|
|
export const assets = new Assets();
|