From 642de2a9bddf8bc56b827a54e6867d25178f357c Mon Sep 17 00:00:00 2001 From: Joel Therrien Date: Wed, 25 Dec 2024 16:47:21 -0800 Subject: [PATCH] WIP - fix multiplayer bugs --- server/src/main.rs | 2 ++ ui/src/Game.tsx | 8 ++++---- ui/src/UI.tsx | 6 +++--- ui/src/api.ts | 6 +++--- ui/src/multiplayer.tsx | 4 ++-- ui/src/utils.ts | 4 ++-- 6 files changed, 16 insertions(+), 14 deletions(-) diff --git a/server/src/main.rs b/server/src/main.rs index a44ec82..b3d6d34 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -11,6 +11,7 @@ use rocket::{tokio, State}; use serde::{Deserialize, Serialize}; use std::collections::HashMap; use std::sync::{Arc, LazyLock, Weak}; +use rocket::fs::FileServer; use tokio::select; use word_grid::api::{APIGame, ApiState, Update}; use word_grid::dictionary::{Dictionary, DictionaryImpl}; @@ -492,5 +493,6 @@ async fn room( fn rocket() -> _ { rocket::build() .manage(Mutex::new(RoomMap::new())) + .mount("/", FileServer::from("../ui/dist")) .mount("/", routes![room]) } diff --git a/ui/src/Game.tsx b/ui/src/Game.tsx index 11c1e34..85a777e 100644 --- a/ui/src/Game.tsx +++ b/ui/src/Game.tsx @@ -37,7 +37,7 @@ export function Game(props: { const historyProcessedNumber = useRef(0); let isGameOver = false; - if (api_state !== undefined) { + if (api_state != null) { isGameOver = api_state.public_information.game_state.type === "Ended"; } @@ -59,7 +59,7 @@ export function Game(props: { const [boardLetters, setBoardLetters] = useState(() => { const newLetterData = [] as HighlightableLetterData[]; for (let i = 0; i < GRID_LENGTH * GRID_LENGTH; i++) { - newLetterData.push(undefined); + newLetterData.push(null); } return newLetterData; @@ -456,14 +456,14 @@ export function Game(props: { disabled={isGameOver || !isPlayersTurn} onClick={async () => { const playedTiles = playerLetters.map((i) => { - if (i === undefined) { + if (i == null) { return null; } if (i.location === LocationType.GRID) { let result: PlayedTile = { index: i.index, - character: undefined + character: null }; if (i.is_blank) { result.character = i.text; diff --git a/ui/src/UI.tsx b/ui/src/UI.tsx index 74b699b..be74107 100644 --- a/ui/src/UI.tsx +++ b/ui/src/UI.tsx @@ -16,12 +16,12 @@ import {APIPlayer, CellType} from "./api"; export function TileSlot(props: { - tile?: React.JSX.Element | undefined, + tile?: React.JSX.Element | null, location: CoordinateData, tileDispatch: TileDispatch, arrowDispatch?: GridArrowDispatch, }): React.JSX.Element { - let isDraggable = props.tile !== undefined; + let isDraggable = props.tile != null; function onDragStart(e: React.DragEvent) { e.dataTransfer.effectAllowed = "move"; @@ -48,7 +48,7 @@ export function TileSlot(props: { } else if(props.location.location == LocationType.TRAY && props.tile != null && props.tile.props.data.text != ' ' && props.tile.props.data.text != '') { onClick = () => { props.tileDispatch({ - action: TileDispatchActionType.MOVE_TO_ARROW, end: undefined, start: props.location, + action: TileDispatchActionType.MOVE_TO_ARROW, end: null, start: props.location, }); } } diff --git a/ui/src/api.ts b/ui/src/api.ts index a9071e5..4ac8eba 100644 --- a/ui/src/api.ts +++ b/ui/src/api.ts @@ -1,5 +1,5 @@ export interface Tray { - letters: (Letter | undefined)[]; + letters: (Letter | null)[]; } export interface ScoreResult { @@ -14,7 +14,7 @@ export interface WordResult { export interface PlayedTile { index: number; - character: string | undefined; + character?: string; } export interface Difficulty { @@ -41,7 +41,7 @@ export enum CellType { Start = "Start", } -export type GameState = { type: "InProgress" } | { type: "Ended"; finisher: string | undefined; remaining_tiles: {[id: string]: Letter[]} }; +export type GameState = { type: "InProgress" } | { type: "Ended"; finisher?: string; remaining_tiles: {[id: string]: Letter[]} }; export interface APIPlayer { name: string; diff --git a/ui/src/multiplayer.tsx b/ui/src/multiplayer.tsx index 046e2b8..48935b1 100644 --- a/ui/src/multiplayer.tsx +++ b/ui/src/multiplayer.tsx @@ -118,8 +118,8 @@ export function Menu(): React.JSX.Element { -