Download for desktop app

This commit is contained in:
2026-10-07 16:24:41 -03:00
parent 3ec25c1471
commit 6fe5e0809e
4 changed files with 184 additions and 32 deletions
+29 -2
View File
@@ -38,6 +38,10 @@ export class TitleScreen extends GuiScreen {
? new Button("Singleplayer", WIDTH, ROW_HEIGHT, () => this.#join_singleplayer())
: undefined;
credits_button = new Button("Credits", WIDTH, ROW_HEIGHT, () => this.#open_credits());
// in the browser, the desktop app for this computer's os
download_button = has_singleplayer()
? undefined
: new Button(`Download for ${download_os().name}`, WIDTH, ROW_HEIGHT, download_desktop_app);
// open over the title screen, it gets the input while it's there
#credits: CreditsScreen | undefined;
@@ -82,6 +86,7 @@ export class TitleScreen extends GuiScreen {
this.singleplayer_button?.handle_input();
this.join_button.handle_input();
this.credits_button.handle_input();
this.download_button?.handle_input();
}
on_render(): void {
@@ -101,11 +106,12 @@ export class TitleScreen extends GuiScreen {
this.server.render();
this.join_button.render();
this.credits_button.render();
this.download_button?.render();
if (this.status) {
const width = measure_text(this.status, TEXT_SCALE);
const x = (canvas.width - width) / 2;
const y = this.credits_button.y + ROW_HEIGHT + GAP;
const y = (this.download_button ?? this.credits_button).y + ROW_HEIGHT + GAP;
draw_rect(x - 8, y - 4, width + 16, TEXT_HEIGHT * TEXT_SCALE + 8, [0, 0, 0, 0.5]);
draw_text(this.status, x, y, TEXT_SCALE, this.status_is_error ? [1, 0.45, 0.45, 1] : [1, 1, 1, 1]);
}
@@ -128,7 +134,9 @@ export class TitleScreen extends GuiScreen {
#layout() {
const x = (canvas.width - WIDTH) / 2;
const singleplayer_height = this.singleplayer_button ? ROW_HEIGHT + GAP : 0;
const total = 2 * (LABEL_GAP + ROW_HEIGHT + GAP) + singleplayer_height + 2 * ROW_HEIGHT + GAP;
const download_height = this.download_button ? ROW_HEIGHT + GAP : 0;
const total = 2 * (LABEL_GAP + ROW_HEIGHT + GAP) + singleplayer_height + 2 * ROW_HEIGHT + GAP +
download_height;
let y = (canvas.height - total) / 2 + 40;
for (const field of [this.name, this.server]) {
field.x = x;
@@ -144,6 +152,10 @@ export class TitleScreen extends GuiScreen {
this.join_button.y = y;
this.credits_button.x = x;
this.credits_button.y = y + ROW_HEIGHT + GAP;
if (this.download_button) {
this.download_button.x = x;
this.download_button.y = this.credits_button.y + ROW_HEIGHT + GAP;
}
}
#label(text: string, field: EditBox) {
@@ -232,6 +244,21 @@ function has_singleplayer() {
return new URL(location.href).searchParams.has("singleplayer");
}
// the desktop app's build for the os the browser is on, next to the page in dist/. everything that isn't windows
// gets linux's
function download_os() {
return /windows/i.test(navigator.userAgent)
? { name: "Windows", file: "dist/windows.zip" }
: { name: "Linux", file: "dist/linux.zip" };
}
function download_desktop_app() {
const link = document.createElement("a");
link.href = download_os().file;
link.download = "";
link.click();
}
// a server's mods can't be unloaded, so going back to the title screen starts the page over. without ?server=
// or ?name=, so the fields show what was used last. the desktop app keeps its ?singleplayer and ?server=, its saved
// fields don't last between launches and the page's own address isn't a server to join