Start maybe working on a native app

This commit is contained in:
2026-11-22 17:38:28 -03:00
parent 681d3afb4d
commit a552883795
31 changed files with 1881 additions and 678 deletions
+12 -12
View File
@@ -2,6 +2,8 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
import { load_texture, Texture } from "./renderer/mod.ts";
import { decode_png } from "./png.ts";
import { platform } from "./platform.ts";
type Asset = Texture | string | Record<string, unknown>;
@@ -18,26 +20,24 @@ export class AssetManager {
return;
}
// the client's own files are next to the page, see platform.page
const url = new URL(src, platform.page);
if (src.endsWith(".png")) {
const img = new Image();
const promise = new Promise<void>((resolve, reject) => {
img.onload = () => {
this.assets[key] = load_texture(img);
resolve();
};
img.onerror = () => reject(new Error(`Failed to load image: ${src}`));
});
img.src = src;
this.loading_promises.push(promise);
const promise = async () => {
const resp = await fetch(url);
if (!resp.ok) throw new Error(`Failed to load image: ${src}`);
this.assets[key] = load_texture(decode_png(new Uint8Array(await resp.arrayBuffer())));
};
this.loading_promises.push(promise());
} else if (src.endsWith(".txt") || src.endsWith(".md") || src.endsWith(".fnt")) {
const promise = async () => {
const resp = await fetch(src);
const resp = await fetch(url);
this.assets[key] = await resp.text();
};
this.loading_promises.push(promise());
} else if (src.endsWith(".json")) {
const promise = async () => {
const resp = await fetch(src);
const resp = await fetch(url);
this.assets[key] = await resp.json();
};
this.loading_promises.push(promise());