Start maybe working on a native app
This commit is contained in:
+11
-11
@@ -7,7 +7,7 @@ import { canvas, draw_rect, draw_text, measure_text } from "@/client/renderer/mo
|
||||
import { default_server, HandshakeError, server_address, ServerAddress } from "@/client/handshake.ts";
|
||||
import { default_player_name } from "@/client/network.ts";
|
||||
import { GuiScreen } from "./gui_screen.ts";
|
||||
import { CreditsScreen } from "./credits_screen.ts";
|
||||
import { platform } from "../platform.ts";
|
||||
import { Button, EditBox, TEXT_HEIGHT, TEXT_SCALE, TextInput } from "./widgets.ts";
|
||||
|
||||
const LAST_SERVER_KEY = "cubi:last_server";
|
||||
@@ -40,7 +40,7 @@ export class TitleScreen extends GuiScreen {
|
||||
// the desktop app for this computer's os
|
||||
download_button = 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;
|
||||
#credits: GuiScreen | undefined;
|
||||
|
||||
status = "";
|
||||
status_is_error = false;
|
||||
@@ -118,7 +118,7 @@ export class TitleScreen extends GuiScreen {
|
||||
}
|
||||
|
||||
#open_credits() {
|
||||
this.#credits ??= new CreditsScreen(() => this.#close_credits());
|
||||
this.#credits ??= platform.credits_screen(() => this.#close_credits());
|
||||
}
|
||||
|
||||
#close_credits() {
|
||||
@@ -188,18 +188,18 @@ export class TitleScreen extends GuiScreen {
|
||||
|
||||
// what was typed last time, unless the page was opened with ?server= or ?name=
|
||||
function initial_server() {
|
||||
const page = new URL(location.href);
|
||||
const page = platform.page;
|
||||
return page.searchParams.has("server") ? default_server(page) : recall(LAST_SERVER_KEY) ?? default_server(page);
|
||||
}
|
||||
|
||||
function initial_name() {
|
||||
const page = new URL(location.href);
|
||||
const page = platform.page;
|
||||
return page.searchParams.has("name") ? default_player_name() : recall(LAST_NAME_KEY) ?? "";
|
||||
}
|
||||
|
||||
function recall(key: string): string | undefined {
|
||||
try {
|
||||
return localStorage.getItem(key) ?? undefined;
|
||||
return platform.storage.getItem(key) ?? undefined;
|
||||
} catch {
|
||||
return undefined;
|
||||
}
|
||||
@@ -207,7 +207,7 @@ function recall(key: string): string | undefined {
|
||||
|
||||
function remember(key: string, value: string) {
|
||||
try {
|
||||
localStorage.setItem(key, value);
|
||||
platform.storage.setItem(key, value);
|
||||
} catch {
|
||||
// private windows and blocked storage just start empty next time
|
||||
}
|
||||
@@ -215,7 +215,7 @@ function remember(key: string, value: string) {
|
||||
|
||||
// the page is the desktop app's, see desktop/main.ts
|
||||
export function in_desktop_app() {
|
||||
return new URL(location.href).searchParams.has("singleplayer");
|
||||
return platform.page.searchParams.has("singleplayer");
|
||||
}
|
||||
|
||||
// the desktop app's build for the os the browser is on, which the server has in /dist/, see DESKTOP_DOWNLOADS. everything that isn't windows
|
||||
@@ -237,11 +237,11 @@ function download_desktop_app() {
|
||||
// or ?name=, so the fields show what was used last. the desktop app keeps its ?singleplayer and ?server=, for its
|
||||
// main menu
|
||||
export function back_to_title() {
|
||||
const page = new URL(location.href);
|
||||
const next = new URL(location.pathname, location.href);
|
||||
const page = platform.page;
|
||||
const next = new URL(page.pathname, page);
|
||||
if (in_desktop_app()) {
|
||||
next.searchParams.set("server", page.searchParams.get("server") ?? "");
|
||||
next.searchParams.set("singleplayer", "");
|
||||
}
|
||||
location.href = next.href;
|
||||
platform.restart(next);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user