Implement main game as a mod
This commit is contained in:
+16
-4
@@ -4,9 +4,7 @@ import { InputManager } from "./input_manager.ts";
|
||||
import { Connection, get_player_name, get_server_url } from "./network.ts";
|
||||
import { begin_drawing, clear_background, end_drawing, init_font, init_window } from "./renderer/mod.ts";
|
||||
import { is_stopped, show_fatal_error } from "./fatal.ts";
|
||||
|
||||
await import("$/common/blocks/mod.ts");
|
||||
await import("$/common/items/mod.ts");
|
||||
import { load_client_mods, set_mods_world } from "./mods.ts";
|
||||
|
||||
export class ClientLoop {
|
||||
running = false;
|
||||
@@ -94,16 +92,30 @@ init_font();
|
||||
|
||||
// the game only runs against a server, it owns the world and everything in it
|
||||
const connection = await Connection.open(get_server_url(), get_player_name());
|
||||
let mods_loaded = false;
|
||||
if (connection) {
|
||||
console.log(`Connected to ${get_server_url()}`);
|
||||
try {
|
||||
// blocks, items and textures all come from mods, so this happens before anything else
|
||||
await load_client_mods(connection.mods);
|
||||
console.log(`Mods: ${connection.mods.map((mod) => `${mod.id} ${mod.version}`).join(", ") || "none"}`);
|
||||
mods_loaded = true;
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
show_fatal_error(`Couldn't load the server's mods: ${e instanceof Error ? e.message : e}`);
|
||||
connection.socket.close();
|
||||
}
|
||||
}
|
||||
|
||||
if (connection && mods_loaded) {
|
||||
const client_world = new ClientWorld(connection);
|
||||
set_mods_world(client_world);
|
||||
client_world.add_chat("Connected to the server");
|
||||
|
||||
const loop = new ClientLoop(client_world);
|
||||
loop.start();
|
||||
|
||||
console.log("Game started");
|
||||
} else {
|
||||
} else if (!connection) {
|
||||
show_fatal_error(`Couldn't connect to the server at ${get_server_url()}`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user