Fix download
This commit is contained in:
@@ -244,12 +244,12 @@ function has_singleplayer() {
|
|||||||
return new URL(location.href).searchParams.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
|
// 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
|
||||||
// gets linux's
|
// gets linux's
|
||||||
function download_os() {
|
function download_os() {
|
||||||
return /windows/i.test(navigator.userAgent)
|
return /windows/i.test(navigator.userAgent)
|
||||||
? { name: "Windows", file: "dist/windows.zip" }
|
? { name: "Windows", file: "/dist/windows.zip" }
|
||||||
: { name: "Linux", file: "dist/linux.zip" };
|
: { name: "Linux", file: "/dist/linux.zip" };
|
||||||
}
|
}
|
||||||
|
|
||||||
function download_desktop_app() {
|
function download_desktop_app() {
|
||||||
|
|||||||
+9
-1
@@ -1,6 +1,6 @@
|
|||||||
// the part of a game server that has permissions: files and networking. the game itself runs in a worker with none.
|
// the part of a game server that has permissions: files and networking. the game itself runs in a worker with none.
|
||||||
// server/main.ts runs it as a dedicated server, and the desktop app runs it for singleplayer
|
// server/main.ts runs it as a dedicated server, and the desktop app runs it for singleplayer
|
||||||
import { serveDir } from "@std/http/file-server";
|
import { serveDir, serveFile } from "@std/http/file-server";
|
||||||
import { join } from "@std/path";
|
import { join } from "@std/path";
|
||||||
import { GameToHost, HostToGame } from "./game/host_protocol.ts";
|
import { GameToHost, HostToGame } from "./game/host_protocol.ts";
|
||||||
import { load_bmods } from "./load_bmods.ts";
|
import { load_bmods } from "./load_bmods.ts";
|
||||||
@@ -12,12 +12,16 @@ const MAX_MESSAGE_SIZE = 4096;
|
|||||||
export const ENGINE_TEXTURES_INDEX = "assets/textures/index.json";
|
export const ENGINE_TEXTURES_INDEX = "assets/textures/index.json";
|
||||||
const SHUTDOWN_TIMEOUT_MS = 5000;
|
const SHUTDOWN_TIMEOUT_MS = 5000;
|
||||||
const DOWNLOAD_TIMEOUT_MS = 10_000;
|
const DOWNLOAD_TIMEOUT_MS = 10_000;
|
||||||
|
// the desktop app's zips that deno task desktop-all makes, for the title screen's download button
|
||||||
|
export const DESKTOP_DOWNLOADS = ["windows.zip", "linux.zip"];
|
||||||
|
|
||||||
export interface HostOptions {
|
export interface HostOptions {
|
||||||
// what deno task build made: the client and the engine's assets
|
// what deno task build made: the client and the engine's assets
|
||||||
build_dir: string;
|
build_dir: string;
|
||||||
// the .bmod files to load
|
// the .bmod files to load
|
||||||
server_mods_dir: string;
|
server_mods_dir: string;
|
||||||
|
// where DESKTOP_DOWNLOADS are, served at /dist/. without it there's nothing to download
|
||||||
|
dist_dir?: string;
|
||||||
// the world's folder: level.json, and the blocks in region/
|
// the world's folder: level.json, and the blocks in region/
|
||||||
world_dir: string;
|
world_dir: string;
|
||||||
seed?: string;
|
seed?: string;
|
||||||
@@ -170,6 +174,10 @@ export async function start_host(options: HostOptions): Promise<Host> {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
const desktop_download = url.pathname.match(/^\/dist\/([^/]+)$/)?.[1];
|
||||||
|
if (options.dist_dir && desktop_download && DESKTOP_DOWNLOADS.includes(desktop_download)) {
|
||||||
|
return serveFile(req, join(options.dist_dir, desktop_download));
|
||||||
|
}
|
||||||
return serve_static(options.build_dir, req, url);
|
return serve_static(options.build_dir, req, url);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ try {
|
|||||||
host = await start_host({
|
host = await start_host({
|
||||||
build_dir: Deno.env.get("BUILD_DIR") ?? "build",
|
build_dir: Deno.env.get("BUILD_DIR") ?? "build",
|
||||||
server_mods_dir: Deno.env.get("SERVER_MODS_DIR") ?? "server_mods",
|
server_mods_dir: Deno.env.get("SERVER_MODS_DIR") ?? "server_mods",
|
||||||
|
dist_dir: Deno.env.get("DIST_DIR") ?? "dist",
|
||||||
world_dir: Deno.env.get("WORLD_DIR") ?? "world",
|
world_dir: Deno.env.get("WORLD_DIR") ?? "world",
|
||||||
seed: Deno.env.get("SEED"),
|
seed: Deno.env.get("SEED"),
|
||||||
on_fatal(message) {
|
on_fatal(message) {
|
||||||
|
|||||||
Reference in New Issue
Block a user