mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-21 17:00:16 +00:00
show alliance icon
This commit is contained in:
@@ -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 = '';
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -30,8 +30,7 @@ export class DevConfig extends DefaultConfig {
|
||||
return info
|
||||
}
|
||||
|
||||
// tradeShipSpawnRate(): number {
|
||||
// return 10
|
||||
// tradeShipSpawnRate(): number { // return 10
|
||||
// }
|
||||
// boatMaxDistance(): number {
|
||||
// return 5000
|
||||
|
||||
@@ -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[]
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user