diff --git a/common/tsconfig.json b/common/tsconfig.json index 5ef15f3..9b2ed3c 100644 --- a/common/tsconfig.json +++ b/common/tsconfig.json @@ -3,7 +3,7 @@ "compilerOptions": { "module": "commonJS", "rootDir": "./", - "outDir": "dist", + "outDir": "dist" }, "references": [] } diff --git a/server/src/state/rooms.ts b/server/src/state/rooms.ts index 4ce45db..8865179 100644 --- a/server/src/state/rooms.ts +++ b/server/src/state/rooms.ts @@ -35,12 +35,12 @@ function isValidRoomName(name: string): VoidResult { } export function createRoom( - id: string, - name: string, + playerId: string, + playerName: string, roomName: string, langs?: readonly string[] ): Result<{ room: Room }> { - let result = isValidName(name); + let result = isValidName(playerName); if (isErr(result)) return result; roomName = parameterize(roomName); result = isValidRoomName(roomName); @@ -55,8 +55,8 @@ export function createRoom( lang: locales.best(supportedLocales).code, players: [ { - id, - name, + id: playerId, + name: playerName, leader: true, active: true } @@ -65,12 +65,16 @@ export function createRoom( }; room.state = new GameState(room); rooms[roomName] = room; - playerRoom[id] = room; + playerRoom[playerId] = room; return Ok({ room }); } -export function joinRoom(id: string, name: string, roomName: string): Result<{ room: Room; oldId?: string }> { - const result = isValidName(name); +export function joinRoom( + playerId: string, + playerName: string, + roomName: string +): Result<{ room: Room; oldId?: string }> { + const result = isValidName(playerName); if (isErr(result)) return result; const room = rooms[parameterize(roomName)]; if (!room) return Info('noRoom'); @@ -80,26 +84,26 @@ export function joinRoom(id: string, name: string, roomName: string): Result<{ r return Info('noSpace'); } - const existingPlayer = room.players.find((player) => player.name === name); + const existingPlayer = room.players.find((player) => player.name === playerName); if (existingPlayer && existingPlayer.active) { return Info('nameTaken'); } else if (existingPlayer) { // if player disconnected, let them join back in as who they were previously const oldId = existingPlayer.id; - playerRoom[id] = room; + playerRoom[playerId] = room; existingPlayer.active = true; - existingPlayer.id = id; + existingPlayer.id = playerId; return Ok({ room, oldId }); } room.players.push({ - id, - name, + id: playerId, + name: playerName, leader: false, active: true }); - playerRoom[id] = room; + playerRoom[playerId] = room; return Ok({ room }); } diff --git a/tsconfig.options.json b/tsconfig.options.json index 94879ed..d0caefc 100644 --- a/tsconfig.options.json +++ b/tsconfig.options.json @@ -12,9 +12,7 @@ "forceConsistentCasingInFileNames": true, "incremental": true, "isolatedModules": true, - "lib": [ - "esnext", "DOM", "DOM.Iterable" - ], + "lib": ["esnext", "DOM", "DOM.Iterable"], "module": "esnext", "moduleResolution": "node", "noEmitOnError": false, @@ -30,5 +28,5 @@ "strict": true, "target": "esnext", "verbatimModuleSyntax": false - }, -} \ No newline at end of file + } +}