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
This commit is contained in:
falc
2025-06-04 18:22:17 +02:00
committed by 1brucben
parent 410d9a1909
commit 07916d46bf
41 changed files with 91 additions and 183 deletions
+14 -16
View File
@@ -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<TerrainMapData> | 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) &&
+6 -7
View File
@@ -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<GameInfo> {
}
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
}
}
+5 -6
View File
@@ -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<void> {
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);
});
}
}
+1 -2
View File
@@ -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;
}
+1 -2
View File
@@ -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;
+2 -3
View File
@@ -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;
}
}
+4 -5
View File
@@ -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", {
-13
View File
@@ -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({
+8 -9
View File
@@ -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;
+1 -2
View File
@@ -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;
}
+2 -3
View File
@@ -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()) {
-39
View File
@@ -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,
) {}
}
+4 -5
View File
@@ -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}`);
+1 -2
View File
@@ -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;
}
+1 -2
View File
@@ -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();
+1 -2
View File
@@ -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;
}
+1 -2
View File
@@ -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;
}
+1 -2
View File
@@ -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;
}
+1 -2
View File
@@ -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()}`,
);
}
+1 -2
View File
@@ -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}`,
);
}
+2 -3
View File
@@ -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}`,
);
}
+2 -3
View File
@@ -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(
+1 -2
View File
@@ -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;
}
+1 -2
View File
@@ -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;
+2 -3
View File
@@ -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;
}
+1 -2
View File
@@ -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`);
}
}
}
+1 -2
View File
@@ -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;
}
+3 -4
View File
@@ -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}`,
);
+1 -2
View File
@@ -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;
}
@@ -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 {
+2 -3
View File
@@ -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);
}
+3 -4
View File
@@ -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;
+2 -3
View File
@@ -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;
}
@@ -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);
}
@@ -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();
@@ -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);
+3 -4
View File
@@ -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;
}
+1 -2
View File
@@ -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();
+2 -3
View File
@@ -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<GameMap> {
}
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}`);
}
}
+2 -3
View File
@@ -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 };
}
+1 -2
View File
@@ -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;
}
}