diff --git a/src/client/SinglePlayerModal.ts b/src/client/SinglePlayerModal.ts index 9173942b7..370a43bba 100644 --- a/src/client/SinglePlayerModal.ts +++ b/src/client/SinglePlayerModal.ts @@ -442,7 +442,7 @@ export class SinglePlayerModal extends LitElement { flagInput.getCurrentFlag() === "xx" ? "" : flagInput.getCurrentFlag(), - pattern: localStorage.getItem("territoryPattern") ?? null, + pattern: localStorage.getItem("territoryPattern") ?? undefined, }, ], config: { diff --git a/src/core/GameRunner.ts b/src/core/GameRunner.ts index 56d1abc1e..6635ddd77 100644 --- a/src/core/GameRunner.ts +++ b/src/core/GameRunner.ts @@ -61,7 +61,7 @@ export async function createGameRunner( new Cell(n.coordinates[0], n.coordinates[1]), n.strength, new PlayerInfo( - null, + undefined, n.flag || "", n.name, PlayerType.FakeHuman, diff --git a/src/core/Schemas.ts b/src/core/Schemas.ts index 61e0f1fc0..13c7d0edd 100644 --- a/src/core/Schemas.ts +++ b/src/core/Schemas.ts @@ -361,7 +361,7 @@ export const PlayerSchema = z.object({ clientID: ID, username: SafeString, flag: SafeString.optional(), - pattern: SafeString.nullable(), + pattern: SafeString.optional(), }); export const GameStartInfoSchema = z.object({ @@ -433,7 +433,7 @@ export const ClientJoinMessageSchema = z.object({ lastTurn: z.number(), // The last turn the client saw. username: SafeString, flag: SafeString.optional(), - pattern: SafeString.nullable(), + pattern: SafeString.optional(), }); export const ClientMessageSchema = z.union([ diff --git a/src/core/execution/BotSpawner.ts b/src/core/execution/BotSpawner.ts index 1868458c1..55337348c 100644 --- a/src/core/execution/BotSpawner.ts +++ b/src/core/execution/BotSpawner.ts @@ -48,7 +48,7 @@ export class BotSpawner { } return new SpawnExecution( new PlayerInfo( - null, + undefined, "", botName, PlayerType.Bot, diff --git a/src/core/game/Game.ts b/src/core/game/Game.ts index 8af2bf0c4..f1f4258f8 100644 --- a/src/core/game/Game.ts +++ b/src/core/game/Game.ts @@ -302,7 +302,7 @@ export class PlayerInfo { public readonly clan: string | null; constructor( - public readonly pattern: string | null, + public readonly pattern: string | undefined, public readonly flag: string | undefined, public readonly name: string, public readonly playerType: PlayerType, diff --git a/src/core/game/GameUpdates.ts b/src/core/game/GameUpdates.ts index 8cf42ddc6..32824d17d 100644 --- a/src/core/game/GameUpdates.ts +++ b/src/core/game/GameUpdates.ts @@ -93,7 +93,7 @@ export interface PlayerUpdate { type: GameUpdateType.Player; nameViewData?: NameViewData; clientID: ClientID | null; - pattern: string | null; + pattern: string | undefined; flag: string | undefined; name: string; displayName: string; diff --git a/src/core/game/GameView.ts b/src/core/game/GameView.ts index 0f7069b64..0935a0a02 100644 --- a/src/core/game/GameView.ts +++ b/src/core/game/GameView.ts @@ -172,7 +172,7 @@ export class PlayerView { return this.data.flag; } - pattern(): string | null { + pattern(): string | undefined { return this.data.pattern; } diff --git a/src/core/game/PlayerImpl.ts b/src/core/game/PlayerImpl.ts index 6dd14d6d1..3edb109de 100644 --- a/src/core/game/PlayerImpl.ts +++ b/src/core/game/PlayerImpl.ts @@ -175,7 +175,7 @@ export class PlayerImpl implements Player { return this._smallID; } - pattern(): string | null { + pattern(): string | undefined { return this.playerInfo.pattern; } diff --git a/src/server/Client.ts b/src/server/Client.ts index 17d2ab105..1e8820bc6 100644 --- a/src/server/Client.ts +++ b/src/server/Client.ts @@ -19,6 +19,6 @@ export class Client { public readonly username: string, public readonly ws: WebSocket, public readonly flag: string | undefined, - public readonly pattern: string | null, + public readonly pattern: string | undefined, ) {} } diff --git a/src/server/GameServer.ts b/src/server/GameServer.ts index 872a57e11..bfb2e8f73 100644 --- a/src/server/GameServer.ts +++ b/src/server/GameServer.ts @@ -11,7 +11,6 @@ import { GameStartInfo, GameStartInfoSchema, Intent, - Player, PlayerRecord, ServerDesyncSchema, ServerPrestartMessageSchema, @@ -291,16 +290,13 @@ export class GameServer { this.gameStartInfo = GameStartInfoSchema.parse({ gameID: this.id, config: this.gameConfig, - players: this.activeClients.map( - (c) => - ({ - playerID: c.playerID, - username: c.username, - clientID: c.clientID, - pattern: c.pattern, - flag: c.flag, - }) satisfies Player, - ), + players: this.activeClients.map((c) => ({ + playerID: c.playerID, + username: c.username, + clientID: c.clientID, + pattern: c.pattern, + flag: c.flag, + })), } satisfies GameStartInfo); this.endTurnIntervalID = setInterval( diff --git a/tests/Attack.test.ts b/tests/Attack.test.ts index 5df47b206..d3267b9cf 100644 --- a/tests/Attack.test.ts +++ b/tests/Attack.test.ts @@ -33,7 +33,7 @@ describe("Attack", () => { infiniteTroops: true, }); const attackerInfo = new PlayerInfo( - null, + undefined, "us", "attacker dude", PlayerType.Human, @@ -42,7 +42,7 @@ describe("Attack", () => { ); game.addPlayer(attackerInfo); const defenderInfo = new PlayerInfo( - null, + undefined, "us", "defender dude", PlayerType.Human, diff --git a/tests/MissileSilo.test.ts b/tests/MissileSilo.test.ts index 1d8a6e862..8c6c0482c 100644 --- a/tests/MissileSilo.test.ts +++ b/tests/MissileSilo.test.ts @@ -32,7 +32,7 @@ describe("MissileSilo", () => { beforeEach(async () => { game = await setup("Plains", { infiniteGold: true, instantBuild: true }); const attacker_info = new PlayerInfo( - null, + undefined, "fr", "attacker_id", PlayerType.Human, diff --git a/tests/PlayerInfo.test.ts b/tests/PlayerInfo.test.ts index a5f788e98..1e6527841 100644 --- a/tests/PlayerInfo.test.ts +++ b/tests/PlayerInfo.test.ts @@ -4,7 +4,7 @@ describe("PlayerInfo", () => { describe("clan", () => { test("should extract clan from name when format is [XX]Name", () => { const playerInfo = new PlayerInfo( - null, + undefined, "fr", "[CL]PlayerName", PlayerType.Human, @@ -16,7 +16,7 @@ describe("PlayerInfo", () => { test("should extract clan from name when format is [XXX]Name", () => { const playerInfo = new PlayerInfo( - null, + undefined, "fr", "[ABC]PlayerName", PlayerType.Human, @@ -28,7 +28,7 @@ describe("PlayerInfo", () => { test("should extract clan from name when format is [XXXX]Name", () => { const playerInfo = new PlayerInfo( - null, + undefined, "fr", "[ABCD]PlayerName", PlayerType.Human, @@ -40,7 +40,7 @@ describe("PlayerInfo", () => { test("should extract clan from name when format is [XXXXX]Name", () => { const playerInfo = new PlayerInfo( - null, + undefined, "fr", "[ABCDE]PlayerName", PlayerType.Human, @@ -52,7 +52,7 @@ describe("PlayerInfo", () => { test("should return null when name doesn't start with [", () => { const playerInfo = new PlayerInfo( - null, + undefined, "fr", "PlayerName", PlayerType.Human, @@ -64,7 +64,7 @@ describe("PlayerInfo", () => { test("should return null when name doesn't contain ]", () => { const playerInfo = new PlayerInfo( - null, + undefined, "fr", "[ABCPlayerName", PlayerType.Human, @@ -76,7 +76,7 @@ describe("PlayerInfo", () => { test("should return null when clan tag is not 2-5 uppercase letters", () => { const playerInfo = new PlayerInfo( - null, + undefined, "fr", "[A]PlayerName", PlayerType.Human, @@ -88,7 +88,7 @@ describe("PlayerInfo", () => { test("should return null when clan tag contains non-uppercase letters", () => { const playerInfo = new PlayerInfo( - null, + undefined, "fr", "[Abc]PlayerName", PlayerType.Human, @@ -100,7 +100,7 @@ describe("PlayerInfo", () => { test("should return null when clan tag is too long", () => { const playerInfo = new PlayerInfo( - null, + undefined, "fr", "[ABCDEF]PlayerName", PlayerType.Human, diff --git a/tests/SAM.test.ts b/tests/SAM.test.ts index 7f1671049..271895e1a 100644 --- a/tests/SAM.test.ts +++ b/tests/SAM.test.ts @@ -18,7 +18,7 @@ describe("SAM", () => { beforeEach(async () => { game = await setup("Plains", { infiniteGold: true, instantBuild: true }); const defender_info = new PlayerInfo( - null, + undefined, "us", "defender_id", PlayerType.Human, @@ -26,7 +26,7 @@ describe("SAM", () => { "defender_id", ); const attacker_info = new PlayerInfo( - null, + undefined, "fr", "attacker_id", PlayerType.Human, diff --git a/tests/TeamAssignment.test.ts b/tests/TeamAssignment.test.ts index a1c685eb5..bea1ea74f 100644 --- a/tests/TeamAssignment.test.ts +++ b/tests/TeamAssignment.test.ts @@ -7,7 +7,7 @@ describe("assignTeams", () => { const createPlayer = (id: string, clan?: string): PlayerInfo => { const name = clan ? `[${clan}]Player ${id}` : `Player ${id}`; return new PlayerInfo( - null, + undefined, "🏳️", // flag name, PlayerType.Human, diff --git a/tests/TerritoryCapture.test.ts b/tests/TerritoryCapture.test.ts index 150cc477c..cbc0c5a61 100644 --- a/tests/TerritoryCapture.test.ts +++ b/tests/TerritoryCapture.test.ts @@ -7,7 +7,7 @@ describe("Territory management", () => { const game = await setup("Plains"); game.addPlayer( new PlayerInfo( - null, + undefined, "us", "test_player", PlayerType.Human, diff --git a/tests/UnitGrid.test.ts b/tests/UnitGrid.test.ts index ca1c3eb3c..dadbae594 100644 --- a/tests/UnitGrid.test.ts +++ b/tests/UnitGrid.test.ts @@ -12,7 +12,7 @@ async function checkRange( const grid = new UnitGrid(game.map()); const player = game.addPlayer( new PlayerInfo( - null, + undefined, "us", "test_player", PlayerType.Human, @@ -42,7 +42,7 @@ async function nearbyUnits( const grid = new UnitGrid(game.map()); const player = game.addPlayer( new PlayerInfo( - null, + undefined, "us", "test_player", PlayerType.Human, @@ -123,7 +123,7 @@ describe("Unit Grid range tests", () => { const grid = new UnitGrid(game.map()); const player = game.addPlayer( new PlayerInfo( - null, + undefined, "us", "test_player", PlayerType.Human, @@ -147,7 +147,7 @@ describe("Unit Grid range tests", () => { const grid = new UnitGrid(game.map()); const player = game.addPlayer( new PlayerInfo( - null, + undefined, "us", "test_player", PlayerType.Human, diff --git a/tests/Warship.test.ts b/tests/Warship.test.ts index cf9c569b2..79260f7cf 100644 --- a/tests/Warship.test.ts +++ b/tests/Warship.test.ts @@ -21,7 +21,7 @@ describe("Warship", () => { instantBuild: true, }); const player_1_info = new PlayerInfo( - null, + undefined, "us", "boat dude", PlayerType.Human, @@ -30,7 +30,7 @@ describe("Warship", () => { ); game.addPlayer(player_1_info); const player_2_info = new PlayerInfo( - null, + undefined, "us", "boat dude", PlayerType.Human, diff --git a/tests/util/Setup.ts b/tests/util/Setup.ts index de2c73d29..d89c4eea8 100644 --- a/tests/util/Setup.ts +++ b/tests/util/Setup.ts @@ -60,5 +60,5 @@ export async function setup( } export function playerInfo(name: string, type: PlayerType): PlayerInfo { - return new PlayerInfo(null, "fr", name, type, null, name); + return new PlayerInfo(undefined, "fr", name, type, null, name); }