Server authority
This commit is contained in:
+14
-12
@@ -3,9 +3,10 @@ import { ClientWorld } from "./client_world.ts";
|
||||
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("./blocks/mod.ts");
|
||||
await import("./items/mod.ts");
|
||||
await import("$/common/blocks/mod.ts");
|
||||
await import("$/common/items/mod.ts");
|
||||
|
||||
export class ClientLoop {
|
||||
running = false;
|
||||
@@ -39,7 +40,7 @@ export class ClientLoop {
|
||||
}
|
||||
|
||||
loop(time: number) {
|
||||
if (!this.running) {
|
||||
if (!this.running || is_stopped()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -91,17 +92,18 @@ await AssetManager.instance.load_all();
|
||||
|
||||
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());
|
||||
if (connection) {
|
||||
console.log(`Connected to ${get_server_url()}`);
|
||||
|
||||
const client_world = new ClientWorld(connection);
|
||||
client_world.add_chat("Connected to the server");
|
||||
|
||||
const loop = new ClientLoop(client_world);
|
||||
loop.start();
|
||||
|
||||
console.log("Game started");
|
||||
} else {
|
||||
console.log("Couldn't reach a server, playing single player");
|
||||
show_fatal_error(`Couldn't connect to the server at ${get_server_url()}`);
|
||||
}
|
||||
|
||||
const client_world = new ClientWorld(connection);
|
||||
client_world.add_chat(connection ? "Connected to the server" : "Playing single player");
|
||||
|
||||
const loop = new ClientLoop(client_world);
|
||||
loop.start();
|
||||
|
||||
console.log("Game started");
|
||||
|
||||
Reference in New Issue
Block a user