diff --git a/src/client/ClientGameRunner.ts b/src/client/ClientGameRunner.ts index af25666e3..a14b967f2 100644 --- a/src/client/ClientGameRunner.ts +++ b/src/client/ClientGameRunner.ts @@ -109,7 +109,7 @@ export async function createClientGame( userSettings: UserSettings, terrainLoad: Promise | null, ): Promise { - if (typeof lobbyConfig.gameStartInfo === "undefined") { + if (lobbyConfig.gameStartInfo === undefined) { throw new Error("missing gameStartInfo"); } const config = await getConfig( @@ -204,7 +204,7 @@ export class ClientGameRunner { winner = update.winner as Team; } - if (typeof this.lobby.gameStartInfo === "undefined") { + if (this.lobby.gameStartInfo === undefined) { throw new Error("missing gameStartInfo"); } const record = createGameRecord( @@ -239,7 +239,7 @@ export class ClientGameRunner { this.renderer.initialize(); this.input.initialize(); this.worker.start((gu: GameUpdateViewData | ErrorUpdate) => { - if (typeof this.lobby.gameStartInfo === "undefined") { + if (this.lobby.gameStartInfo === undefined) { throw new Error("missing gameStartInfo"); } if ("errMsg" in gu) { @@ -296,7 +296,7 @@ export class ClientGameRunner { } } if (message.type === "desync") { - if (typeof this.lobby.gameStartInfo === "undefined") { + if (this.lobby.gameStartInfo === undefined) { throw new Error("missing gameStartInfo"); } showErrorModal( diff --git a/src/client/GoogleAdElement.ts b/src/client/GoogleAdElement.ts index 6ae2b0eaa..8d86e47fa 100644 --- a/src/client/GoogleAdElement.ts +++ b/src/client/GoogleAdElement.ts @@ -87,7 +87,7 @@ export class GoogleAdElement extends LitElement { const isElectron = () => { // Renderer process if ( - typeof window !== "undefined" && + window !== undefined && typeof window.process === "object" && // @ts-expect-error hidden window.process.type === "renderer" @@ -97,7 +97,7 @@ const isElectron = () => { // Main process if ( - typeof process !== "undefined" && + process !== undefined && typeof process.versions === "object" && !!process.versions.electron ) { diff --git a/src/client/LocalPersistantStats.ts b/src/client/LocalPersistantStats.ts index dc4694bb4..9f8c93bd6 100644 --- a/src/client/LocalPersistantStats.ts +++ b/src/client/LocalPersistantStats.ts @@ -27,7 +27,7 @@ function save(stats: LocalStatsData) { // The user can quit the game anytime so better save the lobby as soon as the // game starts. export function startGame(id: GameID, lobby: Partial) { - if (typeof localStorage === "undefined") { + if (localStorage === undefined) { return; } @@ -42,7 +42,7 @@ export function startTime() { } export function endGame(gameRecord: GameRecord) { - if (typeof localStorage === "undefined") { + if (localStorage === undefined) { return; } diff --git a/src/client/Transport.ts b/src/client/Transport.ts index 93c0bc097..e59ecdb0d 100644 --- a/src/client/Transport.ts +++ b/src/client/Transport.ts @@ -176,7 +176,7 @@ export class Transport { // If gameRecord is not null, we are replaying an archived game. // For multiplayer games, GameConfig is not known until game starts. this.isLocal = - typeof lobbyConfig.gameRecord !== "undefined" || + lobbyConfig.gameRecord !== undefined || lobbyConfig.gameStartInfo?.config.gameType === GameType.Singleplayer; this.eventBus.on(SendAllianceRequestIntentEvent, (e) => @@ -291,7 +291,7 @@ export class Transport { while (this.buffer.length > 0) { console.log("sending dropped message"); const msg = this.buffer.pop(); - if (typeof msg === "undefined") { + if (msg === undefined) { console.warn("msg is undefined"); continue; } diff --git a/src/client/UserSettingModal.ts b/src/client/UserSettingModal.ts index 45d911905..f94f0591a 100644 --- a/src/client/UserSettingModal.ts +++ b/src/client/UserSettingModal.ts @@ -281,7 +281,7 @@ export class UserSettingModal extends LitElement { easter="true" @change=${(e: CustomEvent) => { const value = e.detail?.value; - if (typeof value !== "undefined") { + if (value !== undefined) { console.log("Changed:", value); } else { console.warn("Slider event missing detail.value", e); @@ -300,7 +300,7 @@ export class UserSettingModal extends LitElement { easter="true" @change=${(e: CustomEvent) => { const value = e.detail?.value; - if (typeof value !== "undefined") { + if (value !== undefined) { console.log("Changed:", value); } else { console.warn("Slider event missing detail.value", e); diff --git a/src/client/Utils.ts b/src/client/Utils.ts index a0d3ff912..a6c90191f 100644 --- a/src/client/Utils.ts +++ b/src/client/Utils.ts @@ -45,12 +45,12 @@ export function createCanvas(): HTMLCanvasElement { */ export function generateCryptoRandomUUID(): string { // Type guard to check if randomUUID is available - if (typeof crypto !== "undefined" && "randomUUID" in crypto) { + if (crypto !== undefined && "randomUUID" in crypto) { return crypto.randomUUID(); } // Fallback using crypto.getRandomValues - if (typeof crypto !== "undefined" && "getRandomValues" in crypto) { + if (crypto !== undefined && "getRandomValues" in crypto) { return (([1e7] as any) + -1e3 + -4e3 + -8e3 + -1e11).replace( /[018]/g, (c: number): string => diff --git a/src/client/components/baseComponents/setting/SettingSlider.ts b/src/client/components/baseComponents/setting/SettingSlider.ts index 989756b57..87927d467 100644 --- a/src/client/components/baseComponents/setting/SettingSlider.ts +++ b/src/client/components/baseComponents/setting/SettingSlider.ts @@ -30,7 +30,7 @@ export class SettingSlider extends LitElement { private handleSliderChange(e: Event) { const detail = (e as CustomEvent)?.detail; - if (!detail || typeof detail.value === "undefined") { + if (!detail || detail.value === undefined) { console.warn("Invalid slider change event", e); return; } diff --git a/src/client/graphics/layers/NameLayer.ts b/src/client/graphics/layers/NameLayer.ts index 725809fa9..c73460acf 100644 --- a/src/client/graphics/layers/NameLayer.ts +++ b/src/client/graphics/layers/NameLayer.ts @@ -462,7 +462,7 @@ export class NameLayer implements Layer { }); const isMyPlayerTarget = nukesSentByOtherPlayer.find((unit) => { const detonationDst = unit.detonationDst(); - if (typeof detonationDst === "undefined") return false; + if (detonationDst === undefined) return false; const targetId = this.game.owner(detonationDst).id(); return myPlayer && targetId === myPlayer.id(); }); diff --git a/src/client/graphics/layers/RadialMenu.ts b/src/client/graphics/layers/RadialMenu.ts index c9f2efa0f..8b83e17c0 100644 --- a/src/client/graphics/layers/RadialMenu.ts +++ b/src/client/graphics/layers/RadialMenu.ts @@ -488,7 +488,7 @@ export class RadialMenu implements Layer { action: () => void, ) { const menuItem = this.menuItems.get(slot); - if (typeof menuItem === "undefined") return; + if (menuItem === undefined) return; menuItem.action = action; menuItem.disabled = false; menuItem.color = color; diff --git a/src/client/graphics/layers/StructureLayer.ts b/src/client/graphics/layers/StructureLayer.ts index 18310ceff..11c422c13 100644 --- a/src/client/graphics/layers/StructureLayer.ts +++ b/src/client/graphics/layers/StructureLayer.ts @@ -140,7 +140,7 @@ export class StructureLayer implements Layer { const unitUpdates = updates !== null ? updates[GameUpdateType.Unit] : []; for (const u of unitUpdates) { const unit = this.game.unit(u.id); - if (typeof unit === "undefined") continue; + if (unit === undefined) continue; this.handleUnitRendering(unit); } } diff --git a/src/client/graphics/layers/UnitLayer.ts b/src/client/graphics/layers/UnitLayer.ts index 36652de11..4ad9ebea4 100644 --- a/src/client/graphics/layers/UnitLayer.ts +++ b/src/client/graphics/layers/UnitLayer.ts @@ -304,7 +304,7 @@ export class UnitLayer implements Layer { // Clear current and previous positions this.clearCell(this.game.x(unit.lastTile()), this.game.y(unit.lastTile())); const oldTile = this.oldShellTile.get(unit); - if (typeof oldTile !== "undefined") { + if (oldTile !== undefined) { this.clearCell(this.game.x(oldTile), this.game.y(oldTile)); } diff --git a/src/core/Util.ts b/src/core/Util.ts index 33a2c600c..1ae6594e7 100644 --- a/src/core/Util.ts +++ b/src/core/Util.ts @@ -237,7 +237,6 @@ export function decompressGameRecord(gameRecord: GameRecord) { while (lastTurnNum < turn.turnNumber - 1) { lastTurnNum++; turns.push({ - gameID: gameRecord.id, turnNumber: lastTurnNum, intents: [], }); @@ -248,7 +247,6 @@ export function decompressGameRecord(gameRecord: GameRecord) { const turnLength = turns.length; for (let i = turnLength; i < gameRecord.num_turns; i++) { turns.push({ - gameID: gameRecord.id, turnNumber: i, intents: [], }); diff --git a/src/core/execution/PlayerExecution.ts b/src/core/execution/PlayerExecution.ts index 885ce768e..09305fd48 100644 --- a/src/core/execution/PlayerExecution.ts +++ b/src/core/execution/PlayerExecution.ts @@ -122,7 +122,7 @@ export class PlayerExecution implements Execution { clusters.sort((a, b) => b.size - a.size); const main = clusters.shift(); - if (typeof main === "undefined") throw new Error("No clusters"); + if (main === undefined) throw new Error("No clusters"); this.player.largestClusterBoundingBox = calculateBoundingBox(this.mg, main); const surroundedBy = this.surroundedBySamePlayer(main); if (surroundedBy && !this.player.isFriendly(surroundedBy)) { @@ -299,7 +299,7 @@ export class PlayerExecution implements Execution { seen.add(tile); while (queue.length > 0) { const curr = queue.shift(); - if (typeof curr === "undefined") throw new Error("curr is undefined"); + if (curr === undefined) throw new Error("curr is undefined"); cluster.add(curr); const neighbors = (this.mg as GameImpl).neighborsWithDiag(curr); diff --git a/src/core/execution/SAMLauncherExecution.ts b/src/core/execution/SAMLauncherExecution.ts index 48e9ba7a3..702244d30 100644 --- a/src/core/execution/SAMLauncherExecution.ts +++ b/src/core/execution/SAMLauncherExecution.ts @@ -23,7 +23,7 @@ export class SAMLauncherExecution implements Execution { private MIRVWarheadSearchRadius = 400; private MIRVWarheadProtectionRadius = 50; - private pseudoRandom: PseudoRandom; + private pseudoRandom: PseudoRandom | undefined; constructor( private ownerId: PlayerID, @@ -115,7 +115,7 @@ export class SAMLauncherExecution implements Execution { this.player = this.sam.owner(); } - if (this.pseudoRandom === null) { + if (this.pseudoRandom === undefined) { this.pseudoRandom = new PseudoRandom(this.sam.id()); } diff --git a/src/core/execution/SAMMissileExecution.ts b/src/core/execution/SAMMissileExecution.ts index 3f3761720..5035cf309 100644 --- a/src/core/execution/SAMMissileExecution.ts +++ b/src/core/execution/SAMMissileExecution.ts @@ -13,7 +13,7 @@ import { PseudoRandom } from "../PseudoRandom"; export class SAMMissileExecution implements Execution { private active = true; private pathFinder: AirPathFinder; - private SAMMissile: Unit; + private SAMMissile: Unit | undefined; private mg: Game; constructor( @@ -30,7 +30,7 @@ export class SAMMissileExecution implements Execution { } tick(ticks: number): void { - if (this.SAMMissile === null) { + if (this.SAMMissile === undefined) { this.SAMMissile = this._owner.buildUnit( UnitType.SAMMissile, this.spawn, diff --git a/src/core/game/GameMap.ts b/src/core/game/GameMap.ts index 5714ceb37..3a9356f3b 100644 --- a/src/core/game/GameMap.ts +++ b/src/core/game/GameMap.ts @@ -299,7 +299,7 @@ export class GameMapImpl implements GameMap { while (q.length > 0) { const curr = q.pop(); - if (typeof curr === "undefined") continue; + if (curr === undefined) continue; for (const n of this.neighbors(curr)) { if (!seen.has(n) && filter(this, n)) { seen.add(n); diff --git a/src/core/game/GameView.ts b/src/core/game/GameView.ts index a1fa1fa32..d4f25918b 100644 --- a/src/core/game/GameView.ts +++ b/src/core/game/GameView.ts @@ -119,7 +119,7 @@ export class UnitView { return this.data.ticksLeftInCooldown; } isCooldown(): boolean { - if (typeof this.data.ticksLeftInCooldown === "undefined") return false; + if (this.data.ticksLeftInCooldown === undefined) return false; return this.data.ticksLeftInCooldown > 0; } } @@ -346,7 +346,7 @@ export class GameView implements GameMap { gu.updates[GameUpdateType.Player].forEach((pu) => { this.smallIDToID.set(pu.smallID, pu.id); const player = this._players.get(pu.id); - if (typeof player !== "undefined") { + if (player !== undefined) { player.data = pu; player.nameData = gu.playerNameViewData[pu.id]; } else { @@ -362,7 +362,7 @@ export class GameView implements GameMap { } gu.updates[GameUpdateType.Unit].forEach((update) => { let unit = this._units.get(update.id); - if (typeof unit !== "undefined") { + if (unit !== undefined) { unit.update(update); } else { unit = new UnitView(this, update); @@ -408,7 +408,7 @@ export class GameView implements GameMap { player(id: PlayerID): PlayerView { const player = this._players.get(id); - if (typeof player === "undefined") { + if (player === undefined) { throw Error(`player id ${id} not found`); } return player; @@ -423,7 +423,7 @@ export class GameView implements GameMap { return new TerraNulliusImpl(); } const playerId = this.smallIDToID.get(id); - if (typeof playerId === "undefined") { + if (playerId === undefined) { throw new Error(`small id ${id} not found`); } return this.player(playerId); diff --git a/src/core/game/TerrainMapLoader.ts b/src/core/game/TerrainMapLoader.ts index a7723e9cc..2c3ee0c22 100644 --- a/src/core/game/TerrainMapLoader.ts +++ b/src/core/game/TerrainMapLoader.ts @@ -26,7 +26,7 @@ export async function loadTerrainMap( map: GameMapType, ): Promise { const cached = loadedMaps.get(map); - if (typeof cached !== "undefined") return cached; + if (cached !== undefined) return cached; const mapFiles = await terrainMapFileLoader.getMapData(map); const gameMap = await genTerrainFromBin(mapFiles.mapBin); diff --git a/src/core/game/UnitImpl.ts b/src/core/game/UnitImpl.ts index a1bac4f8a..ada40769f 100644 --- a/src/core/game/UnitImpl.ts +++ b/src/core/game/UnitImpl.ts @@ -62,7 +62,7 @@ export class UnitImpl implements Unit { const dstPort = this.dstPort(); if (this._lastTile === null) throw new Error("null _lastTile"); const ticksLeftInCooldown = - typeof this._cooldownDuration !== "undefined" + this._cooldownDuration !== undefined ? this.ticksLeftInCooldown(this._cooldownDuration) : undefined; return { diff --git a/src/core/pathfinding/PathFinding.ts b/src/core/pathfinding/PathFinding.ts index 81baf2b69..9fb0ced93 100644 --- a/src/core/pathfinding/PathFinding.ts +++ b/src/core/pathfinding/PathFinding.ts @@ -135,7 +135,7 @@ export class PathFinder { return this.nextTile(curr, dst); } else { const tile = this.path?.shift(); - if (typeof tile === "undefined") { + if (tile === undefined) { throw new Error("missing tile"); } return { type: PathFindResultType.NextTile, tile }; diff --git a/src/server/Archive.ts b/src/server/Archive.ts index 2c817e917..90d650e18 100644 --- a/src/server/Archive.ts +++ b/src/server/Archive.ts @@ -126,7 +126,7 @@ export async function readGameRecord( Key: `${gameFolder}/${gameId}`, // Fixed - needed to include gameFolder }); // Parse the response body - if (typeof response.Body === "undefined") return null; + if (response.Body === undefined) return null; const bodyContents = await response.Body.transformToString(); return JSON.parse(bodyContents) as GameRecord; } catch (error) { diff --git a/src/server/Master.ts b/src/server/Master.ts index 999125700..f2e9a94df 100644 --- a/src/server/Master.ts +++ b/src/server/Master.ts @@ -235,7 +235,7 @@ async function fetchLobbies(): Promise { lobbyInfos.forEach((l) => { if ( "msUntilStart" in l && - typeof l.msUntilStart !== "undefined" && + l.msUntilStart !== undefined && l.msUntilStart <= 250 ) { publicLobbyIDs.delete(l.gameID); @@ -244,11 +244,11 @@ async function fetchLobbies(): Promise { if ( "gameConfig" in l && - typeof l.gameConfig !== "undefined" && + l.gameConfig !== undefined && "maxPlayers" in l.gameConfig && - typeof l.gameConfig.maxPlayers !== "undefined" && + l.gameConfig.maxPlayers !== undefined && "numClients" in l && - typeof l.numClients !== "undefined" && + l.numClients !== undefined && l.gameConfig.maxPlayers <= l.numClients ) { publicLobbyIDs.delete(l.gameID); diff --git a/tests/util/Setup.ts b/tests/util/Setup.ts index 60ab51464..e8acba56a 100644 --- a/tests/util/Setup.ts +++ b/tests/util/Setup.ts @@ -39,7 +39,6 @@ export async function setup( gameType: GameType.Singleplayer, difficulty: Difficulty.Medium, disableNPCs: false, - disableNukes: false, bots: 0, infiniteGold: false, infiniteTroops: false,