added right click option break alliance

This commit is contained in:
evanpelle
2024-09-21 09:42:43 -07:00
parent 6600c4cbe0
commit 5f38d2a544
8 changed files with 106 additions and 18 deletions
+11 -1
View File
@@ -10,7 +10,7 @@ import {TerrainMap} from "../core/game/TerrainMapLoader";
import {and, bfs, dist, manhattanDist} from "../core/Util";
import {TerrainLayer} from "./graphics/layers/TerrainLayer";
import {WinCheckExecution} from "../core/execution/WinCheckExecution";
import {SendAllianceRequestUIEvent} from "./graphics/layers/UILayer";
import {SendAllianceRequestUIEvent, SendBreakAllianceUIEvent} from "./graphics/layers/UILayer";
import {createCanvas} from "./graphics/Utils";
import {AllianceRequestReplyUIEvent as SendAllianceRequestReplyUIEvent} from "./graphics/layers/EventsDisplay";
@@ -127,6 +127,7 @@ export class ClientGame {
this.eventBus.on(MouseUpEvent, (e) => this.inputEvent(e))
this.eventBus.on(SendAllianceRequestUIEvent, (e) => this.onSendAllianceRequest(e))
this.eventBus.on(SendAllianceRequestReplyUIEvent, (e) => this.onAllianceRequestReplyUIEvent(e))
this.eventBus.on(SendBreakAllianceUIEvent, (e) => this.onBreakAllianceRequestUIEvent(e))
this.renderer.initialize()
this.input.initialize()
@@ -294,6 +295,15 @@ export class ClientGame {
})
}
private onBreakAllianceRequestUIEvent(event: SendBreakAllianceUIEvent) {
this.sendIntent({
type: "breakAlliance",
clientID: this.id,
requestor: event.requestor.id(),
recipient: event.recipient.id(),
})
}
private sendSpawnIntent(cell: Cell) {
this.sendIntent({
type: "spawn",
+32 -10
View File
@@ -14,6 +14,14 @@ export class SendAllianceRequestUIEvent implements GameEvent {
) { }
}
export class SendBreakAllianceUIEvent implements GameEvent {
constructor(
public readonly requestor: Player,
public readonly recipient: Player
) { }
}
interface MenuOption {
label: string;
action: () => void;
@@ -236,34 +244,48 @@ export class UILayer implements Layer {
if (!tile.hasOwner()) {
return
}
const options: MenuOption[] = []
const owner = tile.owner() as Player
if (owner.clientID() == this.clientID) {
return
}
// TODO: check if already allied with
const myPlayer = this.game.players().find(p => p.clientID() == this.clientID)
if (!myPlayer) {
console.warn('my player not found')
return
}
if (myPlayer.alliedWith(owner) || myPlayer.pendingAllianceRequestWith(owner)) {
if (myPlayer.pendingAllianceRequestWith(owner)) {
return
}
this.customMenu!.style.display = 'block';
this.customMenu!.style.left = `${e.x}px`;
this.customMenu!.style.top = `${e.y}px`;
this.populateMenu([
{
if (myPlayer.alliedWith(owner)) {
options.push({
label: "Break Alliance",
action: (): void => {
this.eventBus.emit(
new SendBreakAllianceUIEvent(myPlayer, owner)
)
},
})
} else {
options.push({
label: "Request Alliance",
action: (): void => {
this.eventBus.emit(
new SendAllianceRequestUIEvent(myPlayer, owner)
)
},
}
])
})
}
this.customMenu!.style.display = 'block';
this.customMenu!.style.left = `${e.x}px`;
this.customMenu!.style.top = `${e.y}px`;
this.populateMenu(options)
}
private populateMenu(options: MenuOption[]) {