This commit is contained in:
Scott Anderson
2025-05-13 02:13:27 -04:00
parent 781ddb5911
commit a38d3d986f
23 changed files with 39 additions and 42 deletions
+4 -4
View File
@@ -109,7 +109,7 @@ export async function createClientGame(
userSettings: UserSettings,
terrainLoad: Promise<TerrainMapData> | null,
): Promise<ClientGameRunner> {
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(
+2 -2
View File
@@ -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
) {
+2 -2
View File
@@ -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<GameConfig>) {
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;
}
+2 -2
View File
@@ -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;
}
+2 -2
View File
@@ -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);
+2 -2
View File
@@ -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 =>
@@ -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;
}
+1 -1
View File
@@ -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();
});
+1 -1
View File
@@ -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;
+1 -1
View File
@@ -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);
}
}
+1 -1
View File
@@ -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));
}
-2
View File
@@ -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: [],
});
+2 -2
View File
@@ -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);
+2 -2
View File
@@ -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());
}
+2 -2
View File
@@ -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,
+1 -1
View File
@@ -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);
+5 -5
View File
@@ -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);
+1 -1
View File
@@ -26,7 +26,7 @@ export async function loadTerrainMap(
map: GameMapType,
): Promise<TerrainMapData> {
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);
+1 -1
View File
@@ -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 {
+1 -1
View File
@@ -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 };
+1 -1
View File
@@ -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) {
+4 -4
View File
@@ -235,7 +235,7 @@ async function fetchLobbies(): Promise<number> {
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<number> {
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);
-1
View File
@@ -39,7 +39,6 @@ export async function setup(
gameType: GameType.Singleplayer,
difficulty: Difficulty.Medium,
disableNPCs: false,
disableNukes: false,
bots: 0,
infiniteGold: false,
infiniteTroops: false,