From 07916d46bf63f7caa0a102e8b1136f25a6a13a10 Mon Sep 17 00:00:00 2001 From: falc <76709589+falcolnic@users.noreply.github.com> Date: Wed, 4 Jun 2025 18:22:17 +0200 Subject: [PATCH] Changed consolex to console logging (#1036) ## Description: Changed from consolex to console ## Please complete the following: - [x] I have added screenshots for all UI updates - [x] I process any text displayed to the user through translateText() and I've added it to the en.json file - [x] I have added relevant tests to the test directory - [x] I confirm I have thoroughly tested these changes and take full responsibility for any bugs introduced - [x] I understand that submitting code with bugs that could have been caught through manual testing blocks releases and new features for all contributors ## Please put your Discord username so you can be contacted if a bug or regression is found: @qqkedsi --- src/client/ClientGameRunner.ts | 30 +++++++------- src/client/HostLobbyModal.ts | 13 +++---- src/client/JoinPrivateLobbyModal.ts | 11 +++--- src/client/LocalPersistantStats.ts | 3 +- src/client/LocalServer.ts | 3 +- src/client/PublicLobby.ts | 5 +-- src/client/SinglePlayerModal.ts | 9 ++--- src/client/Transport.ts | 13 ------- src/client/graphics/GameRenderer.ts | 17 ++++---- src/client/graphics/fx/SpriteFx.ts | 3 +- src/client/graphics/layers/RadialMenu.ts | 5 +-- src/core/Consolex.ts | 39 ------------------- src/core/configuration/ConfigLoader.ts | 9 ++--- src/core/execution/BoatRetreatExecution.ts | 3 +- src/core/execution/BotSpawner.ts | 3 +- src/core/execution/CityExecution.ts | 3 +- src/core/execution/ConstructionExecution.ts | 3 +- src/core/execution/DefensePostExecution.ts | 3 +- src/core/execution/DonateGoldExecution.ts | 3 +- src/core/execution/DonateTroopExecution.ts | 3 +- src/core/execution/EmojiExecution.ts | 5 +-- src/core/execution/FakeHumanExecution.ts | 5 +-- src/core/execution/MIRVExecution.ts | 3 +- src/core/execution/MissileSiloExecution.ts | 3 +- src/core/execution/NukeExecution.ts | 5 +-- src/core/execution/PlayerExecution.ts | 3 +- src/core/execution/PortExecution.ts | 3 +- src/core/execution/QuickChatExecution.ts | 7 ++-- src/core/execution/SAMLauncherExecution.ts | 3 +- .../execution/SetTargetTroopRatioExecution.ts | 3 +- src/core/execution/TradeShipExecution.ts | 5 +-- src/core/execution/TransportShipExecution.ts | 7 ++-- src/core/execution/WarshipExecution.ts | 5 +-- .../alliance/AllianceRequestExecution.ts | 5 +-- .../alliance/AllianceRequestReplyExecution.ts | 5 +-- .../alliance/BreakAllianceExecution.ts | 3 +- src/core/game/GameImpl.ts | 7 ++-- src/core/game/PlayerImpl.ts | 3 +- src/core/game/TerrainMapLoader.ts | 5 +-- src/core/pathfinding/PathFinding.ts | 5 +-- src/core/pathfinding/SerialAStar.ts | 3 +- 41 files changed, 91 insertions(+), 183 deletions(-) delete mode 100644 src/core/Consolex.ts diff --git a/src/client/ClientGameRunner.ts b/src/client/ClientGameRunner.ts index 67d899f22..65ea5be59 100644 --- a/src/client/ClientGameRunner.ts +++ b/src/client/ClientGameRunner.ts @@ -1,5 +1,4 @@ import { translateText } from "../client/Utils"; -import { consolex, initRemoteSender } from "../core/Consolex"; import { EventBus } from "../core/EventBus"; import { ClientID, @@ -58,10 +57,9 @@ export function joinLobby( onJoin: () => void, ): () => void { const eventBus = new EventBus(); - initRemoteSender(eventBus); - consolex.log( - `joinging lobby: gameID: ${lobbyConfig.gameID}, clientID: ${lobbyConfig.clientID}`, + console.log( + `joining lobby: gameID: ${lobbyConfig.gameID}, clientID: ${lobbyConfig.clientID}`, ); const userSettings: UserSettings = new UserSettings(); @@ -70,21 +68,21 @@ export function joinLobby( const transport = new Transport(lobbyConfig, eventBus); const onconnect = () => { - consolex.log(`Joined game lobby ${lobbyConfig.gameID}`); + console.log(`Joined game lobby ${lobbyConfig.gameID}`); transport.joinGame(0); }; let terrainLoad: Promise | null = null; const onmessage = (message: ServerMessage) => { if (message.type === "prestart") { - consolex.log(`lobby: game prestarting: ${JSON.stringify(message)}`); + console.log(`lobby: game prestarting: ${JSON.stringify(message)}`); terrainLoad = loadTerrainMap(message.gameMap); onPrestart(); } if (message.type === "start") { // Trigger prestart for singleplayer games onPrestart(); - consolex.log(`lobby: game started: ${JSON.stringify(message, null, 2)}`); + console.log(`lobby: game started: ${JSON.stringify(message, null, 2)}`); onJoin(); // For multiplayer games, GameStartInfo is not known until game starts. lobbyConfig.gameStartInfo = message.gameStartInfo; @@ -99,7 +97,7 @@ export function joinLobby( }; transport.connect(onconnect, onmessage); return () => { - consolex.log("leaving game"); + console.log("leaving game"); transport.leaveGame(); }; } @@ -139,12 +137,12 @@ export async function createClientGame( lobbyConfig.gameStartInfo.gameID, ); - consolex.log("going to init path finder"); - consolex.log("inited path finder"); + console.log("going to init path finder"); + console.log("inited path finder"); const canvas = createCanvas(); const gameRenderer = createRenderer(canvas, gameView, eventBus); - consolex.log( + console.log( `creating private game got difficulty: ${lobbyConfig.gameStartInfo.config.difficulty}`, ); @@ -221,7 +219,7 @@ export class ClientGameRunner { } public start() { - consolex.log("starting client game"); + console.log("starting client game"); this.isActive = true; this.lastMessageTime = Date.now(); @@ -270,14 +268,14 @@ export class ClientGameRunner { requestAnimationFrame(keepWorkerAlive); const onconnect = () => { - consolex.log("Connected to game server!"); + console.log("Connected to game server!"); this.transport.joinGame(this.turnsSeen); }; const onmessage = (message: ServerMessage) => { this.lastMessageTime = Date.now(); if (message.type === "start") { this.hasJoined = true; - consolex.log("starting game!"); + console.log("starting game!"); for (const turn of message.turns) { if (turn.turnNumber < this.turnsSeen) { continue; @@ -312,7 +310,7 @@ export class ClientGameRunner { return; } if (this.turnsSeen !== message.turn.turnNumber) { - consolex.error( + console.error( `got wrong turn have turns ${this.turnsSeen}, received turn ${message.turn.turnNumber}`, ); } else { @@ -345,7 +343,7 @@ export class ClientGameRunner { if (!this.gameView.isValidCoord(cell.x, cell.y)) { return; } - consolex.log(`clicked cell ${cell}`); + console.log(`clicked cell ${cell}`); const tile = this.gameView.ref(cell.x, cell.y); if ( this.gameView.isLand(tile) && diff --git a/src/client/HostLobbyModal.ts b/src/client/HostLobbyModal.ts index 6e12a4ad3..41447146f 100644 --- a/src/client/HostLobbyModal.ts +++ b/src/client/HostLobbyModal.ts @@ -3,7 +3,6 @@ import { customElement, query, state } from "lit/decorators.js"; import randomMap from "../../resources/images/RandomMap.webp"; import { translateText } from "../client/Utils"; import { getServerConfigFromClient } from "../core/configuration/ConfigLoader"; -import { consolex } from "../core/Consolex"; import { Difficulty, Duos, @@ -457,7 +456,7 @@ export class HostLobbyModal extends LitElement { private async handleDisableNPCsChange(e: Event) { this.disableNPCs = Boolean((e.target as HTMLInputElement).checked); - consolex.log(`updating disable npcs to ${this.disableNPCs}`); + console.log(`updating disable npcs to ${this.disableNPCs}`); this.putGameConfig(); } @@ -498,7 +497,7 @@ export class HostLobbyModal extends LitElement { } private toggleUnit(unit: UnitType, checked: boolean): void { - consolex.log(`Toggling unit type: ${unit} to ${checked}`); + console.log(`Toggling unit type: ${unit} to ${checked}`); this.disabledUnits = checked ? [...this.disabledUnits, unit] : this.disabledUnits.filter((u) => u !== unit); @@ -518,7 +517,7 @@ export class HostLobbyModal extends LitElement { } await this.putGameConfig(); - consolex.log( + console.log( `Starting private game with map: ${GameMapType[this.selectedMap]} ${this.useRandomMap ? " (Randomly selected)" : ""}`, ); this.close(); @@ -546,7 +545,7 @@ export class HostLobbyModal extends LitElement { this.copySuccess = false; }, 2000); } catch (err) { - consolex.error(`Failed to copy text: ${err}`); + console.error(`Failed to copy text: ${err}`); } } @@ -586,11 +585,11 @@ async function createLobby(): Promise { } const data = await response.json(); - consolex.log("Success:", data); + console.log("Success:", data); return data as GameInfo; } catch (error) { - consolex.error("Error creating lobby:", error); + console.error("Error creating lobby:", error); throw error; // Re-throw the error so the caller can handle it } } diff --git a/src/client/JoinPrivateLobbyModal.ts b/src/client/JoinPrivateLobbyModal.ts index 01424e26a..3640bb220 100644 --- a/src/client/JoinPrivateLobbyModal.ts +++ b/src/client/JoinPrivateLobbyModal.ts @@ -1,7 +1,6 @@ import { LitElement, html } from "lit"; import { customElement, query, state } from "lit/decorators.js"; import { translateText } from "../client/Utils"; -import { consolex } from "../core/Consolex"; import { GameInfo, GameRecord } from "../core/Schemas"; import { generateID } from "../core/Util"; import { getServerConfigFromClient } from "../core/configuration/ConfigLoader"; @@ -145,13 +144,13 @@ export class JoinPrivateLobbyModal extends LitElement { this.lobbyIdInput.value = lobbyId; } catch (err) { - consolex.error("Failed to read clipboard contents: ", err); + console.error("Failed to read clipboard contents: ", err); } } private async joinLobby(): Promise { const lobbyId = this.lobbyIdInput.value; - consolex.log(`Joining lobby with ID: ${lobbyId}`); + console.log(`Joining lobby with ID: ${lobbyId}`); this.message = `${translateText("private_lobby.checking")}`; try { @@ -165,7 +164,7 @@ export class JoinPrivateLobbyModal extends LitElement { this.message = `${translateText("private_lobby.not_found")}`; } catch (error) { - consolex.error("Error checking lobby existence:", error); + console.error("Error checking lobby existence:", error); this.message = `${translateText("private_lobby.error")}`; } } @@ -218,7 +217,7 @@ export class JoinPrivateLobbyModal extends LitElement { archiveData.success === false && archiveData.error === "Version mismatch" ) { - consolex.warn( + console.warn( `Git commit hash mismatch for game ${lobbyId}`, archiveData.details, ); @@ -266,7 +265,7 @@ export class JoinPrivateLobbyModal extends LitElement { this.players = data.clients?.map((p) => p.username) ?? []; }) .catch((error) => { - consolex.error("Error polling players:", error); + console.error("Error polling players:", error); }); } } diff --git a/src/client/LocalPersistantStats.ts b/src/client/LocalPersistantStats.ts index 616e40db7..c6dd1df5a 100644 --- a/src/client/LocalPersistantStats.ts +++ b/src/client/LocalPersistantStats.ts @@ -1,4 +1,3 @@ -import { consolex } from "../core/Consolex"; import { GameConfig, GameID, GameRecord } from "../core/Schemas"; import { replacer } from "../core/Util"; @@ -51,7 +50,7 @@ export function endGame(gameRecord: GameRecord) { const gameStat = stats[gameRecord.info.gameID]; if (!gameStat) { - consolex.log("LocalPersistantStats: game not found"); + console.log("LocalPersistantStats: game not found"); return; } diff --git a/src/client/LocalServer.ts b/src/client/LocalServer.ts index c3982510f..e3bc08dcf 100644 --- a/src/client/LocalServer.ts +++ b/src/client/LocalServer.ts @@ -1,4 +1,3 @@ -import { consolex } from "../core/Consolex"; import { AllPlayersStats, ClientMessage, @@ -172,7 +171,7 @@ export class LocalServer { } public endGame(saveFullGame: boolean = false) { - consolex.log("local server ending game"); + console.log("local server ending game"); clearInterval(this.turnCheckInterval); if (this.isReplay) { return; diff --git a/src/client/PublicLobby.ts b/src/client/PublicLobby.ts index ee3069504..2292d9d8d 100644 --- a/src/client/PublicLobby.ts +++ b/src/client/PublicLobby.ts @@ -1,7 +1,6 @@ import { LitElement, html } from "lit"; import { customElement, state } from "lit/decorators.js"; import { translateText } from "../client/Utils"; -import { consolex } from "../core/Consolex"; import { GameMode } from "../core/game/Game"; import { GameID, GameInfo } from "../core/Schemas"; import { generateID } from "../core/Util"; @@ -51,7 +50,7 @@ export class PublicLobby extends LitElement { } }); } catch (error) { - consolex.error("Error fetching lobbies:", error); + console.error("Error fetching lobbies:", error); } } @@ -63,7 +62,7 @@ export class PublicLobby extends LitElement { const data = await response.json(); return data.lobbies; } catch (error) { - consolex.error("Error fetching lobbies:", error); + console.error("Error fetching lobbies:", error); throw error; } } diff --git a/src/client/SinglePlayerModal.ts b/src/client/SinglePlayerModal.ts index 509f564f6..f633c1e31 100644 --- a/src/client/SinglePlayerModal.ts +++ b/src/client/SinglePlayerModal.ts @@ -2,7 +2,6 @@ import { LitElement, html } from "lit"; import { customElement, query, state } from "lit/decorators.js"; import randomMap from "../../resources/images/RandomMap.webp"; import { translateText } from "../client/Utils"; -import { consolex } from "../core/Consolex"; import { Difficulty, Duos, @@ -367,7 +366,7 @@ export class SinglePlayerModal extends LitElement { } private toggleUnit(unit: UnitType, checked: boolean): void { - consolex.log(`Toggling unit type: ${unit} to ${checked}`); + console.log(`Toggling unit type: ${unit} to ${checked}`); this.disabledUnits = checked ? [...this.disabledUnits, unit] : this.disabledUnits.filter((u) => u !== unit); @@ -379,7 +378,7 @@ export class SinglePlayerModal extends LitElement { this.selectedMap = this.getRandomMap(); } - consolex.log( + console.log( `Starting single player game with map: ${GameMapType[this.selectedMap]}${this.useRandomMap ? " (Randomly selected)" : ""}`, ); const clientID = generateID(); @@ -389,12 +388,12 @@ export class SinglePlayerModal extends LitElement { "username-input", ) as UsernameInput; if (!usernameInput) { - consolex.warn("Username input element not found"); + console.warn("Username input element not found"); } const flagInput = document.querySelector("flag-input") as FlagInput; if (!flagInput) { - consolex.warn("Flag input element not found"); + console.warn("Flag input element not found"); } this.dispatchEvent( new CustomEvent("join-lobby", { diff --git a/src/client/Transport.ts b/src/client/Transport.ts index ab06dc938..f208a55a1 100644 --- a/src/client/Transport.ts +++ b/src/client/Transport.ts @@ -1,4 +1,3 @@ -import { SendLogEvent } from "../core/Consolex"; import { EventBus, GameEvent } from "../core/EventBus"; import { AllPlayers, @@ -16,7 +15,6 @@ import { ClientHashMessage, ClientIntentMessage, ClientJoinMessage, - ClientLogMessage, ClientPingMessage, ClientSendWinnerMessage, Intent, @@ -211,7 +209,6 @@ export class Transport { ); this.eventBus.on(BuildUnitIntentEvent, (e) => this.onBuildUnitIntent(e)); - this.eventBus.on(SendLogEvent, (e) => this.onSendLogEvent(e)); this.eventBus.on(PauseGameEvent, (e) => this.onPauseGameEvent(e)); this.eventBus.on(SendWinnerEvent, (e) => this.onSendWinnerEvent(e)); this.eventBus.on(SendHashEvent, (e) => this.onSendHashEvent(e)); @@ -336,16 +333,6 @@ export class Transport { } } - private onSendLogEvent(event: SendLogEvent) { - this.sendMsg( - JSON.stringify({ - type: "log", - log: event.log, - severity: event.severity, - } satisfies ClientLogMessage), - ); - } - joinGame(numTurns: number) { this.sendMsg( JSON.stringify({ diff --git a/src/client/graphics/GameRenderer.ts b/src/client/graphics/GameRenderer.ts index 149706c8f..cf4ea6f7b 100644 --- a/src/client/graphics/GameRenderer.ts +++ b/src/client/graphics/GameRenderer.ts @@ -1,4 +1,3 @@ -import { consolex } from "../../core/Consolex"; import { EventBus } from "../../core/EventBus"; import { GameView } from "../../core/game/GameView"; import { GameStartingModal } from "../GameStartingModal"; @@ -51,7 +50,7 @@ export function createRenderer( // TODO maybe append this to dcoument instead of querying for them? const emojiTable = document.querySelector("emoji-table") as EmojiTable; if (!emojiTable || !(emojiTable instanceof EmojiTable)) { - consolex.error("EmojiTable element not found in the DOM"); + console.error("EmojiTable element not found in the DOM"); } emojiTable.eventBus = eventBus; emojiTable.transformHandler = transformHandler; @@ -60,28 +59,28 @@ export function createRenderer( const buildMenu = document.querySelector("build-menu") as BuildMenu; if (!buildMenu || !(buildMenu instanceof BuildMenu)) { - consolex.error("BuildMenu element not found in the DOM"); + console.error("BuildMenu element not found in the DOM"); } buildMenu.game = game; buildMenu.eventBus = eventBus; const leaderboard = document.querySelector("leader-board") as Leaderboard; if (!emojiTable || !(leaderboard instanceof Leaderboard)) { - consolex.error("EmojiTable element not found in the DOM"); + console.error("EmojiTable element not found in the DOM"); } leaderboard.eventBus = eventBus; leaderboard.game = game; const teamStats = document.querySelector("team-stats") as TeamStats; if (!emojiTable || !(teamStats instanceof TeamStats)) { - consolex.error("EmojiTable element not found in the DOM"); + console.error("EmojiTable element not found in the DOM"); } teamStats.eventBus = eventBus; teamStats.game = game; const controlPanel = document.querySelector("control-panel") as ControlPanel; if (!(controlPanel instanceof ControlPanel)) { - consolex.error("ControlPanel element not found in the DOM"); + console.error("ControlPanel element not found in the DOM"); } controlPanel.eventBus = eventBus; controlPanel.uiState = uiState; @@ -91,14 +90,14 @@ export function createRenderer( "events-display", ) as EventsDisplay; if (!(eventsDisplay instanceof EventsDisplay)) { - consolex.error("events display not found"); + console.error("events display not found"); } eventsDisplay.eventBus = eventBus; eventsDisplay.game = game; const chatDisplay = document.querySelector("chat-display") as ChatDisplay; if (!(chatDisplay instanceof ChatDisplay)) { - consolex.error("chat display not found"); + console.error("chat display not found"); } chatDisplay.eventBus = eventBus; chatDisplay.game = game; @@ -107,7 +106,7 @@ export function createRenderer( "player-info-overlay", ) as PlayerInfoOverlay; if (!(playerInfo instanceof PlayerInfoOverlay)) { - consolex.error("player info overlay not found"); + console.error("player info overlay not found"); } playerInfo.eventBus = eventBus; playerInfo.transform = transformHandler; diff --git a/src/client/graphics/fx/SpriteFx.ts b/src/client/graphics/fx/SpriteFx.ts index 54b4f18df..9293dd663 100644 --- a/src/client/graphics/fx/SpriteFx.ts +++ b/src/client/graphics/fx/SpriteFx.ts @@ -1,5 +1,4 @@ import { Theme } from "../../../core/configuration/Config"; -import { consolex } from "../../../core/Consolex"; import { PlayerView } from "../../../core/game/GameView"; import { AnimatedSprite } from "../AnimatedSprite"; import { AnimatedSpriteLoader } from "../AnimatedSpriteLoader"; @@ -62,7 +61,7 @@ export class SpriteFx implements Fx { theme, ); if (!this.animatedSprite) { - consolex.error("Could not load animated sprite", fxType); + console.error("Could not load animated sprite", fxType); } else { this.duration = duration ?? this.animatedSprite.lifeTime() ?? 1000; } diff --git a/src/client/graphics/layers/RadialMenu.ts b/src/client/graphics/layers/RadialMenu.ts index 4df72f104..74cbb7b27 100644 --- a/src/client/graphics/layers/RadialMenu.ts +++ b/src/client/graphics/layers/RadialMenu.ts @@ -6,7 +6,6 @@ import disabledIcon from "../../../../resources/images/DisabledIcon.svg"; import infoIcon from "../../../../resources/images/InfoIcon.svg"; import swordIcon from "../../../../resources/images/SwordIconWhite.svg"; import traitorIcon from "../../../../resources/images/TraitorIconWhite.svg"; -import { consolex } from "../../../core/Consolex"; import { EventBus } from "../../../core/EventBus"; import { Cell, @@ -341,7 +340,7 @@ export class RadialMenu implements Layer { const myPlayer = this.g.myPlayer(); if (myPlayer === null) { - consolex.warn("my player not found"); + console.warn("my player not found"); return; } if (myPlayer && !myPlayer.isAlive() && !this.g.inSpawnPhase()) { @@ -453,7 +452,7 @@ export class RadialMenu implements Layer { if (!this.isCenterButtonEnabled) { return; } - consolex.log("Center button clicked"); + console.log("Center button clicked"); if (this.clickedCell === null) return; const clicked = this.g.ref(this.clickedCell.x, this.clickedCell.y); if (this.g.inSpawnPhase()) { diff --git a/src/core/Consolex.ts b/src/core/Consolex.ts deleted file mode 100644 index 7817d3b08..000000000 --- a/src/core/Consolex.ts +++ /dev/null @@ -1,39 +0,0 @@ -import { EventBus, GameEvent } from "./EventBus"; -import { LogSeverity } from "./Schemas"; - -export const consolex = { - log: console.log, - warn: console.warn, - error: console.error, -}; - -let inited = false; - -// Only call this in client/browser! -export function initRemoteSender(eventBus: EventBus) { - if (inited) { - return; - } - inited = true; - - consolex.log = (...args: any[]): void => { - console.log(...args); - // eventBus.emit(new SendLogEvent(LogSeverity.Info, args.join(' '))) - }; - - consolex.warn = (...args: any[]): void => { - console.warn(...args); - // eventBus.emit(new SendLogEvent(LogSeverity.Warn, args.join(' '))) - }; - - consolex.error = (...args: any[]): void => { - console.error(...args); - // eventBus.emit(new SendLogEvent(LogSeverity.Error, args.join(' '))) - }; -} -export class SendLogEvent implements GameEvent { - constructor( - public readonly severity: LogSeverity, - public readonly log: string, - ) {} -} diff --git a/src/core/configuration/ConfigLoader.ts b/src/core/configuration/ConfigLoader.ts index 94a723c13..184902694 100644 --- a/src/core/configuration/ConfigLoader.ts +++ b/src/core/configuration/ConfigLoader.ts @@ -1,4 +1,3 @@ -import { consolex } from "../Consolex"; import { UserSettings } from "../game/UserSettings"; import { GameConfig } from "../Schemas"; import { Config, GameEnv, ServerConfig } from "./Config"; @@ -20,7 +19,7 @@ export async function getConfig( return new DevConfig(sc, gameConfig, userSettings, isReplay); case GameEnv.Preprod: case GameEnv.Prod: - consolex.log("using prod config"); + console.log("using prod config"); return new DefaultConfig(sc, gameConfig, userSettings, isReplay); default: throw Error(`unsupported server configuration: ${process.env.GAME_ENV}`); @@ -51,13 +50,13 @@ export function getServerConfigFromServer(): ServerConfig { export function getServerConfig(gameEnv: string) { switch (gameEnv) { case "dev": - consolex.log("using dev server config"); + console.log("using dev server config"); return new DevServerConfig(); case "staging": - consolex.log("using preprod server config"); + console.log("using preprod server config"); return preprodConfig; case "prod": - consolex.log("using prod server config"); + console.log("using prod server config"); return prodConfig; default: throw Error(`unsupported server configuration: ${gameEnv}`); diff --git a/src/core/execution/BoatRetreatExecution.ts b/src/core/execution/BoatRetreatExecution.ts index bcef746a4..c5c597639 100644 --- a/src/core/execution/BoatRetreatExecution.ts +++ b/src/core/execution/BoatRetreatExecution.ts @@ -1,4 +1,3 @@ -import { consolex } from "../Consolex"; import { Execution, Game, Player, PlayerID, UnitType } from "../game/Game"; export class BoatRetreatExecution implements Execution { @@ -33,7 +32,7 @@ export class BoatRetreatExecution implements Execution { ); if (!unit) { - consolex.warn(`Didn't find outgoing boat with id ${this.unitID}`); + console.warn(`Didn't find outgoing boat with id ${this.unitID}`); this.active = false; return; } diff --git a/src/core/execution/BotSpawner.ts b/src/core/execution/BotSpawner.ts index 521729a67..644fbc803 100644 --- a/src/core/execution/BotSpawner.ts +++ b/src/core/execution/BotSpawner.ts @@ -1,4 +1,3 @@ -import { consolex } from "../Consolex"; import { Game, PlayerInfo, PlayerType } from "../game/Game"; import { TileRef } from "../game/GameMap"; import { PseudoRandom } from "../PseudoRandom"; @@ -22,7 +21,7 @@ export class BotSpawner { let tries = 0; while (this.bots.length < numBots) { if (tries > 10000) { - consolex.log("too many retries while spawning bots, giving up"); + console.log("too many retries while spawning bots, giving up"); return this.bots; } const botName = this.randomBotName(); diff --git a/src/core/execution/CityExecution.ts b/src/core/execution/CityExecution.ts index c6046f2de..d488df6e3 100644 --- a/src/core/execution/CityExecution.ts +++ b/src/core/execution/CityExecution.ts @@ -1,4 +1,3 @@ -import { consolex } from "../Consolex"; import { Execution, Game, @@ -34,7 +33,7 @@ export class CityExecution implements Execution { if (this.city === null) { const spawnTile = this.player.canBuild(UnitType.City, this.tile); if (spawnTile === false) { - consolex.warn("cannot build city"); + console.warn("cannot build city"); this.active = false; return; } diff --git a/src/core/execution/ConstructionExecution.ts b/src/core/execution/ConstructionExecution.ts index 073f342d9..5c350ff00 100644 --- a/src/core/execution/ConstructionExecution.ts +++ b/src/core/execution/ConstructionExecution.ts @@ -1,4 +1,3 @@ -import { consolex } from "../Consolex"; import { Execution, Game, @@ -56,7 +55,7 @@ export class ConstructionExecution implements Execution { } const spawnTile = this.player.canBuild(this.constructionType, this.tile); if (spawnTile === false) { - consolex.warn(`cannot build ${this.constructionType}`); + console.warn(`cannot build ${this.constructionType}`); this.active = false; return; } diff --git a/src/core/execution/DefensePostExecution.ts b/src/core/execution/DefensePostExecution.ts index c0d6e4711..2ec384cb8 100644 --- a/src/core/execution/DefensePostExecution.ts +++ b/src/core/execution/DefensePostExecution.ts @@ -1,4 +1,3 @@ -import { consolex } from "../Consolex"; import { Execution, Game, @@ -63,7 +62,7 @@ export class DefensePostExecution implements Execution { if (this.post === null) { const spawnTile = this.player.canBuild(UnitType.DefensePost, this.tile); if (spawnTile === false) { - consolex.warn("cannot build Defense Post"); + console.warn("cannot build Defense Post"); this.active = false; return; } diff --git a/src/core/execution/DonateGoldExecution.ts b/src/core/execution/DonateGoldExecution.ts index 20837d66e..672c5861d 100644 --- a/src/core/execution/DonateGoldExecution.ts +++ b/src/core/execution/DonateGoldExecution.ts @@ -1,4 +1,3 @@ -import { consolex } from "../Consolex"; import { Execution, Game, Gold, Player, PlayerID } from "../game/Game"; export class DonateGoldExecution implements Execution { @@ -40,7 +39,7 @@ export class DonateGoldExecution implements Execution { ) { this.recipient.updateRelation(this.sender, 50); } else { - consolex.warn( + console.warn( `cannot send gold from ${this.sender.name()} to ${this.recipient.name()}`, ); } diff --git a/src/core/execution/DonateTroopExecution.ts b/src/core/execution/DonateTroopExecution.ts index 3e5ac43da..dd05689da 100644 --- a/src/core/execution/DonateTroopExecution.ts +++ b/src/core/execution/DonateTroopExecution.ts @@ -1,4 +1,3 @@ -import { consolex } from "../Consolex"; import { Execution, Game, Player, PlayerID } from "../game/Game"; export class DonateTroopsExecution implements Execution { @@ -43,7 +42,7 @@ export class DonateTroopsExecution implements Execution { ) { this.recipient.updateRelation(this.sender, 50); } else { - consolex.warn( + console.warn( `cannot send troops from ${this.sender} to ${this.recipient}`, ); } diff --git a/src/core/execution/EmojiExecution.ts b/src/core/execution/EmojiExecution.ts index a544411e4..068f11d89 100644 --- a/src/core/execution/EmojiExecution.ts +++ b/src/core/execution/EmojiExecution.ts @@ -1,4 +1,3 @@ -import { consolex } from "../Consolex"; import { AllPlayers, Execution, @@ -43,7 +42,7 @@ export class EmojiExecution implements Execution { tick(ticks: number): void { const emojiString = flattenedEmojiTable[this.emoji]; if (emojiString === undefined) { - consolex.warn( + console.warn( `cannot send emoji ${this.emoji} from ${this.requestor} to ${this.recipient}`, ); } else if (this.requestor.canSendEmoji(this.recipient)) { @@ -56,7 +55,7 @@ export class EmojiExecution implements Execution { this.recipient.updateRelation(this.requestor, -100); } } else { - consolex.warn( + console.warn( `cannot send emoji from ${this.requestor} to ${this.recipient}`, ); } diff --git a/src/core/execution/FakeHumanExecution.ts b/src/core/execution/FakeHumanExecution.ts index de34803a0..9e2508499 100644 --- a/src/core/execution/FakeHumanExecution.ts +++ b/src/core/execution/FakeHumanExecution.ts @@ -1,4 +1,3 @@ -import { consolex } from "../Consolex"; import { Cell, Difficulty, @@ -117,7 +116,7 @@ export class FakeHumanExecution implements Execution { if (this.mg.inSpawnPhase()) { const rl = this.randomLand(); if (rl === null) { - consolex.warn(`cannot spawn ${this.nation.playerInfo.name}`); + console.warn(`cannot spawn ${this.nation.playerInfo.name}`); return; } this.mg.addExecution(new SpawnExecution(this.nation.playerInfo, rl)); @@ -488,7 +487,7 @@ export class FakeHumanExecution implements Execution { } const canBuild = this.player.canBuild(UnitType.Warship, targetTile); if (canBuild === false) { - consolex.warn("cannot spawn destroyer"); + console.warn("cannot spawn destroyer"); return false; } this.mg.addExecution( diff --git a/src/core/execution/MIRVExecution.ts b/src/core/execution/MIRVExecution.ts index 41e617f8a..9b0e8e511 100644 --- a/src/core/execution/MIRVExecution.ts +++ b/src/core/execution/MIRVExecution.ts @@ -1,4 +1,3 @@ -import { consolex } from "../Consolex"; import { Execution, Game, @@ -64,7 +63,7 @@ export class MirvExecution implements Execution { if (this.nuke === null) { const spawn = this.player.canBuild(UnitType.MIRV, this.dst); if (spawn === false) { - consolex.warn(`cannot build MIRV`); + console.warn(`cannot build MIRV`); this.active = false; return; } diff --git a/src/core/execution/MissileSiloExecution.ts b/src/core/execution/MissileSiloExecution.ts index d9b30f9dd..b0c404405 100644 --- a/src/core/execution/MissileSiloExecution.ts +++ b/src/core/execution/MissileSiloExecution.ts @@ -1,4 +1,3 @@ -import { consolex } from "../Consolex"; import { Execution, Game, @@ -38,7 +37,7 @@ export class MissileSiloExecution implements Execution { if (this.silo === null) { const spawn = this.player.canBuild(UnitType.MissileSilo, this.tile); if (spawn === false) { - consolex.warn( + console.warn( `player ${this.player} cannot build missile silo at ${this.tile}`, ); this.active = false; diff --git a/src/core/execution/NukeExecution.ts b/src/core/execution/NukeExecution.ts index facdbb649..83955ded0 100644 --- a/src/core/execution/NukeExecution.ts +++ b/src/core/execution/NukeExecution.ts @@ -1,4 +1,3 @@ -import { consolex } from "../Consolex"; import { Execution, Game, @@ -109,7 +108,7 @@ export class NukeExecution implements Execution { if (this.nuke === null) { const spawn = this.src ?? this.player.canBuild(this.type, this.dst); if (spawn === false) { - consolex.warn(`cannot build Nuke`); + console.warn(`cannot build Nuke`); this.active = false; return; } @@ -161,7 +160,7 @@ export class NukeExecution implements Execution { // make the nuke unactive if it was intercepted if (!this.nuke.isActive()) { - consolex.log(`Nuke destroyed before reaching target`); + console.log(`Nuke destroyed before reaching target`); this.active = false; return; } diff --git a/src/core/execution/PlayerExecution.ts b/src/core/execution/PlayerExecution.ts index 4bf039072..276be4890 100644 --- a/src/core/execution/PlayerExecution.ts +++ b/src/core/execution/PlayerExecution.ts @@ -1,6 +1,5 @@ import { renderNumber } from "../../client/Utils"; import { Config } from "../configuration/Config"; -import { consolex } from "../Consolex"; import { Execution, Game, @@ -116,7 +115,7 @@ export class PlayerExecution implements Execution { this.removeClusters(); const end = performance.now(); if (end - start > 1000) { - consolex.log(`player ${this.player.name()}, took ${end - start}ms`); + console.log(`player ${this.player.name()}, took ${end - start}ms`); } } } diff --git a/src/core/execution/PortExecution.ts b/src/core/execution/PortExecution.ts index 74b6554f6..d234a8de8 100644 --- a/src/core/execution/PortExecution.ts +++ b/src/core/execution/PortExecution.ts @@ -1,4 +1,3 @@ -import { consolex } from "../Consolex"; import { Execution, Game, @@ -43,7 +42,7 @@ export class PortExecution implements Execution { const player = this.mg.player(this._owner); const spawn = player.canBuild(UnitType.Port, tile); if (spawn === false) { - consolex.warn(`player ${player} cannot build port at ${this.tile}`); + console.warn(`player ${player} cannot build port at ${this.tile}`); this.active = false; return; } diff --git a/src/core/execution/QuickChatExecution.ts b/src/core/execution/QuickChatExecution.ts index 002171a83..f9d4230bf 100644 --- a/src/core/execution/QuickChatExecution.ts +++ b/src/core/execution/QuickChatExecution.ts @@ -1,4 +1,3 @@ -import { consolex } from "../Consolex"; import { Execution, Game, Player, PlayerID } from "../game/Game"; export class QuickChatExecution implements Execution { @@ -18,12 +17,12 @@ export class QuickChatExecution implements Execution { init(mg: Game, ticks: number): void { this.mg = mg; if (!mg.hasPlayer(this.senderID)) { - consolex.warn(`QuickChatExecution: sender ${this.senderID} not found`); + console.warn(`QuickChatExecution: sender ${this.senderID} not found`); this.active = false; return; } if (!mg.hasPlayer(this.recipientID)) { - consolex.warn( + console.warn( `QuickChatExecution: recipient ${this.recipientID} not found`, ); this.active = false; @@ -55,7 +54,7 @@ export class QuickChatExecution implements Execution { this.recipient.name(), ); - consolex.log( + console.log( `[QuickChat] ${this.sender.name} → ${this.recipient.name}: ${message}`, ); diff --git a/src/core/execution/SAMLauncherExecution.ts b/src/core/execution/SAMLauncherExecution.ts index e2547218c..09b5a1d8a 100644 --- a/src/core/execution/SAMLauncherExecution.ts +++ b/src/core/execution/SAMLauncherExecution.ts @@ -1,4 +1,3 @@ -import { consolex } from "../Consolex"; import { Execution, Game, @@ -102,7 +101,7 @@ export class SAMLauncherExecution implements Execution { } const spawnTile = this.player.canBuild(UnitType.SAMLauncher, this.tile); if (spawnTile === false) { - consolex.warn("cannot build SAM Launcher"); + console.warn("cannot build SAM Launcher"); this.active = false; return; } diff --git a/src/core/execution/SetTargetTroopRatioExecution.ts b/src/core/execution/SetTargetTroopRatioExecution.ts index 2d143e245..9ad8e1380 100644 --- a/src/core/execution/SetTargetTroopRatioExecution.ts +++ b/src/core/execution/SetTargetTroopRatioExecution.ts @@ -1,4 +1,3 @@ -import { consolex } from "../Consolex"; import { Execution, Game, Player, PlayerID } from "../game/Game"; export class SetTargetTroopRatioExecution implements Execution { @@ -22,7 +21,7 @@ export class SetTargetTroopRatioExecution implements Execution { tick(ticks: number): void { if (this.targetTroopsRatio < 0 || this.targetTroopsRatio > 1) { - consolex.warn( + console.warn( `target troop ratio of ${this.targetTroopsRatio} for player ${this.player} invalid`, ); } else { diff --git a/src/core/execution/TradeShipExecution.ts b/src/core/execution/TradeShipExecution.ts index 3094b9384..5e1fb10e9 100644 --- a/src/core/execution/TradeShipExecution.ts +++ b/src/core/execution/TradeShipExecution.ts @@ -1,5 +1,4 @@ import { renderNumber } from "../../client/Utils"; -import { consolex } from "../Consolex"; import { Execution, Game, @@ -41,7 +40,7 @@ export class TradeShipExecution implements Execution { this.srcPort.tile(), ); if (spawn === false) { - consolex.warn(`cannot build trade ship`); + console.warn(`cannot build trade ship`); this.active = false; return; } @@ -115,7 +114,7 @@ export class TradeShipExecution implements Execution { this.tradeShip.move(result.tile); break; case PathFindResultType.PathNotFound: - consolex.warn("captured trade ship cannot find route"); + console.warn("captured trade ship cannot find route"); if (this.tradeShip.isActive()) { this.tradeShip.delete(false); } diff --git a/src/core/execution/TransportShipExecution.ts b/src/core/execution/TransportShipExecution.ts index 8851d8fdf..e7607cd05 100644 --- a/src/core/execution/TransportShipExecution.ts +++ b/src/core/execution/TransportShipExecution.ts @@ -1,4 +1,3 @@ -import { consolex } from "../Consolex"; import { Execution, Game, @@ -100,7 +99,7 @@ export class TransportShipExecution implements Execution { this.dst = targetTransportTile(this.mg, this.ref); if (this.dst === null) { - consolex.warn( + console.warn( `${this.attacker} cannot send ship to ${this.target}, cannot find attack tile`, ); this.active = false; @@ -112,7 +111,7 @@ export class TransportShipExecution implements Execution { this.dst, ); if (closestTileSrc === false) { - consolex.warn(`can't build transport ship`); + console.warn(`can't build transport ship`); this.active = false; return; } @@ -215,7 +214,7 @@ export class TransportShipExecution implements Execution { break; case PathFindResultType.PathNotFound: // TODO: add to poisoned port list - consolex.warn(`path not found to dst`); + console.warn(`path not found to dst`); this.attacker.addTroops(this.troops); this.boat.delete(false); this.active = false; diff --git a/src/core/execution/WarshipExecution.ts b/src/core/execution/WarshipExecution.ts index 43233bd91..969eec2e0 100644 --- a/src/core/execution/WarshipExecution.ts +++ b/src/core/execution/WarshipExecution.ts @@ -1,4 +1,3 @@ -import { consolex } from "../Consolex"; import { Execution, Game, @@ -192,7 +191,7 @@ export class WarshipExecution implements Execution { this.warship.touch(); break; case PathFindResultType.PathNotFound: - consolex.log(`path not found to target`); + console.log(`path not found to target`); break; } } @@ -222,7 +221,7 @@ export class WarshipExecution implements Execution { this.warship.touch(); return; case PathFindResultType.PathNotFound: - consolex.warn(`path not found to target tile`); + console.warn(`path not found to target tile`); this.warship.setTargetTile(undefined); break; } diff --git a/src/core/execution/alliance/AllianceRequestExecution.ts b/src/core/execution/alliance/AllianceRequestExecution.ts index 7698b0c82..0475d8f9f 100644 --- a/src/core/execution/alliance/AllianceRequestExecution.ts +++ b/src/core/execution/alliance/AllianceRequestExecution.ts @@ -1,4 +1,3 @@ -import { consolex } from "../../Consolex"; import { Execution, Game, Player, PlayerID } from "../../game/Game"; export class AllianceRequestExecution implements Execution { @@ -36,9 +35,9 @@ export class AllianceRequestExecution implements Execution { throw new Error("Not initialized"); } if (this.requestor.isFriendly(this.recipient)) { - consolex.warn("already allied"); + console.warn("already allied"); } else if (!this.requestor.canSendAllianceRequest(this.recipient)) { - consolex.warn("recent or pending alliance request"); + console.warn("recent or pending alliance request"); } else { this.requestor.createAllianceRequest(this.recipient); } diff --git a/src/core/execution/alliance/AllianceRequestReplyExecution.ts b/src/core/execution/alliance/AllianceRequestReplyExecution.ts index 3c6bdc5e7..ed3177517 100644 --- a/src/core/execution/alliance/AllianceRequestReplyExecution.ts +++ b/src/core/execution/alliance/AllianceRequestReplyExecution.ts @@ -1,4 +1,3 @@ -import { consolex } from "../../Consolex"; import { Execution, Game, Player, PlayerID } from "../../game/Game"; export class AllianceRequestReplyExecution implements Execution { @@ -36,13 +35,13 @@ export class AllianceRequestReplyExecution implements Execution { throw new Error("Not initialized"); } if (this.requestor.isFriendly(this.recipient)) { - consolex.warn("already allied"); + console.warn("already allied"); } else { const request = this.requestor .outgoingAllianceRequests() .find((ar) => ar.recipient() === this.recipient); if (request === undefined) { - consolex.warn("no alliance request found"); + console.warn("no alliance request found"); } else { if (this.accept) { request.accept(); diff --git a/src/core/execution/alliance/BreakAllianceExecution.ts b/src/core/execution/alliance/BreakAllianceExecution.ts index 65e2ebc16..a028b0cb0 100644 --- a/src/core/execution/alliance/BreakAllianceExecution.ts +++ b/src/core/execution/alliance/BreakAllianceExecution.ts @@ -1,4 +1,3 @@ -import { consolex } from "../../Consolex"; import { Execution, Game, Player, PlayerID } from "../../game/Game"; export class BreakAllianceExecution implements Execution { @@ -42,7 +41,7 @@ export class BreakAllianceExecution implements Execution { } const alliance = this.requestor.allianceWith(this.recipient); if (alliance === null) { - consolex.warn("cant break alliance, not allied"); + console.warn("cant break alliance, not allied"); } else { this.requestor.breakAlliance(alliance); this.recipient.updateRelation(this.requestor, -200); diff --git a/src/core/game/GameImpl.ts b/src/core/game/GameImpl.ts index b54618bca..1b26d3f83 100644 --- a/src/core/game/GameImpl.ts +++ b/src/core/game/GameImpl.ts @@ -1,5 +1,4 @@ import { Config } from "../configuration/Config"; -import { consolex } from "../Consolex"; import { AllPlayersStats, ClientID } from "../Schemas"; import { simpleHash } from "../Util"; import { AllianceImpl } from "./AllianceImpl"; @@ -196,7 +195,7 @@ export class GameImpl implements Game { recipient: Player, ): AllianceRequest | null { if (requestor.isAlliedWith(recipient)) { - consolex.log("cannot request alliance, already allied"); + console.log("cannot request alliance, already allied"); return null; } if ( @@ -204,14 +203,14 @@ export class GameImpl implements Game { .incomingAllianceRequests() .find((ar) => ar.requestor() === requestor) !== undefined ) { - consolex.log(`duplicate alliance request from ${requestor.name()}`); + console.log(`duplicate alliance request from ${requestor.name()}`); return null; } const correspondingReq = requestor .incomingAllianceRequests() .find((ar) => ar.requestor() === recipient); if (correspondingReq !== undefined) { - consolex.log(`got corresponding alliance requests, accepting`); + console.log(`got corresponding alliance requests, accepting`); correspondingReq.accept(); return null; } diff --git a/src/core/game/PlayerImpl.ts b/src/core/game/PlayerImpl.ts index d5acf261d..2812b71ab 100644 --- a/src/core/game/PlayerImpl.ts +++ b/src/core/game/PlayerImpl.ts @@ -1,5 +1,4 @@ import { renderNumber, renderTroops } from "../../client/Utils"; -import { consolex } from "../Consolex"; import { PseudoRandom } from "../PseudoRandom"; import { ClientID } from "../Schemas"; import { @@ -270,7 +269,7 @@ export class PlayerImpl implements Player { orderRetreat(id: string) { const attack = this._outgoingAttacks.filter((attack) => attack.id() === id); if (!attack || !attack[0]) { - consolex.warn(`Didn't find outgoing attack with id ${id}`); + console.warn(`Didn't find outgoing attack with id ${id}`); return; } attack[0].orderRetreat(); diff --git a/src/core/game/TerrainMapLoader.ts b/src/core/game/TerrainMapLoader.ts index adf2399fb..73098359e 100644 --- a/src/core/game/TerrainMapLoader.ts +++ b/src/core/game/TerrainMapLoader.ts @@ -1,4 +1,3 @@ -import { consolex } from "../Consolex"; import { GameMapType } from "./Game"; import { GameMap, GameMapImpl } from "./GameMap"; import { terrainMapFileLoader } from "./TerrainMapFileLoader"; @@ -65,13 +64,13 @@ export async function genTerrainFromBin(data: string): Promise { } function logBinaryAsAscii(data: string, length: number = 8) { - consolex.log("Binary data (1 = set bit, 0 = unset bit):"); + console.log("Binary data (1 = set bit, 0 = unset bit):"); for (let i = 0; i < Math.min(length, data.length); i++) { const byte = data.charCodeAt(i); let byteString = ""; for (let j = 7; j >= 0; j--) { byteString += byte & (1 << j) ? "1" : "0"; } - consolex.log(`Byte ${i}: ${byteString}`); + console.log(`Byte ${i}: ${byteString}`); } } diff --git a/src/core/pathfinding/PathFinding.ts b/src/core/pathfinding/PathFinding.ts index 9d26439e0..049407ad0 100644 --- a/src/core/pathfinding/PathFinding.ts +++ b/src/core/pathfinding/PathFinding.ts @@ -1,4 +1,3 @@ -import { consolex } from "../Consolex"; import { Game } from "../game/Game"; import { GameMap, TileRef } from "../game/GameMap"; import { PseudoRandom } from "../PseudoRandom"; @@ -117,11 +116,11 @@ export class PathFinder { dist: number = 1, ): TileResult { if (curr === null) { - consolex.error("curr is null"); + console.error("curr is null"); return { type: PathFindResultType.PathNotFound }; } if (dst === null) { - consolex.error("dst is null"); + console.error("dst is null"); return { type: PathFindResultType.PathNotFound }; } diff --git a/src/core/pathfinding/SerialAStar.ts b/src/core/pathfinding/SerialAStar.ts index 7655a75ba..927fc4b90 100644 --- a/src/core/pathfinding/SerialAStar.ts +++ b/src/core/pathfinding/SerialAStar.ts @@ -1,5 +1,4 @@ import { PriorityQueue } from "@datastructures-js/priority-queue"; -import { consolex } from "../Consolex"; import { GameMap, TileRef } from "../game/GameMap"; import { AStar, PathFindResultType } from "./AStar"; @@ -154,7 +153,7 @@ export class SerialAStar implements AStar { Math.abs(this.gameMap.y(a) - this.gameMap.y(b))) ); } catch { - consolex.log("uh oh"); + console.log("uh oh"); return 0; } }