Separate sprites into their own files
This commit is contained in:
+7
-1
@@ -1,4 +1,4 @@
|
||||
type Asset = HTMLImageElement | HTMLAudioElement | string;
|
||||
type Asset = HTMLImageElement | HTMLAudioElement | string | Record<string, unknown>;
|
||||
|
||||
export class AssetManager {
|
||||
static instance = new AssetManager();
|
||||
@@ -47,6 +47,12 @@ export class AssetManager {
|
||||
this.assets[key] = await resp.text();
|
||||
};
|
||||
this.loading_promises.push(promise());
|
||||
} else if (src.endsWith(".json")) {
|
||||
const promise = async () => {
|
||||
const resp = await fetch(src);
|
||||
this.assets[key] = await resp.json();
|
||||
};
|
||||
this.loading_promises.push(promise());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+4
-1
@@ -62,9 +62,12 @@ if (!canvas) {
|
||||
InputManager.initialize(canvas);
|
||||
|
||||
AssetManager.instance.load("bworld:assets_text", "/assets/ASSETS.md");
|
||||
|
||||
AssetManager.instance.load("bworld:textures", "/assets/sprites/textures.png");
|
||||
AssetManager.instance.load("bworld:textures_info", "/assets/sprites/textures.json");
|
||||
|
||||
AssetManager.instance.load("bworld:player", "/assets/sprites/player.png");
|
||||
AssetManager.instance.load("bworld:roguelike", "/assets/sprites/roguelike.png");
|
||||
AssetManager.instance.load("bworld:tiny_town", "/assets/sprites/tiny_town.png");
|
||||
AssetManager.instance.load("bworld:ui", "/assets/sprites/ui.png");
|
||||
|
||||
await AssetManager.instance.load_all();
|
||||
|
||||
+4
-1
@@ -32,7 +32,10 @@ export function create_player() {
|
||||
// TODO: actual player ids
|
||||
player.add(new PlayerInventory(player.id));
|
||||
player.get(PlayerInventory)!.container.add_item(new ItemStack("bworld:pickaxe", 1, 1));
|
||||
player.get(PlayerInventory)!.container.add_item(new ItemStack("bworld:bomb", 5));
|
||||
player.get(PlayerInventory)!.container.add_item(new ItemStack("bworld:sword", 1, 1));
|
||||
player.get(PlayerInventory)!.container.add_item(new ItemStack("bworld:axe", 1, 1));
|
||||
player.get(PlayerInventory)!.container.add_item(new ItemStack("bworld:hoe", 1, 1));
|
||||
player.get(PlayerInventory)!.container.add_item(new ItemStack("bworld:watering_can", 1, 1));
|
||||
player.get(PlayerInventory)!.container.add_item(new ItemStack("bworld:bomb", 64));
|
||||
player.add(new Camera(-100, -100));
|
||||
return player;
|
||||
|
||||
@@ -107,7 +107,7 @@ export function draw_nine_slice(
|
||||
export function draw_item(ctx: CanvasRenderingContext2D, item: ItemStack, x: number, y: number) {
|
||||
const sprite_region = get_sprite_region(item.type_id);
|
||||
ctx.drawImage(
|
||||
AssetManager.instance.get("bworld:tiny_town"),
|
||||
AssetManager.instance.get("bworld:textures"),
|
||||
sprite_region.x * 16,
|
||||
sprite_region.y * 16,
|
||||
16,
|
||||
|
||||
Reference in New Issue
Block a user