mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-24 11:45:24 +00:00
2f67c45a17
## Description: Cleanup code & small perf improvement Gave it v26 milestone because it gives a little perf bump at no cost, all the removed code isn't used anywhere so can be safely deleted. Triple checked. - Remove 'setFocusedPlayer' and 'checkTileUnderCursor' (not to be confused by still in use 'getTileUnderCursor') from ClientGameRunner, '_focusedPlayer' and 'setFocusedPlayer' (not to be confused with still-in-use 'focusedPlayer') from GameView, and 'setFocusedPlayer' from TransformHander. These are remnants of PR #304, the first one that added highlighting territory. The remants are still ran for every mouse-move, costing some performance for no reason. _focusedPlayer is never used anywhere anymore, only calculated and set. It was later adapted from #387. But ultimately almost completely disabled because it was too performance-costly, from commits15c2cc1and thenec895af. The thing that remained was permanent highlight of the player's own border. For that, function 'focusedPlayer' in GameView is still used by 'drawFocusedPlayerHighlight' in TerritoryLayer. But it simply returns myPlayer instead of the obsolete _focusedPlayer that it returned earlier. Function 'focusedPlayer' still had the annotation "// TODO: renable when performance issues are fixed." which i removed. Because another PR for highlighting other's territory already followed it up with its own functions, so chances of needing to change 'focusedPlayer' back are very slim. Later PR #1320 introduced a new attempt for highlighting territory in the alternate view. It used its own equivalent functions in TerritoryLayer for MouseOver and updateHighlightedTerritory (the latter being the equivalent of the old checkTileUnderCursor in ClientGameRunner). That was also disabled in part due to perfomance cost, and now only shows border color changes. All this to say: the remnants of PR 320 and 387 have long been redundant. - Main: removed uncommented chatModal code, which was never used and leftover from tests during development probably. - PlayerActionHandler: removed handleQuickChat and the sendQuickChatEvent import it needed. It was added in PR Multi-level radial menu #1018. But the new Radial menu in the meantime moved to using ChatIntegration.ts to send the chat event, or from there opened the original Chat Modal which then sent the chat event. Later on, chat was even removed from the Radial menu. 'handleQuickChat' is used nowhere anymore and isn't needed. This is maybe also the case for ChatIntegration, but i didn't remove it because it may still be enabled again in the future for UI changes or something. - OptionsMenu: removed, also from index.html (options-menu). This menu has been succeeded by GameRightSidebar (game-right-sidebar for index.html) for awhile now. ## Please complete the following: - [x] I have added screenshots for all UI updates - [x] I process any text displayed to the user through translateText() and I've added it to the en.json file - [x] I have added relevant tests to the test directory - [x] I confirm I have thoroughly tested these changes and take full responsibility for any bugs introduced ## Please put your Discord username so you can be contacted if a bug or regression is found: tryout33
103 lines
2.7 KiB
TypeScript
103 lines
2.7 KiB
TypeScript
import { EventBus } from "../../../core/EventBus";
|
|
import { PlayerActions, PlayerID } from "../../../core/game/Game";
|
|
import { TileRef } from "../../../core/game/GameMap";
|
|
import { PlayerView } from "../../../core/game/GameView";
|
|
import {
|
|
SendAllianceRequestIntentEvent,
|
|
SendAttackIntentEvent,
|
|
SendBoatAttackIntentEvent,
|
|
SendBreakAllianceIntentEvent,
|
|
SendDeleteUnitIntentEvent,
|
|
SendDonateGoldIntentEvent,
|
|
SendDonateTroopsIntentEvent,
|
|
SendEmbargoIntentEvent,
|
|
SendEmojiIntentEvent,
|
|
SendSpawnIntentEvent,
|
|
SendTargetPlayerIntentEvent,
|
|
} from "../../Transport";
|
|
import { UIState } from "../UIState";
|
|
|
|
export class PlayerActionHandler {
|
|
constructor(
|
|
private eventBus: EventBus,
|
|
private uiState: UIState,
|
|
) {}
|
|
|
|
async getPlayerActions(
|
|
player: PlayerView,
|
|
tile: TileRef,
|
|
): Promise<PlayerActions> {
|
|
return await player.actions(tile);
|
|
}
|
|
|
|
handleAttack(player: PlayerView, targetId: string | null) {
|
|
this.eventBus.emit(
|
|
new SendAttackIntentEvent(
|
|
targetId,
|
|
this.uiState.attackRatio * player.troops(),
|
|
),
|
|
);
|
|
}
|
|
|
|
handleBoatAttack(
|
|
player: PlayerView,
|
|
targetId: PlayerID | null,
|
|
targetTile: TileRef,
|
|
spawnTile: TileRef | null,
|
|
) {
|
|
this.eventBus.emit(
|
|
new SendBoatAttackIntentEvent(
|
|
targetId,
|
|
targetTile,
|
|
this.uiState.attackRatio * player.troops(),
|
|
spawnTile,
|
|
),
|
|
);
|
|
}
|
|
|
|
async findBestTransportShipSpawn(
|
|
player: PlayerView,
|
|
tile: TileRef,
|
|
): Promise<TileRef | false> {
|
|
return await player.bestTransportShipSpawn(tile);
|
|
}
|
|
|
|
handleSpawn(tile: TileRef) {
|
|
this.eventBus.emit(new SendSpawnIntentEvent(tile));
|
|
}
|
|
|
|
handleAllianceRequest(player: PlayerView, recipient: PlayerView) {
|
|
this.eventBus.emit(new SendAllianceRequestIntentEvent(player, recipient));
|
|
}
|
|
|
|
handleBreakAlliance(player: PlayerView, recipient: PlayerView) {
|
|
this.eventBus.emit(new SendBreakAllianceIntentEvent(player, recipient));
|
|
}
|
|
|
|
handleTargetPlayer(targetId: string | null) {
|
|
if (!targetId) return;
|
|
|
|
this.eventBus.emit(new SendTargetPlayerIntentEvent(targetId));
|
|
}
|
|
|
|
handleDonateGold(recipient: PlayerView) {
|
|
this.eventBus.emit(new SendDonateGoldIntentEvent(recipient, null));
|
|
}
|
|
|
|
handleDonateTroops(recipient: PlayerView) {
|
|
this.eventBus.emit(new SendDonateTroopsIntentEvent(recipient, null));
|
|
}
|
|
|
|
handleEmbargo(recipient: PlayerView, action: "start" | "stop") {
|
|
this.eventBus.emit(new SendEmbargoIntentEvent(recipient, action));
|
|
}
|
|
|
|
handleEmoji(targetPlayer: PlayerView | "AllPlayers", emojiIndex: number) {
|
|
this.eventBus.emit(new SendEmojiIntentEvent(targetPlayer, emojiIndex));
|
|
}
|
|
|
|
handleDeleteUnit(unitId: number) {
|
|
this.eventBus.emit(new SendDeleteUnitIntentEvent(unitId));
|
|
}
|
|
}
|