alert when alliance request has been accepted or rejected

This commit is contained in:
evanpelle
2024-09-17 20:53:40 -07:00
parent d4d0be5e37
commit 0ef18a1602
3 changed files with 19 additions and 7 deletions
+14 -2
View File
@@ -1,7 +1,7 @@
import {GameEnv, Theme} from "../../../core/configuration/Config";
import {EventBus, GameEvent} from "../../../core/EventBus";
import {WinEvent} from "../../../core/execution/WinCheckExecution";
import {AllianceRequest, Game, Player} from "../../../core/game/Game";
import {AllianceRequest, AllianceRequestReplyEvent, Game, Player} from "../../../core/game/Game";
import {ClientID} from "../../../core/Schemas";
import {renderTroops} from "../Utils";
import winModalHtml from '../WinModal.html';
@@ -31,6 +31,7 @@ export class UILayer implements Layer {
constructor(private eventBus: EventBus, private game: Game, private theme: Theme, private clientID: ClientID, private transformHandler: TransformHandler) {
}
render(context: CanvasRenderingContext2D) {
if (!this.game.inSpawnPhase()) {
return
@@ -62,6 +63,7 @@ export class UILayer implements Layer {
this.initRightClickMenu()
this.eventBus.on(WinEvent, (e) => this.onWinEvent(e))
this.eventBus.on(RightClickEvent, (e) => this.onRightClick(e))
this.eventBus.on(AllianceRequestReplyEvent, (e) => this.onAllianceRequestReplyEvent(e))
}
initRightClickMenu() {
@@ -186,12 +188,22 @@ export class UILayer implements Layer {
document.body.appendChild(this.exitButton);
}
onWinEvent(event: WinEvent) {
console.log(`${event.winner.name()} won the game!!}`)
this.showWinModal(event.winner)
}
onAllianceRequestReplyEvent(event: AllianceRequestReplyEvent) {
if (event.allianceRequest.requestor().clientID() == this.clientID) {
const recipient = event.allianceRequest.recipient().name()
if (event.accepted) {
alert(`${recipient} accepted your alliance request`)
} else {
alert(`${recipient} rejected your alliance request`)
}
}
}
showWinModal(winner: Player) {
if (this.winModal) {
const message = this.winModal.querySelector('#winMessage');
+2 -2
View File
@@ -15,10 +15,10 @@ export class AllianceRequestImpl implements MutableAllianceRequest {
}
accept(): void {
throw new Error("Method not implemented.");
this.game.acceptAllianceRequest(this)
}
reject(): void {
throw new Error("Method not implemented.");
this.game.rejectAllianceRequest(this)
}
}
+3 -3
View File
@@ -1,7 +1,7 @@
import {info} from "console";
import {Config} from "../configuration/Config";
import {EventBus} from "../EventBus";
import {Cell, Execution, MutableGame, Game, MutablePlayer, PlayerEvent, PlayerID, PlayerInfo, Player, TerraNullius, Tile, TileEvent, Boat, BoatEvent, PlayerType, MutableAllianceRequest} from "./Game";
import {Cell, Execution, MutableGame, Game, MutablePlayer, PlayerEvent, PlayerID, PlayerInfo, Player, TerraNullius, Tile, TileEvent, Boat, BoatEvent, PlayerType, MutableAllianceRequest, AllianceRequestReplyEvent} from "./Game";
import {TerrainMap} from "./TerrainMapLoader";
import {PlayerImpl} from "./PlayerImpl";
import {TerraNulliusImpl} from "./TerraNulliusImpl";
@@ -57,12 +57,12 @@ export class GameImpl implements MutableGame {
this.allianceRequests = this.allianceRequests.filter(ar => ar != request)
const alliance = new AllianceImpl(request.requestor() as PlayerImpl, request.recipient() as PlayerImpl, this._ticks)
this.alliances_.push(alliance)
// TODO: Fire event.
this.eventBus.emit(new AllianceRequestReplyEvent(request, true))
}
rejectAllianceRequest(request: AllianceRequestImpl) {
this.allianceRequests = this.allianceRequests.filter(ar => ar != request)
// TODO: Fire event.
this.eventBus.emit(new AllianceRequestReplyEvent(request, false))
}
numLandTiles(): number {