Skip to content

Commit

Permalink
a couple last second hot fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Lukas-Petervary committed Dec 2, 2024
1 parent 00ee9c6 commit 49614b0
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
1 change: 0 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
{
"imports": {
"three": "https://cdn.jsdelivr.net/npm/[email protected]/build/three.module.min.js",
"three/examples/jsm/controls/PointerLockControls": "https://cdn.jsdelivr.net/npm/[email protected]/examples/jsm/controls/PointerLockControls.js",
"cannon": "https://cdn.jsdelivr.net/npm/[email protected]/dist/cannon-es.js"
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { MenuRegistry } from "./overlay/MenuRegistry.js";
import { AudioManager } from "./client/audio/AudioManager.js";
import { Controls } from "./client/controls/Keybinds.js";
import { Stats } from "./overlay/Stats.js";
import { Lobby } from "./networking/Lobby.js";
import { Server } from "./networking/Server.js";

async function init() {
window.g_AudioManager = new AudioManager();
Expand All @@ -21,7 +21,7 @@ async function init() {
window.g_Controls = Controls;
window.g_Client = new ClientPlayer();
window.g_ConnectionManager = new ConnectionManager();
window.g_Lobby = new Lobby();
window.g_Lobby = new Server();

window.runtimeStats = new Stats();

Expand Down
6 changes: 5 additions & 1 deletion src/networking/Packets.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,11 @@ export class StartGamePacket extends GenericPacket {
};
}

static handleStartGame(packet) {
static handleStartGame(packet, senderID) {
if (senderID !== g_Lobby.leader) {
console.error('Non-leader tried to initiate game')
return;
}
g_Menu.hideAllMenus();
startGameLoop();
g_ConnectionManager.broadcastPacket(new JoinGamePacket(packet));
Expand Down
9 changes: 8 additions & 1 deletion src/networking/Lobby.js → src/networking/Server.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {JoinGamePacket, KickPlayerPacket, LobbyReadyPacket, StartGamePacket} from "./Packets.js";
import {PlayerBody} from "../client/player/PlayerBody.js";

export class Lobby {
export class Server {
constructor() {
this.leader = g_ConnectionManager.peerId;
this.lobbyReadied = false;
Expand Down Expand Up @@ -97,6 +97,13 @@ export class Lobby {

readyButton() {
this.lobbyReadied = !this.lobbyReadied;

if (this.lobbyReadied) {
document.getElementById('lobby-title').classList.add("lobby-ready");
} else {
document.getElementById('lobby-title').classList.remove("lobby-ready");
}

g_ConnectionManager.broadcastPacket(new LobbyReadyPacket(this.lobbyReadied));
}

Expand Down

0 comments on commit 49614b0

Please sign in to comment.