From 3885b3944293420adb2a631aac58226ae3dae475 Mon Sep 17 00:00:00 2001 From: evanpelle Date: Tue, 15 Oct 2024 17:51:46 -0700 Subject: [PATCH] now get message if join sucessful --- src/client/ClientGame.ts | 3 +- src/client/JoinPrivateLobbyModal.ts | 98 ++++++++++++++++++++++------- src/client/Main.ts | 15 +++-- src/server/GameManager.ts | 5 ++ src/server/Server.ts | 12 +++- webpack.config.js | 2 +- 6 files changed, 106 insertions(+), 29 deletions(-) diff --git a/src/client/ClientGame.ts b/src/client/ClientGame.ts index 2495f89c2..7a4d754c8 100644 --- a/src/client/ClientGame.ts +++ b/src/client/ClientGame.ts @@ -73,7 +73,7 @@ export class ClientGame { private transport: Transport, ) { } - public join() { + public join(onstart: () => void) { const onconnect = () => { console.log('Connected to game server!'); this.transport.joinGame(this.clientIP, this.turns.length) @@ -81,6 +81,7 @@ export class ClientGame { const onmessage = (message: ServerMessage) => { if (message.type == "start") { console.log("starting game!") + onstart() for (const turn of message.turns) { if (turn.turnNumber < this.turns.length) { continue diff --git a/src/client/JoinPrivateLobbyModal.ts b/src/client/JoinPrivateLobbyModal.ts index 4d81396b4..bc7ee4ea4 100644 --- a/src/client/JoinPrivateLobbyModal.ts +++ b/src/client/JoinPrivateLobbyModal.ts @@ -5,6 +5,7 @@ import {GameMap} from '../core/game/Game'; @customElement('join-private-lobby-modal') export class JoinPrivateLobbyModal extends LitElement { @state() private isModalOpen = false; + @state() private message: string = ''; @query('#lobbyIdInput') private lobbyIdInput!: HTMLInputElement; static styles = css` @@ -74,22 +75,52 @@ export class JoinPrivateLobbyModal extends LitElement { .join-button { margin-top: 10px; } + + .message-area { + margin-top: 10px; + padding: 10px; + border-radius: 4px; + font-size: 14px; + transition: opacity 0.3s ease; + opacity: 0; + height: 0; + overflow: hidden; + } + + .message-area.show { + opacity: 1; + height: auto; + margin-bottom: 10px; + } + + .message-area.error { + background-color: #ffebee; + color: #c62828; + } + + .message-area.success { + background-color: #e8f5e9; + color: #2e7d32; + } `; render() { return html` -