diff --git a/src/client/Transport.ts b/src/client/Transport.ts index 9a8300144..acfac9089 100644 --- a/src/client/Transport.ts +++ b/src/client/Transport.ts @@ -1,7 +1,8 @@ import { Config } from "../core/configuration/Config" +import { SendLogEvent } from "../core/Consolex" import { EventBus, GameEvent } from "../core/EventBus" import { AllianceRequest, AllPlayers, Cell, GameType, Player, PlayerID, PlayerType, Tile, UnitType } from "../core/game/Game" -import { ClientID, ClientIntentMessageSchema, ClientJoinMessageSchema, GameID, Intent, ServerMessage, ServerMessageSchema, ClientPingMessageSchema, GameConfig, ClientLogMessageSchema, LogSeverity } from "../core/Schemas" +import { ClientID, ClientIntentMessageSchema, ClientJoinMessageSchema, GameID, Intent, ServerMessage, ServerMessageSchema, ClientPingMessageSchema, GameConfig, ClientLogMessageSchema } from "../core/Schemas" import { LobbyConfig } from "./GameRunner" import { LocalServer } from "./LocalServer" @@ -82,13 +83,6 @@ export class SendSetTargetTroopRatioEvent implements GameEvent { ) { } } -export class SendLogEvent implements GameEvent { - constructor( - public readonly severity: LogSeverity, - public readonly log: string, - ) { } -} - export class Transport { private socket: WebSocket diff --git a/src/core/Consolex.ts b/src/core/Consolex.ts index 8026b66ab..944e3e6b4 100644 --- a/src/core/Consolex.ts +++ b/src/core/Consolex.ts @@ -1,6 +1,5 @@ -import { EventBus } from "./EventBus" +import { EventBus, GameEvent } from "./EventBus" import { LogSeverity } from "./Schemas" -import { SendLogEvent } from "../client/Transport" export const consolex = { log: console.log, @@ -31,4 +30,10 @@ export function initRemoteSender(eventBus: EventBus) { console.error(...args); eventBus.emit(new SendLogEvent(LogSeverity.Error, args.join(' '))) } -} \ No newline at end of file +} +export class SendLogEvent implements GameEvent { + constructor( + public readonly severity: LogSeverity, + public readonly log: string + ) { } +} diff --git a/src/core/configuration/Config.ts b/src/core/configuration/Config.ts index 379cbde73..d8aa1e034 100644 --- a/src/core/configuration/Config.ts +++ b/src/core/configuration/Config.ts @@ -4,6 +4,7 @@ import { devConfig } from "./DevConfig"; import { GameID } from "../Schemas"; import { preprodConfig } from "./PreprodConfig"; import { prodConfig } from "./ProdConfig"; +import { consolex } from "../Consolex"; export enum GameEnv { Dev, @@ -13,13 +14,13 @@ export enum GameEnv { export function getConfig(): Config { switch (process.env.GAME_ENV) { case 'dev': - console.log('using dev config') + consolex.log('using dev config') return devConfig case 'preprod': - console.log('using preprod config') + consolex.log('using preprod config') return preprodConfig case 'prod': - console.log('using prod config') + consolex.log('using prod config') return prodConfig default: throw Error(`unsupported server configuration: ${process.env.GAME_ENV}`) diff --git a/src/core/configuration/DefaultConfig.ts b/src/core/configuration/DefaultConfig.ts index 19b602859..e109a8f23 100644 --- a/src/core/configuration/DefaultConfig.ts +++ b/src/core/configuration/DefaultConfig.ts @@ -264,7 +264,7 @@ export abstract class DefaultConfig implements Config { const ratio = 1 - (player.population() / max) toAdd *= ratio toAdd *= .5 - // console.log(`to add ${toAdd}`) + // consolex.log(`to add ${toAdd}`) if (player.type() == PlayerType.FakeHuman) { toAdd *= 1.0 diff --git a/src/core/execution/AttackExecution.ts b/src/core/execution/AttackExecution.ts index 7b5fae3bd..cc0a4ff5f 100644 --- a/src/core/execution/AttackExecution.ts +++ b/src/core/execution/AttackExecution.ts @@ -130,8 +130,8 @@ export class AttackExecution implements Execution { } let numTilesPerTick = this.mg.config().attackTilesPerTick(this._owner, this.target, this.border.size + this.random.nextInt(0, 5)) - // console.log(`num tiles per tick: ${numTilesPerTick}`) - // console.log(`num execs: ${this.mg.executions().length}`) + // consolex.log(`num tiles per tick: ${numTilesPerTick}`) + // consolex.log(`num execs: ${this.mg.executions().length}`) while (numTilesPerTick > 0) { diff --git a/src/core/execution/BattleshipExecution.ts b/src/core/execution/BattleshipExecution.ts index a2fa7793a..50cd9a5a8 100644 --- a/src/core/execution/BattleshipExecution.ts +++ b/src/core/execution/BattleshipExecution.ts @@ -5,6 +5,7 @@ import { SerialAStar } from "../pathfinding/SerialAStar"; import { PseudoRandom } from "../PseudoRandom"; import { distSort, distSortUnit, manhattanDist } from "../Util"; import { ShellExecution } from "./ShellExecution"; +import { consolex } from "../Consolex"; export class BattleshipExecution implements Execution { private random: PseudoRandom @@ -66,7 +67,7 @@ export class BattleshipExecution implements Execution { case PathFindResultType.Pending: return case PathFindResultType.PathNotFound: - console.log(`path not found to patrol tile`) + consolex.log(`path not found to patrol tile`) this.patrolTile = this.randomTile() break } diff --git a/src/core/execution/BotSpawner.ts b/src/core/execution/BotSpawner.ts index 59ed42fd4..7c86491c4 100644 --- a/src/core/execution/BotSpawner.ts +++ b/src/core/execution/BotSpawner.ts @@ -1,3 +1,4 @@ +import { consolex } from "../Consolex"; import {Cell, Game, PlayerType, Tile, TileEvent} from "../game/Game"; import {PseudoRandom} from "../PseudoRandom"; import {GameID, SpawnIntent} from "../Schemas"; @@ -16,7 +17,7 @@ export class BotSpawner { let tries = 0 while (this.bots.length < numBots) { if (tries > 10000) { - console.log('too many retries while spawning bots, giving up') + consolex.log('too many retries while spawning bots, giving up') return this.bots } const spawn = this.spawnBot("Bot" + this.bots.length) diff --git a/src/core/execution/CityExecution.ts b/src/core/execution/CityExecution.ts index e9046f0dd..b5b5a49d5 100644 --- a/src/core/execution/CityExecution.ts +++ b/src/core/execution/CityExecution.ts @@ -1,3 +1,4 @@ +import { consolex } from "../Consolex"; import { Cell, DefenseBonus, Execution, MutableGame, MutablePlayer, MutableUnit, PlayerID, Tile, UnitType } from "../game/Game"; import { bfs, dist } from "../Util"; @@ -21,7 +22,7 @@ export class CityExecution implements Execution { if (this.city == null) { const spawnTile = this.player.canBuild(UnitType.City, this.tile) if (spawnTile == false) { - console.warn('cannot build Defense Post') + consolex.warn('cannot build Defense Post') this.active = false return } diff --git a/src/core/execution/DefensePostExecution.ts b/src/core/execution/DefensePostExecution.ts index 86869f1d4..34e4cb2dc 100644 --- a/src/core/execution/DefensePostExecution.ts +++ b/src/core/execution/DefensePostExecution.ts @@ -1,3 +1,4 @@ +import { consolex } from "../Consolex"; import { Cell, DefenseBonus, Execution, MutableGame, MutablePlayer, MutableUnit, PlayerID, Tile, UnitType } from "../game/Game"; import { bfs, dist } from "../Util"; @@ -23,7 +24,7 @@ export class DefensePostExecution implements Execution { if (this.post == null) { const spawnTile = this.player.canBuild(UnitType.DefensePost, this.tile) if (spawnTile == false) { - console.warn('cannot build Defense Post') + consolex.warn('cannot build Defense Post') this.active = false return } diff --git a/src/core/execution/DestroyerExecution.ts b/src/core/execution/DestroyerExecution.ts index 371bbc00d..1ac1da493 100644 --- a/src/core/execution/DestroyerExecution.ts +++ b/src/core/execution/DestroyerExecution.ts @@ -4,6 +4,7 @@ import { PathFindResultType } from "../pathfinding/AStar"; import { SerialAStar } from "../pathfinding/SerialAStar"; import { PseudoRandom } from "../PseudoRandom"; import { distSort, distSortUnit, manhattanDist } from "../Util"; +import { consolex } from "../Consolex"; export class DestroyerExecution implements Execution { private random: PseudoRandom @@ -72,7 +73,7 @@ export class DestroyerExecution implements Execution { case PathFindResultType.Pending: return case PathFindResultType.PathNotFound: - console.log(`path not found to patrol tile`) + consolex.log(`path not found to patrol tile`) this.patrolTile = this.randomTile() break } @@ -110,7 +111,7 @@ export class DestroyerExecution implements Execution { case PathFindResultType.Pending: break case PathFindResultType.PathNotFound: - console.log(`path not found to target`) + consolex.log(`path not found to target`) break } } diff --git a/src/core/execution/DonateExecution.ts b/src/core/execution/DonateExecution.ts index 995c63e3b..c737f1bca 100644 --- a/src/core/execution/DonateExecution.ts +++ b/src/core/execution/DonateExecution.ts @@ -1,3 +1,4 @@ +import { consolex } from "../Consolex"; import {AllPlayers, Execution, MutableGame, MutablePlayer, PlayerID} from "../game/Game"; export class DonateExecution implements Execution { @@ -26,7 +27,7 @@ export class DonateExecution implements Execution { if (this.sender.canDonate(this.recipient)) { this.sender.donate(this.recipient, this.troops) } else { - console.warn(`cannot send tropps from ${this.sender} to ${this.recipient}`) + consolex.warn(`cannot send tropps from ${this.sender} to ${this.recipient}`) } this.active = false } diff --git a/src/core/execution/EmojiExecution.ts b/src/core/execution/EmojiExecution.ts index fa6b2e385..89146ec8d 100644 --- a/src/core/execution/EmojiExecution.ts +++ b/src/core/execution/EmojiExecution.ts @@ -1,3 +1,4 @@ +import { consolex } from "../Consolex"; import {AllPlayers, Execution, MutableGame, MutablePlayer, PlayerID} from "../game/Game"; export class EmojiExecution implements Execution { @@ -23,7 +24,7 @@ export class EmojiExecution implements Execution { if (this.requestor.canSendEmoji(this.recipient)) { this.requestor.sendEmoji(this.recipient, this.emoji) } else { - console.warn(`cannot send emoji from ${this.requestor} to ${this.recipient}`) + consolex.warn(`cannot send emoji from ${this.requestor} to ${this.recipient}`) } this.active = false } diff --git a/src/core/execution/FakeHumanExecution.ts b/src/core/execution/FakeHumanExecution.ts index 06346e74d..9fa1e4885 100644 --- a/src/core/execution/FakeHumanExecution.ts +++ b/src/core/execution/FakeHumanExecution.ts @@ -10,6 +10,7 @@ import { PathFinder } from "../pathfinding/PathFinding"; import { DestroyerExecution } from "./DestroyerExecution"; import { BattleshipExecution } from "./BattleshipExecution"; import { GameID } from "../Schemas"; +import { consolex } from "../Consolex"; export class FakeHumanExecution implements Execution { @@ -42,7 +43,7 @@ export class FakeHumanExecution implements Execution { if (ticks % this.random.nextInt(5, 30) == 0) { const rl = this.randomLand() if (rl == null) { - console.warn(`cannot spawn ${this.playerInfo.name}`) + consolex.warn(`cannot spawn ${this.playerInfo.name}`) return } this.mg.addExecution(new SpawnExecution( @@ -180,7 +181,7 @@ export class FakeHumanExecution implements Execution { } const canBuild = this.player.canBuild(UnitType.Destroyer, targetTile) if (canBuild == false) { - console.warn('cannot spawn destroyer') + consolex.warn('cannot spawn destroyer') return false } switch (shipType) { diff --git a/src/core/execution/MissileSiloExecution.ts b/src/core/execution/MissileSiloExecution.ts index 5142eb21e..4a233b786 100644 --- a/src/core/execution/MissileSiloExecution.ts +++ b/src/core/execution/MissileSiloExecution.ts @@ -1,3 +1,4 @@ +import { consolex } from "../Consolex"; import { Cell, Execution, MutableGame, MutablePlayer, MutableUnit, Player, PlayerID, Tile, Unit, UnitType } from "../game/Game"; export class MissileSiloExecution implements Execution { @@ -22,7 +23,7 @@ export class MissileSiloExecution implements Execution { if (this.silo == null) { const tile = this.mg.tile(this.cell) if (!this.player.canBuild(UnitType.MissileSilo, tile)) { - console.warn(`player ${this.player} cannot build port at ${this.cell}`) + consolex.warn(`player ${this.player} cannot build port at ${this.cell}`) this.active = false return } diff --git a/src/core/execution/NukeExecution.ts b/src/core/execution/NukeExecution.ts index 5f904f560..39f5c04ad 100644 --- a/src/core/execution/NukeExecution.ts +++ b/src/core/execution/NukeExecution.ts @@ -4,6 +4,7 @@ import { PathFinder } from "../pathfinding/PathFinding"; import { PathFindResultType } from "../pathfinding/AStar"; import { PseudoRandom } from "../PseudoRandom"; import { bfs, dist, distSortUnit, euclideanDist, manhattanDist } from "../Util"; +import { consolex } from "../Consolex"; export class NukeExecution implements Execution { @@ -35,7 +36,7 @@ export class NukeExecution implements Execution { if (this.nuke == null) { const spawn = this.player.canBuild(this.type, this.dst) if (spawn == false) { - console.warn(`cannot build Nuke`) + consolex.warn(`cannot build Nuke`) this.active = false return } @@ -55,7 +56,7 @@ export class NukeExecution implements Execution { case PathFindResultType.Pending: break case PathFindResultType.PathNotFound: - console.warn(`nuke cannot find path from ${this.nuke.tile()} to ${this.dst}`) + consolex.warn(`nuke cannot find path from ${this.nuke.tile()} to ${this.dst}`) this.active = false return } diff --git a/src/core/execution/PlayerExecution.ts b/src/core/execution/PlayerExecution.ts index c86f7942c..981e4a408 100644 --- a/src/core/execution/PlayerExecution.ts +++ b/src/core/execution/PlayerExecution.ts @@ -2,6 +2,7 @@ import { Config } from "../configuration/Config" import { Execution, MutableGame, MutablePlayer, Player, PlayerID, TerraNullius, Tile } from "../game/Game" import { bfs, calculateBoundingBox, getMode, inscribed, simpleHash } from "../Util" import { GameImpl } from "../game/GameImpl" +import { consolex } from "../Consolex" export class PlayerExecution implements Execution { @@ -71,7 +72,7 @@ export class PlayerExecution implements Execution { this.removeClusters() const end = performance.now() if (end - start > 1000) { - console.log(`player ${this.player.name()}, took ${end - start}ms`) + consolex.log(`player ${this.player.name()}, took ${end - start}ms`) } } } @@ -138,7 +139,7 @@ export class PlayerExecution implements Execution { const arr = Array.from(cluster) const mode = getMode(arr.flatMap(t => t.neighbors()).filter(t => t.hasOwner() && t.owner() != this.player).map(t => t.owner().id())) if (!this.mg.hasPlayer(mode)) { - console.warn('mode is not found') + consolex.warn('mode is not found') return } const firstTile = arr[0] @@ -147,7 +148,7 @@ export class PlayerExecution implements Execution { const modePlayer = this.mg.player(mode) if (modePlayer == null) { - console.warn('mode player is null') + consolex.warn('mode player is null') } for (const tile of tiles) { modePlayer.conquer(tile) diff --git a/src/core/execution/PortExecution.ts b/src/core/execution/PortExecution.ts index aeb6d81a2..fdd608623 100644 --- a/src/core/execution/PortExecution.ts +++ b/src/core/execution/PortExecution.ts @@ -6,6 +6,7 @@ import { PseudoRandom } from "../PseudoRandom"; import { bfs, dist, manhattanDist } from "../Util"; import { TradeShipExecution } from "./TradeShipExecution"; import { ParallelAStar, WorkerClient } from "../worker/WorkerClient"; +import { consolex } from "../Consolex"; export class PortExecution implements Execution { @@ -35,7 +36,7 @@ export class PortExecution implements Execution { const tile = this.mg.tile(this.cell) const player = this.mg.player(this._owner) if (!player.canBuild(UnitType.Port, tile)) { - console.warn(`player ${player} cannot build port at ${this.cell}`) + consolex.warn(`player ${player} cannot build port at ${this.cell}`) this.active = false return } @@ -44,7 +45,7 @@ export class PortExecution implements Execution { .sort((a, b) => manhattanDist(a.cell(), tile.cell()) - manhattanDist(b.cell(), tile.cell())) if (spawns.length == 0) { - console.warn(`cannot find spawn for port`) + consolex.warn(`cannot find spawn for port`) this.active = false return } @@ -78,13 +79,13 @@ export class PortExecution implements Execution { case PathFindResultType.Pending: break case PathFindResultType.PathNotFound: - console.warn(`path not found to port`) + consolex.warn(`path not found to port`) break } continue } const asyncPF = this.worker.createParallelAStar(this.port.tile(), port.tile(), 25, [TerrainType.Ocean]) - // console.log(`adding new port path from ${this.player().name()}:${this.port.tile().cell()} to ${port.owner().name()}:${port.tile().cell()}`) + // consolex.log(`adding new port path from ${this.player().name()}:${this.port.tile().cell()} to ${port.owner().name()}:${port.tile().cell()}`) this.computingPaths.set(port, asyncPF) } diff --git a/src/core/execution/SetTargetTroopRatioExecution.ts b/src/core/execution/SetTargetTroopRatioExecution.ts index 10e68fe17..9e8fcb546 100644 --- a/src/core/execution/SetTargetTroopRatioExecution.ts +++ b/src/core/execution/SetTargetTroopRatioExecution.ts @@ -1,3 +1,4 @@ +import { consolex } from "../Consolex"; import { Execution, MutableGame, MutablePlayer, PlayerID } from "../game/Game"; export class SetTargetTroopRatioExecution implements Execution { @@ -15,7 +16,7 @@ export class SetTargetTroopRatioExecution implements Execution { tick(ticks: number): void { if (this.targetTroopsRatio < 0 || this.targetTroopsRatio > 1) { - console.warn(`target troop ratio of ${this.targetTroopsRatio} for player ${this.player} invalid`) + consolex.warn(`target troop ratio of ${this.targetTroopsRatio} for player ${this.player} invalid`) } else { this.player.setTargetTroopRatio(this.targetTroopsRatio) } diff --git a/src/core/execution/ShellExecution.ts b/src/core/execution/ShellExecution.ts index b3b17a0df..834ef4421 100644 --- a/src/core/execution/ShellExecution.ts +++ b/src/core/execution/ShellExecution.ts @@ -1,6 +1,7 @@ import { Execution, MutableGame, MutablePlayer, MutableUnit, Tile, Unit, UnitType } from "../game/Game"; import { PathFinder } from "../pathfinding/PathFinding"; import { PathFindResultType } from "../pathfinding/AStar"; +import { consolex } from "../Consolex"; export class ShellExecution implements Execution { @@ -43,7 +44,7 @@ export class ShellExecution implements Execution { case PathFindResultType.Pending: return case PathFindResultType.PathNotFound: - console.log(`Shell ${this.shell} could not find target`) + consolex.log(`Shell ${this.shell} could not find target`) this.active = false this.shell.delete(false) return diff --git a/src/core/execution/TradeShipExecution.ts b/src/core/execution/TradeShipExecution.ts index f8f94d12c..962a4893c 100644 --- a/src/core/execution/TradeShipExecution.ts +++ b/src/core/execution/TradeShipExecution.ts @@ -6,6 +6,7 @@ import { PathFindResultType } from "../pathfinding/AStar"; import { SerialAStar } from "../pathfinding/SerialAStar"; import { PseudoRandom } from "../PseudoRandom"; import { bfs, dist, distSortUnit, manhattanDist } from "../Util"; +import { consolex } from "../Consolex"; export class TradeShipExecution implements Execution { @@ -35,7 +36,7 @@ export class TradeShipExecution implements Execution { if (this.tradeShip == null) { const spawn = this.origOwner.canBuild(UnitType.TradeShip, this.srcPort.tile()) if (spawn == false) { - console.warn(`cannot build trade ship`) + consolex.warn(`cannot build trade ship`) this.active = false return } @@ -86,7 +87,7 @@ export class TradeShipExecution implements Execution { this.tradeShip.move(result.tile) break case PathFindResultType.PathNotFound: - console.warn('captured trade ship cannot find route') + consolex.warn('captured trade ship cannot find route') this.active = false break } diff --git a/src/core/execution/TransportShipExecution.ts b/src/core/execution/TransportShipExecution.ts index f1ce4d19f..0a3231b87 100644 --- a/src/core/execution/TransportShipExecution.ts +++ b/src/core/execution/TransportShipExecution.ts @@ -5,6 +5,7 @@ import { DisplayMessageEvent, MessageType } from "../../client/graphics/layers/E import { PathFinder } from "../pathfinding/PathFinding"; import { PathFindResultType } from "../pathfinding/AStar"; import { SerialAStar } from "../pathfinding/SerialAStar"; +import { consolex } from "../Consolex"; export class TransportShipExecution implements Execution { @@ -68,13 +69,13 @@ export class TransportShipExecution implements Execution { this.dst = targetTransportTile(this.mg, this.mg.tile(this.cell)) if (this.dst == null) { - console.warn(`${this.attacker} cannot send ship to ${this.target}, cannot find attack tile`) + consolex.warn(`${this.attacker} cannot send ship to ${this.target}, cannot find attack tile`) this.active = false return } const src = this.attacker.canBuild(UnitType.TransportShip, this.dst) if (src == false) { - console.warn(`can't build transport ship`) + consolex.warn(`can't build transport ship`) this.active = false return } @@ -124,7 +125,7 @@ export class TransportShipExecution implements Execution { break case PathFindResultType.PathNotFound: // TODO: add to poisoned port list - console.warn(`path not found tot dst`) + consolex.warn(`path not found tot dst`) this.boat.delete(false) this.active = false return diff --git a/src/core/execution/alliance/AllianceRequestExecution.ts b/src/core/execution/alliance/AllianceRequestExecution.ts index 588e0b0fc..17cce82fe 100644 --- a/src/core/execution/alliance/AllianceRequestExecution.ts +++ b/src/core/execution/alliance/AllianceRequestExecution.ts @@ -1,3 +1,4 @@ +import { consolex } from "../../Consolex"; import {AllianceRequest, Execution, MutableGame, MutablePlayer, Player, PlayerID} from "../../game/Game"; export class AllianceRequestExecution implements Execution { @@ -16,9 +17,9 @@ export class AllianceRequestExecution implements Execution { tick(ticks: number): void { if (this.requestor.isAlliedWith(this.recipient)) { - console.warn('already allied') + consolex.warn('already allied') } else if (this.requestor.recentOrPendingAllianceRequestWith(this.recipient)) { - console.warn('recent or pending alliance request') + consolex.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 82afd0b6e..dbd68acb1 100644 --- a/src/core/execution/alliance/AllianceRequestReplyExecution.ts +++ b/src/core/execution/alliance/AllianceRequestReplyExecution.ts @@ -1,3 +1,4 @@ +import { consolex } from "../../Consolex"; import {AllianceRequest, Execution, MutableGame, MutablePlayer, Player, PlayerID} from "../../game/Game"; export class AllianceRequestReplyExecution implements Execution { @@ -16,11 +17,11 @@ export class AllianceRequestReplyExecution implements Execution { tick(ticks: number): void { if (this.requestor.isAlliedWith(this.recipient)) { - console.warn('already allied') + consolex.warn('already allied') } else { const request = this.requestor.outgoingAllianceRequests().find(ar => ar.recipient() == this.recipient) if (request == null) { - console.warn('no alliance request found') + consolex.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 9f316c18a..2e383a6d4 100644 --- a/src/core/execution/alliance/BreakAllianceExecution.ts +++ b/src/core/execution/alliance/BreakAllianceExecution.ts @@ -1,3 +1,4 @@ +import { consolex } from "../../Consolex"; import {AllianceRequest, Execution, MutableGame, MutablePlayer, Player, PlayerID} from "../../game/Game"; export class BreakAllianceExecution implements Execution { @@ -15,7 +16,7 @@ export class BreakAllianceExecution implements Execution { tick(ticks: number): void { const alliance = this.requestor.allianceWith(this.recipient) if (alliance == null) { - console.warn('cant break alliance, not allied') + consolex.warn('cant break alliance, not allied') } else { this.requestor.breakAlliance(alliance) } diff --git a/src/core/game/GameImpl.ts b/src/core/game/GameImpl.ts index 00eca92c5..49e4b4618 100644 --- a/src/core/game/GameImpl.ts +++ b/src/core/game/GameImpl.ts @@ -11,6 +11,7 @@ import { AllianceImpl } from "./AllianceImpl"; import { ClientID, GameConfig } from "../Schemas"; import { DisplayMessageEvent, MessageType } from "../../client/graphics/layers/EventsDisplay"; import { UnitImpl } from "./UnitImpl"; +import { consolex } from "../Consolex"; export function createGame(terrainMap: TerrainMapImpl, miniMap: TerrainMap, eventBus: EventBus, config: Config, gameConfig: GameConfig): Game { return new GameImpl(terrainMap, miniMap, eventBus, config, gameConfig) @@ -104,16 +105,16 @@ export class GameImpl implements MutableGame { createAllianceRequest(requestor: MutablePlayer, recipient: Player): MutableAllianceRequest { if (requestor.isAlliedWith(recipient)) { - console.log('cannot request alliance, already allied') + consolex.log('cannot request alliance, already allied') return } if (recipient.incomingAllianceRequests().find(ar => ar.requestor() == requestor) != null) { - console.log(`duplicate alliance request from ${requestor.name()}`) + consolex.log(`duplicate alliance request from ${requestor.name()}`) return } const correspondingReq = requestor.incomingAllianceRequests().find(ar => ar.requestor() == recipient) if (correspondingReq != null) { - console.log(`got corresponding alliance requests, accepting`) + consolex.log(`got corresponding alliance requests, accepting`) correspondingReq.accept() return } @@ -182,7 +183,7 @@ export class GameImpl implements MutableGame { this._players.forEach(p => { hash += p.hash() }) - console.log(`tick ${this._ticks}: hash ${hash}`) + consolex.log(`tick ${this._ticks}: hash ${hash}`) } } diff --git a/src/core/game/TerrainMapLoader.ts b/src/core/game/TerrainMapLoader.ts index 40f587ad7..1b4d03857 100644 --- a/src/core/game/TerrainMapLoader.ts +++ b/src/core/game/TerrainMapLoader.ts @@ -14,6 +14,7 @@ import northAmericaInfo from "../../../resources/maps/NorthAmerica.json" import oceaniaBin from "!!binary-loader!../../../resources/maps/Oceania.bin" import oceaniaInfo from "../../../resources/maps/Oceania.json" +import { consolex } from '../Consolex'; const maps = new Map() .set(GameMap.World, { bin: worldBin, info: worldInfo }) @@ -113,13 +114,13 @@ export async function loadTerrainMap(map: GameMap): Promise { setTimeout(() => resolve(mapData.bin), 100); }); - console.log(`Loaded data length: ${fileData.length} bytes`); + consolex.log(`Loaded data length: ${fileData.length} bytes`); // Extract width and height from the first 4 bytes const width = (fileData.charCodeAt(1) << 8) | fileData.charCodeAt(0); const height = (fileData.charCodeAt(3) << 8) | fileData.charCodeAt(2); - console.log(`Decoded dimensions: ${width}x${height}`); + consolex.log(`Decoded dimensions: ${width}x${height}`); // Check if the data length matches the expected size if (fileData.length != width * height + 4) { // +4 for the width and height bytes @@ -221,13 +222,13 @@ export async function createMiniMap(tm: TerrainMap): Promise { function logBinaryAsAscii(data: string, length: number = 8) { - console.log('Binary data (1 = set bit, 0 = unset bit):'); + consolex.log('Binary data (1 = set bit, 0 = unset bit):'); for (let i = 0; i < Math.min(length, data.length); i++) { let byte = data.charCodeAt(i); let byteString = ''; for (let j = 7; j >= 0; j--) { byteString += (byte & (1 << j)) ? '1' : '0'; } - console.log(`Byte ${i}: ${byteString}`); + consolex.log(`Byte ${i}: ${byteString}`); } } \ No newline at end of file diff --git a/src/core/pathfinding/PathFinding.ts b/src/core/pathfinding/PathFinding.ts index 5a2ce35c0..a1b9b9fe5 100644 --- a/src/core/pathfinding/PathFinding.ts +++ b/src/core/pathfinding/PathFinding.ts @@ -4,6 +4,7 @@ import { AStar, PathFindResultType, SearchNode, TileResult } from "./AStar"; import { ParallelAStar, WorkerClient } from "../worker/WorkerClient"; import { SerialAStar } from "./SerialAStar"; import { MiniAStar } from "./MiniAStar"; +import { consolex } from "../Consolex"; export class PathFinder { @@ -65,10 +66,10 @@ export class PathFinder { nextTile(curr: Tile, dst: Tile, dist: number = 1): TileResult { if (curr == null) { - console.error('curr is null') + consolex.error('curr is null') } if (dst == null) { - console.error('dst is null') + consolex.error('dst is null') } if (manhattanDist(curr.cell(), dst.cell()) < dist) { diff --git a/src/core/pathfinding/SerialAStar.ts b/src/core/pathfinding/SerialAStar.ts index c35ad8423..8251c71ee 100644 --- a/src/core/pathfinding/SerialAStar.ts +++ b/src/core/pathfinding/SerialAStar.ts @@ -2,6 +2,7 @@ import { PriorityQueue } from "@datastructures-js/priority-queue"; import { AStar, SearchNode } from "./AStar"; import { PathFindResultType } from "./AStar"; import { Cell } from "../game/Game"; +import { consolex } from "../Consolex"; export class SerialAStar implements AStar { @@ -111,7 +112,7 @@ export class SerialAStar implements AStar { try { return 1.1 * Math.abs(a.cell().x - b.cell().x) + Math.abs(a.cell().y - b.cell().y); } catch { - console.log('uh oh') + consolex.log('uh oh') } } diff --git a/src/core/worker/Worker.worker.ts b/src/core/worker/Worker.worker.ts index b868c118b..ed285a493 100644 --- a/src/core/worker/Worker.worker.ts +++ b/src/core/worker/Worker.worker.ts @@ -5,6 +5,7 @@ import { PriorityQueue } from "@datastructures-js/priority-queue"; import { SerialAStar } from "../pathfinding/SerialAStar"; import { AStar, PathFindResultType, SearchNode } from "../pathfinding/AStar"; import { MiniAStar } from "../pathfinding/MiniAStar"; +import { consolex } from "../Consolex"; let terrainMapPromise: Promise<{ terrainMap: TerrainMap, @@ -99,7 +100,7 @@ function computeSearches() { searches.push(search) break case PathFindResultType.PathNotFound: - console.warn(`worker: path not found to port`); + consolex.warn(`worker: path not found to port`); self.postMessage({ type: 'pathNotFound', requestId: search.requestId, diff --git a/src/core/worker/WorkerClient.ts b/src/core/worker/WorkerClient.ts index 3db8c7a36..4d202d8ad 100644 --- a/src/core/worker/WorkerClient.ts +++ b/src/core/worker/WorkerClient.ts @@ -1,3 +1,4 @@ +import { consolex } from "../Consolex"; import { Cell, Game, GameMap, TerrainTile, TerrainType, Tile } from "../game/Game"; import { AStar, PathFindResultType } from "../pathfinding/AStar"; import { MiniAStar } from "../pathfinding/MiniAStar"; @@ -111,7 +112,7 @@ export class ParallelAStar implements AStar { } // Path was not found in worker thread in time, so now we need // to recompute it in main thread. This will lock up game. - console.warn(`path not completed in worker thread, recomputing`) + consolex.warn(`path not completed in worker thread, recomputing`) const local = new MiniAStar( this.game.terrainMap(), this.game.terrainMiniMap(), @@ -123,7 +124,7 @@ export class ParallelAStar implements AStar { const result = local.compute() switch (result) { case PathFindResultType.Completed: - console.log('recomputed path in worker client') + consolex.log('recomputed path in worker client') this.path = local.reconstructPath() break case PathFindResultType.PathNotFound: @@ -131,7 +132,7 @@ export class ParallelAStar implements AStar { break case PathFindResultType.Pending: // TODO: make sure same number of tries as worker thread. - console.warn("path not found after many tries") + consolex.warn("path not found after many tries") this.path = "NOT_FOUND" break } diff --git a/src/server/Server.ts b/src/server/Server.ts index c3974e92a..3804e0076 100644 --- a/src/server/Server.ts +++ b/src/server/Server.ts @@ -45,7 +45,7 @@ app.get('/lobbies', (req, res) => { app.post('/private_lobby', (req, res) => { const id = gm.createPrivateGame() - console.logx('creating private lobby with id ${id}') + console.log('creating private lobby with id ${id}') res.json({ id: id }); @@ -79,7 +79,7 @@ app.post('/archive_singleplayer_game', (req, res) => { }) app.post('/start_private_lobby/:id', (req, res) => { - console.logx(`starting private lobby with id ${req.params.id}`) + console.log(`starting private lobby with id ${req.params.id}`) gm.startPrivateGame(req.params.id) });