show alliance icon

This commit is contained in:
evanpelle
2025-01-21 16:47:18 -08:00
committed by Evan
parent ba654fd7ea
commit ab183e4f59
7 changed files with 22 additions and 20 deletions
+1 -11
View File
@@ -1,6 +1,5 @@
import { AllPlayers, Cell, Game, Player, PlayerType } from "../../../core/game/Game"
import { PseudoRandom } from "../../../core/PseudoRandom"
import { calculateBoundingBox } from "../../../core/Util"
import { Theme } from "../../../core/configuration/Config"
import { Layer } from "./Layer"
import { TransformHandler } from "../TransformHandler"
@@ -28,7 +27,6 @@ class RenderInfo {
export class NameLayer implements Layer {
private canvas: HTMLCanvasElement
private context: CanvasRenderingContext2D
private lastChecked = 0
@@ -50,11 +48,6 @@ export class NameLayer implements Layer {
private firstPlace: Player | null = null
private lastUpdate = 0
private updateFrequency = 250
private lastRect = null;
constructor(private game: GameView, private theme: Theme, private transformHandler: TransformHandler, private clientID: ClientID) {
this.traitorIconImage = new Image();
this.traitorIconImage.src = traitorIcon;
@@ -83,9 +76,6 @@ export class NameLayer implements Layer {
public init() {
// this.canvas = document.createElement('canvas');
this.canvas = createCanvas()
this.context = this.canvas.getContext("2d")
window.addEventListener('resize', () => this.resizeCanvas());
this.resizeCanvas();
@@ -293,7 +283,7 @@ export class NameLayer implements Layer {
if (this.myPlayer != null) {
return this.myPlayer
}
this.myPlayer = this.game.players().find(p => p.clientID() == this.clientID)
this.myPlayer = this.game.playerViews().find(p => p.clientID() == this.clientID)
return this.myPlayer
}
}
@@ -61,6 +61,8 @@ export class PlayerInfoOverlay extends LitElement implements Layer {
private _isActive = false;
private lastMouseUpdate = 0
init() {
this.eventBus.on(MouseMoveEvent, (e: MouseMoveEvent) => this.onMouseEvent(e));
this._isActive = true;
@@ -68,6 +70,13 @@ export class PlayerInfoOverlay extends LitElement implements Layer {
}
private onMouseEvent(event: MouseMoveEvent) {
const now = Date.now()
if (now - this.lastMouseUpdate < 100) {
return
}
this.lastMouseUpdate = now
this.setVisible(false);
this.unit = null;
this.player = null;
@@ -85,7 +94,6 @@ export class PlayerInfoOverlay extends LitElement implements Layer {
if (owner && owner.isPlayer()) {
this.player = owner;
(this.player as PlayerView).profile().then(p => {
console.log(`got profile ${JSON.stringify(p)}`);
this.playerProfile = p;
});
this.setVisible(true);
@@ -136,7 +144,7 @@ export class PlayerInfoOverlay extends LitElement implements Layer {
private renderPlayerInfo(player: Player) {
const myPlayer = this.myPlayer();
const isAlly = (myPlayer?.isAlliedWith(player) || player == this.myPlayer()) ?? false;
const isAlly = myPlayer.isAlliedWith(player)
let relationHtml = null;
if (player.type() == PlayerType.FakeHuman && myPlayer != null) {
let classType = '';
+5 -2
View File
@@ -119,12 +119,15 @@ export class GameRunner {
throw new Error(`player with id ${playerID} not found`);
}
return {
const rel = {
relations: Object.fromEntries(
player.allRelationsSorted()
.map(({ player, relation }) => [player.smallID(), relation])
)
),
alliances: player.alliances().map(a => a.other(player).smallID())
};
console.log(`got relations: ${JSON.stringify(rel)}`)
return rel
}
private canBoat(myPlayer: Player, tile: TileRef): boolean {
+1 -1
View File
@@ -127,7 +127,7 @@ export class PlayerView implements Player {
}
isAlliedWith(other: Player): boolean {
return false
return this.data.alliances.some(n => other.smallID() == n)
}
allianceWith(other: Player): Alliance | null {
return null
+1 -2
View File
@@ -30,8 +30,7 @@ export class DevConfig extends DefaultConfig {
return info
}
// tradeShipSpawnRate(): number {
// return 10
// tradeShipSpawnRate(): number { // return 10
// }
// boatMaxDistance(): number {
// return 5000
+2 -1
View File
@@ -370,7 +370,7 @@ export interface PlayerActions {
export interface PlayerProfile {
relations: Record<number, Relation>
// TODO: add alliances etc
alliances: number[]
}
export interface PlayerInteraction {
@@ -428,6 +428,7 @@ export interface PlayerUpdate {
workers: number,
troops: number,
targetTroopRatio: number
alliances: number[]
}
+2 -1
View File
@@ -75,7 +75,8 @@ export class PlayerImpl implements MutablePlayer {
population: this.population(),
workers: this.workers(),
troops: this.troops(),
targetTroopRatio: this.targetTroopRatio()
targetTroopRatio: this.targetTroopRatio(),
alliances: this.alliances().map(a => a.other(this).smallID())
}
}