Skip to content

Commit

Permalink
* minor renaming and prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
ConorMurphy21 committed Jan 24, 2024
1 parent 1fd6b32 commit 4222849
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 20 deletions.
2 changes: 1 addition & 1 deletion common/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"compilerOptions": {
"module": "commonJS",
"rootDir": "./",
"outDir": "dist",
"outDir": "dist"
},
"references": []
}
32 changes: 18 additions & 14 deletions server/src/state/rooms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -55,8 +55,8 @@ export function createRoom(
lang: locales.best(supportedLocales).code,
players: [
{
id,
name,
id: playerId,
name: playerName,
leader: true,
active: true
}
Expand All @@ -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');
Expand All @@ -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 });
}

Expand Down
8 changes: 3 additions & 5 deletions tsconfig.options.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -30,5 +28,5 @@
"strict": true,
"target": "esnext",
"verbatimModuleSyntax": false
},
}
}
}

0 comments on commit 4222849

Please sign in to comment.