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
+7 -4
View File
@@ -8,7 +8,7 @@ import { InputManager } from "@/client/input_manager.ts";
import { canvas, draw_rect, draw_text, measure_text } from "@/client/renderer/mod.ts";
import { server_address } from "@/client/handshake.ts";
import { GuiScreen } from "./gui_screen.ts";
import { CreditsScreen } from "./credits_screen.ts";
import { platform } from "../platform.ts";
import type { JoinServer } from "./title_screen.ts";
import { Button, EditBox, ListBox, TEXT_HEIGHT, TEXT_SCALE, TextInput } from "./widgets.ts";
@@ -37,7 +37,7 @@ export class MainMenuScreen extends GuiScreen {
new Button("Singleplayer", WIDTH, ROW_HEIGHT, () => show(new WorldListScreen(show, join))),
multiplayer,
mods,
new Button("Credits", WIDTH, ROW_HEIGHT, () => show(new CreditsScreen(back))),
new Button("Credits", WIDTH, ROW_HEIGHT, () => show(platform.credits_screen(back))),
];
}
@@ -145,7 +145,7 @@ class WorldListScreen extends GuiScreen {
this.#status.set(`Starting ${world.name}...`);
try {
await desktop("play", { world: world.name });
await this.#join(server_address(location.host), SINGLEPLAYER_NAME, (text) => this.#status.set(text));
await this.#join(server_address(platform.page.host), SINGLEPLAYER_NAME, (text) => this.#status.set(text));
} catch (e) {
this.#status.fail(e);
this.#busy = false;
@@ -294,7 +294,10 @@ function draw_centered(text: string, y: number, scale: number) {
// asks the desktop app, see desktop/main.ts. throws with what the app said went wrong
async function desktop(path: string, body: unknown = {}): Promise<Response> {
const response = await fetch(`/desktop/${path}`, { method: "POST", body: JSON.stringify(body) });
const response = await fetch(new URL(`/desktop/${path}`, platform.page), {
method: "POST",
body: JSON.stringify(body),
});
if (!response.ok) throw new Error(await response.text());
return response;
}