mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-07-30 08:39:40 +00:00
have GameRunner calculate Name location
This commit is contained in:
+17
-4
@@ -1,3 +1,4 @@
|
||||
import { placeName } from "../client/graphics/NameBoxCalculator";
|
||||
import { getConfig } from "./configuration/Config";
|
||||
import { EventBus } from "./EventBus";
|
||||
import { Executor } from "./execution/ExecutionManager";
|
||||
@@ -5,7 +6,7 @@ import { WinCheckExecution } from "./execution/WinCheckExecution";
|
||||
import { Game, MutableGame, MutableTile, PlayerID, Tile, TileEvent } from "./game/Game";
|
||||
import { createGame } from "./game/GameImpl";
|
||||
import { loadTerrainMap } from "./game/TerrainMapLoader";
|
||||
import { GameUpdateViewData, packTileData, PlayerViewData } from "./GameView";
|
||||
import { GameUpdateViewData, NameViewData, packTileData, PlayerViewData } from "./GameView";
|
||||
import { GameConfig, Turn } from "./Schemas";
|
||||
|
||||
export async function createGameRunner(gameID: string, gameConfig: GameConfig, callBack: (gu: GameUpdateViewData) => void): Promise<GameRunner> {
|
||||
@@ -25,6 +26,8 @@ export class GameRunner {
|
||||
private currTurn = 0
|
||||
private isExecuting = false
|
||||
|
||||
private playerToName = new Map<PlayerID, NameViewData>()
|
||||
|
||||
constructor(
|
||||
private game: MutableGame,
|
||||
private eventBus: EventBus,
|
||||
@@ -64,16 +67,26 @@ export class GameRunner {
|
||||
this.currTurn++
|
||||
this.game.executeNextTick()
|
||||
|
||||
if (this.game.ticks() % 10 == 0) {
|
||||
this.game.players()
|
||||
.forEach(p => this.playerToName.set(p.id(), placeName(this.game, p)))
|
||||
}
|
||||
|
||||
const playerViewData = {}
|
||||
for (const player of this.game.allPlayers()) {
|
||||
const viewData = player.toViewData()
|
||||
viewData.nameViewData = this.playerToName.get(player.id())
|
||||
playerViewData[player.id()] = viewData
|
||||
}
|
||||
|
||||
this.callBack({
|
||||
tick: this.game.ticks(),
|
||||
units: this.game.units().map(u => u.toViewData()),
|
||||
packedTileUpdates: Array.from(this.updatedTiles).map(t => packTileData(t.toViewData())),
|
||||
players: Object.fromEntries(
|
||||
this.game.allPlayers().map(p => [p.id(), p.toViewData()])
|
||||
) as Record<PlayerID, PlayerViewData>
|
||||
players: playerViewData
|
||||
})
|
||||
|
||||
|
||||
this.isExecuting = false
|
||||
}
|
||||
|
||||
|
||||
@@ -98,7 +98,15 @@ export class UnitView {
|
||||
}
|
||||
}
|
||||
|
||||
export interface NameViewData {
|
||||
nameX: number,
|
||||
nameY: number,
|
||||
nameSize: number,
|
||||
}
|
||||
|
||||
export interface PlayerViewData extends ViewData<PlayerViewData> {
|
||||
nameViewData?: NameViewData,
|
||||
|
||||
clientID: ClientID,
|
||||
name: string,
|
||||
displayName: string,
|
||||
|
||||
Reference in New Issue
Block a user