mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-21 12:10:46 +00:00
alert when alliance request has been accepted or rejected
This commit is contained in:
@@ -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');
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user