leaderboard works with view

This commit is contained in:
evanpelle
2025-01-06 14:29:02 -08:00
committed by Evan
parent d5e6667b1f
commit 29ad62c2a4
6 changed files with 15 additions and 18 deletions
+4 -4
View File
@@ -49,9 +49,9 @@ export class Leaderboard extends LitElement implements Layer {
if (this.clientID == null) {
return
}
const myPlayer = this.game.players().find(p => p.clientID() == this.clientID)
const myPlayer = this.game.playerViews().find(p => p.clientID() == this.clientID)
const sorted = this.game.players()
const sorted = this.game.playerViews()
.sort((a, b) => b.numTilesOwned() - a.numTilesOwned())
this.players = sorted
@@ -59,7 +59,7 @@ export class Leaderboard extends LitElement implements Layer {
.map((player, index) => ({
name: player.displayName(),
position: index + 1,
score: formatPercentage(player.numTilesOwned() / this.game.numLandTiles()),
score: formatPercentage(player.numTilesOwned() / this.game.terrainMap().numLandTiles()),
gold: renderNumber(player.gold()),
isMyPlayer: player == myPlayer,
player: player
@@ -78,7 +78,7 @@ export class Leaderboard extends LitElement implements Layer {
this.players.push({
name: myPlayer.displayName(),
position: place,
score: formatPercentage(myPlayer.numTilesOwned() / this.game.numLandTiles()),
score: formatPercentage(myPlayer.numTilesOwned() / this.game.terrainMap().numLandTiles()),
gold: renderNumber(myPlayer.gold()),
isMyPlayer: true,
player: myPlayer
+2 -4
View File
@@ -176,7 +176,7 @@ export class PlayerView implements Player {
return this.data.targetTroopRatio
}
troops(): number {
return
return this.data.troops
}
isAlliedWith(other: Player): boolean {
@@ -327,9 +327,7 @@ export class GameView {
height(): number {
return this._terrainMap.height()
}
numLandTiles(): number {
throw new Error("Method not implemented.");
}
forEachTile(fn: (tile: Tile) => void): void {
for (let x = 0; x < this._terrainMap.width(); x++) {
for (let y = 0; y < this._terrainMap.height(); y++) {
+3 -3
View File
@@ -1,5 +1,5 @@
import {EventBus, GameEvent} from "../EventBus"
import {Execution, MutableGame, MutablePlayer, Player, PlayerID} from "../game/Game"
import { EventBus, GameEvent } from "../EventBus"
import { Execution, MutableGame, MutablePlayer, Player, PlayerID } from "../game/Game"
export class WinEvent implements GameEvent {
constructor(public readonly winner: Player) { }
@@ -27,7 +27,7 @@ export class WinCheckExecution implements Execution {
return
}
const max = sorted[0]
if (max.numTilesOwned() / this.mg.numLandTiles() * 100 > this.mg.config().percentageTilesOwnedToWin()) {
if (max.numTilesOwned() / this.mg.terrainMap().numLandTiles() * 100 > this.mg.config().percentageTilesOwnedToWin()) {
this.eventBus.emit(new WinEvent(max))
this.active = false
}
+1 -1
View File
@@ -160,6 +160,7 @@ export interface TerrainMap {
width(): number
height(): number
isOnMap(cell: Cell): boolean
numLandTiles(): number
}
export interface TerrainTile extends SearchNode {
@@ -326,7 +327,6 @@ export interface Game {
neighbors(cell: Cell | Tile): Tile[]
width(): number
height(): number
numLandTiles(): number
forEachTile(fn: (tile: Tile) => void): void
executions(): ExecutionView[]
terraNullius(): TerraNullius
-4
View File
@@ -52,7 +52,6 @@ export class GameImpl implements MutableGame {
this._terraNullius = new TerraNulliusImpl()
this._width = _terrainMap.width();
this._height = _terrainMap.height();
this._numLandTiles = _terrainMap.numLandTiles
this.map = new Array(this._width);
for (let x = 0; x < this._width; x++) {
this.map[x] = new Array(this._height);
@@ -136,9 +135,6 @@ export class GameImpl implements MutableGame {
this.eventBus.emit(new AllianceRequestReplyEvent(request, false))
}
numLandTiles(): number {
return this._numLandTiles
}
hasPlayer(id: PlayerID): boolean {
return this._players.has(id)
}
+5 -2
View File
@@ -81,10 +81,13 @@ export class TerrainTileImpl implements TerrainTile {
export class TerrainMapImpl implements TerrainMap {
public tiles: TerrainTileImpl[][]
public numLandTiles: number
public _numLandTiles: number
public nationMap: NationMap
constructor(
) { }
numLandTiles(): number {
return this._numLandTiles
}
isOnMap(cell: Cell): boolean {
return cell.x >= 0 && cell.x < this.tiles.length && cell.y >= 0 && cell.y < this.tiles[0].length
}
@@ -177,7 +180,7 @@ export async function loadTerrainFromFile(fileData: string): Promise<TerrainMapI
}
}
m.tiles = terrain
m.numLandTiles = numLand
m._numLandTiles = numLand
return m
}