mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-07-16 11:23:16 +00:00
replace MapInteraction with HoverHighlightController; one input system
MapInteraction bound DOM events to the WebGL canvas, but the canvas has pointer-events: none post-migration so its pointermove/down/up/wheel/ keydown listeners never fired — duplicating InputHandler (which owns the inputOverlay div + EventBus pipeline) and leaving most features dead. The one alive bit was hover→setHighlightOwner, which I'd manually forwarded as a workaround. Now there's a HoverHighlightController that listens to MouseMoveEvent, computes the cursor's tile owner, and pushes setHighlightOwner. Delete map-interaction.ts (418 lines) + keyboard-pan.ts, trim the DOM-binding constructor + proxy methods (setFitZoomOnDoubleClick, setPanSpeed, setZoomSpeed, etc.) out of GameView, and drop the ClientGameRunner pointermove forwarder. Input flows through one path: DOM → inputOverlay → InputHandler → EventBus → controllers/renderer.
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
/**
|
||||
* HoverHighlightController — pushes the cursor's tile-owner to the WebGL
|
||||
* view so the territory + border passes can highlight the hovered player.
|
||||
*
|
||||
* Replaces the hover path inside the renderer's MapInteraction class (which
|
||||
* was bound to the WebGL canvas; that canvas has pointer-events: none in the
|
||||
* current input architecture so its listeners never fired). All input flows
|
||||
* through InputHandler → MouseMoveEvent on the EventBus, so we just listen.
|
||||
*/
|
||||
|
||||
import { EventBus } from "../../core/EventBus";
|
||||
import { GameView } from "../../core/game/GameView";
|
||||
import { Controller } from "../Controller";
|
||||
import { MouseMoveEvent } from "../InputHandler";
|
||||
import { GameView as WebGLGameView } from "../render/gl";
|
||||
import { OWNER_MASK } from "../render/gl/utils/tile-codec";
|
||||
import { TransformHandler } from "../TransformHandler";
|
||||
|
||||
export class HoverHighlightController implements Controller {
|
||||
private lastOwnerID = 0;
|
||||
|
||||
constructor(
|
||||
private game: GameView,
|
||||
private eventBus: EventBus,
|
||||
private transformHandler: TransformHandler,
|
||||
private view: WebGLGameView,
|
||||
) {}
|
||||
|
||||
init() {
|
||||
this.eventBus.on(MouseMoveEvent, (e) => this.onMouseMove(e));
|
||||
}
|
||||
|
||||
private onMouseMove(e: MouseMoveEvent): void {
|
||||
const cell = this.transformHandler.screenToWorldCoordinates(e.x, e.y);
|
||||
let ownerID = 0;
|
||||
if (this.game.isValidCoord(cell.x, cell.y)) {
|
||||
const ref = this.game.ref(cell.x, cell.y);
|
||||
ownerID = this.game.tileState(ref) & OWNER_MASK;
|
||||
}
|
||||
if (ownerID === this.lastOwnerID) return;
|
||||
this.lastOwnerID = ownerID;
|
||||
this.view.setHighlightOwner(ownerID);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user