Files
OpenFrontIO/src/client/controllers/HoverHighlightController.ts
T
evanpelle 5a9694e2bd 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.
2026-05-17 20:46:02 -07:00

45 lines
1.6 KiB
TypeScript

/**
* 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);
}
}