Move away from browser as a main plataform

This commit is contained in:
2026-11-22 21:38:12 -03:00
parent cbd662dc2a
commit 90dd86b336
12 changed files with 166 additions and 150 deletions
+2 -20
View File
@@ -4,7 +4,7 @@
import { canvas, draw_rect, draw_text, measure_text } from "../renderer/mod.ts";
import { GuiScreen } from "../gui/gui_screen.ts";
import { credit_sections } from "../gui/credits_screen.ts";
import { Button, ListBox, TEXT_SCALE } from "../gui/widgets.ts";
import { Button, ListBox, TEXT_SCALE, wrap_text } from "../gui/widgets.ts";
const MAX_WIDTH = 1200;
const MARGIN = 32;
@@ -58,23 +58,5 @@ export class TextCreditsScreen extends GuiScreen {
// every section's heading and text, wrapped at spaces to width pixels
function credit_lines(sections: { heading: string; text: string }[], width: number): string[] {
const lines: string[] = [];
for (const { heading, text } of sections) {
lines.push(heading, "");
for (const line of text.split("\n")) {
let current = "";
for (const word of line.split(" ")) {
const next = current ? `${current} ${word}` : word;
if (current && measure_text(next, TEXT_SCALE) > width) {
lines.push(current);
current = word;
} else {
current = next;
}
}
lines.push(current);
}
lines.push("");
}
return lines;
return sections.flatMap(({ heading, text }) => [heading, "", ...wrap_text(text, width), ""]);
}
+3 -18
View File
@@ -61,12 +61,12 @@ function set_shown(now_shown: boolean) {
// what was asked of the window, by id, waiting for its answer
let next_id = 0;
const asking = new Map<number, (answer: string | boolean) => void>();
const asking = new Map<number, (answer: string) => void>();
function ask<T extends string | boolean>(question: (id: number) => ClientMessage): Promise<T> {
function ask(question: (id: number) => ClientMessage): Promise<string> {
const id = next_id++;
post(question(id));
return new Promise((resolve) => asking.set(id, resolve as (answer: string | boolean) => void));
return new Promise((resolve) => asking.set(id, resolve));
}
function native_platform(page: URL, stored: Record<string, string>, credits: string | undefined): Platform {
@@ -93,17 +93,6 @@ function native_platform(page: URL, stored: Record<string, string>, credits: str
show_fatal_error(message) {
post({ type: "fatal", message });
},
confirm_mods(address, welcome) {
const mods = welcome.mods.map((mod) => {
// it can change anything about the game, not just add to it
const access = mod.engine_access ? ", changes the engine" : "";
return `• ${mod.name} ${mod.version} (${mod.id}${access})`;
});
const text = "This server runs these mods in the game. They can do anything the game can, including " +
`reading what it saved. Only join servers you trust.\n\n${mods.join("\n")}`;
const title = `Join ${address.base.host}?`;
return ask((id) => ({ type: "ask", id, title, text, yes: "Join", no: "Cancel" }));
},
credits_screen: (on_back) => new TextCreditsScreen(on_back, credits),
read_clipboard: () => ask((id) => ({ type: "read_clipboard", id })),
write_clipboard(text) {
@@ -205,10 +194,6 @@ self.onmessage = (event: MessageEvent<WindowMessage>) => {
asking.get(message.id)?.(message.text);
asking.delete(message.id);
break;
case "answer":
asking.get(message.id)?.(message.yes);
asking.delete(message.id);
break;
case "audio_ended":
sources_ended(message.sources);
break;
+1 -4
View File
@@ -43,9 +43,8 @@ export type WindowMessage =
| { type: "focus"; focused: boolean }
// whether the window can be seen
| { type: "shown"; shown: boolean }
// answers, by the id they were asked with
// the answer to read_clipboard, by the id it was asked with
| { type: "clipboard"; id: number; text: string }
| { type: "answer"; id: number; yes: boolean }
// sources that played to their end, see web_audio.ts
| { type: "audio_ended"; sources: number[] };
@@ -55,8 +54,6 @@ export type ClientMessage =
// start the client over at page, see Platform.restart
| { type: "restart"; page: string }
| { type: "fatal"; message: string }
// a question with a yes and a no, answered with "answer"
| { type: "ask"; id: number; title: string; text: string; yes: string; no: string }
| { type: "read_clipboard"; id: number }
| { type: "write_clipboard"; text: string }
| { type: "store"; key: string; value: string }