From 6b4e5d1e588720ca45d5931fff78de160f963ee2 Mon Sep 17 00:00:00 2001 From: James Ketrenos Date: Tue, 7 Oct 2025 14:51:11 -0700 Subject: [PATCH] Contuining rewrite --- client/src/App.tsx | 8 ++- client/src/RoomView.css | 10 --- client/src/index.css | 18 ----- server/routes/games.ts | 121 +-------------------------------- server/routes/games/helpers.ts | 108 +++++++++++++++++++++++++++++ 5 files changed, 116 insertions(+), 149 deletions(-) create mode 100644 server/routes/games/helpers.ts diff --git a/client/src/App.tsx b/client/src/App.tsx index 21c21a9..8af21fd 100755 --- a/client/src/App.tsx +++ b/client/src/App.tsx @@ -90,10 +90,14 @@ const App = () => { return ( diff --git a/client/src/RoomView.css b/client/src/RoomView.css index b804702..3cade8f 100644 --- a/client/src/RoomView.css +++ b/client/src/RoomView.css @@ -1,13 +1,3 @@ -body { - font-family: 'Droid Sans', 'Arial Narrow', Arial, sans-serif; - overflow: hidden; -} - -#root { - width: 100vw; -/* height: 100vh; breaks on mobile -- not needed */ -} - .RoomView { display: flex; position: absolute; diff --git a/client/src/index.css b/client/src/index.css index 5fd920b..00b979c 100644 --- a/client/src/index.css +++ b/client/src/index.css @@ -1,21 +1,3 @@ -/*@media only screen and (max-height: 512px) { - html { - font-size: 6.75px; - } -} - -@media only screen and (min-height: 513px) and (max-height: 800px) {*/ - html { - font-size: 2vh;/*10px;*/ - } -/*} - -@media only screen and (min-height: 2000px) { - html { - font-size: 30px; - } -}*/ - html { height: 100dvh; width: 100dvw; diff --git a/server/routes/games.ts b/server/routes/games.ts index 56a8610..0f894c4 100755 --- a/server/routes/games.ts +++ b/server/routes/games.ts @@ -26,6 +26,7 @@ const router = express.Router(); // normalizeIncoming imported from './games/utils' import { initGameDB } from "./games/store"; +import { addActivity, addChatMessage, getNextPlayerSession } from "./games/helpers"; import type { GameDB } from "./games/store"; let gameDB: GameDB | undefined; @@ -96,7 +97,6 @@ const processTies = (players: Player[]): boolean => { return ties; }; - const processGameOrder = (game: any, player: any, dice: number): any => { if (player.orderRoll) { return `You have already rolled for game order and are not in a tie.`; @@ -1317,124 +1317,7 @@ const setPlayerColor = (game: any, session: any, color: string): string | undefi sendUpdateToPlayers(game, update); return undefined; }; - -const addActivity = (game: any, session: any, message: string): void => { - let date = Date.now(); - if (game.activities.length && game.activities[game.activities.length - 1].date === date) { - date++; - } - game.activities.push({ color: session ? session.color : "", message, date }); - if (game.activities.length > 30) { - game.activities.splice(0, game.activities.length - 30); - } -}; - -const addChatMessage = (game: any, session: any, message: string, isNormalChat?: boolean) => { - let now = Date.now(); - let lastTime = 0; - if (game.chat.length) { - lastTime = game.chat[game.chat.length - 1].date; - } - if (now <= lastTime) { - now = lastTime + 1; - } - - const entry: any = { - date: now, - message: message, - }; - if (isNormalChat) { - entry.normalChat = true; - } - if (session && session.name) { - entry.from = session.name; - } - if (session && session.color) { - entry.color = session.color; - } - game.chat.push(entry); - if (game.chat.length > 50) { - game.chat.splice(0, game.chat.length - 50); - } -}; - -const getColorFromName = (game: any, name: string): string => { - for (let id in game.sessions) { - if (game.sessions[id].name === name) { - return game.sessions[id].color; - } - } - return ""; -}; - -const getLastPlayerName = (game: any): string => { - let index = game.playerOrder.length - 1; - for (let id in game.sessions) { - if (game.sessions[id].color === game.playerOrder[index]) { - return game.sessions[id].name; - } - } - return ""; -}; - -const getFirstPlayerName = (game: any): string => { - let index = 0; - for (let id in game.sessions) { - if (game.sessions[id].color === game.playerOrder[index]) { - return game.sessions[id].name; - } - } - return ""; -}; - -const getNextPlayerSession = (game: any, name: string): any => { - let color; - for (let id in game.sessions) { - if (game.sessions[id].name === name) { - color = game.sessions[id].color; - break; - } - } - - let index = game.playerOrder.indexOf(color); - index = (index + 1) % game.playerOrder.length; - color = game.playerOrder[index]; - for (let id in game.sessions) { - if (game.sessions[id].color === color) { - return game.sessions[id]; - } - } - console.error(`getNextPlayerSession -- no player found!`); - console.log(game.players); -}; - -// Keep some helper symbols present for external use or tests; reference them -// as no-ops so TypeScript/linters do not mark them as unused. - -const getPrevPlayerSession = (game: any, name: string): any => { - let color; - for (let id in game.sessions) { - if (game.sessions[id].name === name) { - color = game.sessions[id].color; - break; - } - } - let index = game.playerOrder.indexOf(color); - index = (index - 1) % game.playerOrder.length; - for (let id in game.sessions) { - if (game.sessions[id].color === game.playerOrder[index]) { - return game.sessions[id]; - } - } - console.error(`getNextPlayerSession -- no player found!`); - console.log(game.players); -}; - -// Prevent 'declared but never used' warnings for public helpers that may be used externally -void getColorFromName; -void getLastPlayerName; -void getFirstPlayerName; -void getPrevPlayerSession; + const processCorner = (game: Game, color: string, cornerIndex: number, placedCorner: CornerPlacement): number => { /* If this corner is allocated and isn't assigned to the walking color, skip it */ diff --git a/server/routes/games/helpers.ts b/server/routes/games/helpers.ts new file mode 100644 index 0000000..1e3a1fa --- /dev/null +++ b/server/routes/games/helpers.ts @@ -0,0 +1,108 @@ +export const addActivity = (game: any, session: any, message: string): void => { + let date = Date.now(); + if (game.activities.length && game.activities[game.activities.length - 1].date === date) { + date++; + } + game.activities.push({ color: session ? session.color : "", message, date }); + if (game.activities.length > 30) { + game.activities.splice(0, game.activities.length - 30); + } +}; + +export const addChatMessage = (game: any, session: any, message: string, isNormalChat?: boolean) => { + let now = Date.now(); + let lastTime = 0; + if (game.chat.length) { + lastTime = game.chat[game.chat.length - 1].date; + } + if (now <= lastTime) { + now = lastTime + 1; + } + + const entry: any = { + date: now, + message: message, + }; + if (isNormalChat) { + entry.normalChat = true; + } + if (session && session.name) { + entry.from = session.name; + } + if (session && session.color) { + entry.color = session.color; + } + game.chat.push(entry); + if (game.chat.length > 50) { + game.chat.splice(0, game.chat.length - 50); + } +}; + +export const getColorFromName = (game: any, name: string): string => { + for (let id in game.sessions) { + if (game.sessions[id].name === name) { + return game.sessions[id].color; + } + } + return ""; +}; + +export const getLastPlayerName = (game: any): string => { + let index = game.playerOrder.length - 1; + for (let id in game.sessions) { + if (game.sessions[id].color === game.playerOrder[index]) { + return game.sessions[id].name; + } + } + return ""; +}; + +export const getFirstPlayerName = (game: any): string => { + let index = 0; + for (let id in game.sessions) { + if (game.sessions[id].color === game.playerOrder[index]) { + return game.sessions[id].name; + } + } + return ""; +}; + +export const getNextPlayerSession = (game: any, name: string): any => { + let color; + for (let id in game.sessions) { + if (game.sessions[id].name === name) { + color = game.sessions[id].color; + break; + } + } + + let index = game.playerOrder.indexOf(color); + index = (index + 1) % game.playerOrder.length; + color = game.playerOrder[index]; + for (let id in game.sessions) { + if (game.sessions[id].color === color) { + return game.sessions[id]; + } + } + console.error(`getNextPlayerSession -- no player found!`); + console.log(game.players); +}; + +export const getPrevPlayerSession = (game: any, name: string): any => { + let color; + for (let id in game.sessions) { + if (game.sessions[id].name === name) { + color = game.sessions[id].color; + break; + } + } + let index = game.playerOrder.indexOf(color); + index = (index - 1) % game.playerOrder.length; + for (let id in game.sessions) { + if (game.sessions[id].color === game.playerOrder[index]) { + return game.sessions[id]; + } + } + console.error(`getNextPlayerSession -- no player found!`); + console.log(game.players); +};