move single-unit warship selection box to WebGL SelectionBoxPass

UnitSelectionEvent now forwards to view.setSelectedUnit(unit.id()) in
mountWebGLDebugRenderer; the renderer's SelectionBoxPass draws the
animated stippled outline on the GPU. UILayer still tracks
selectedUnit for game-logic readers (the click handlers) but no longer
paints to canvas2D for it.

Drops drawSelectionBox + lastSelectionBoxCenter (~50 LOC) plus the
per-tick single-unit redraw in tick(). Multi-selection stays on
canvas2D — SelectionBoxPass is single-unit only.

Test update: replaces the now-dead drawSelectionBox spy with a
selectedUnit state assertion + a deselect case.
This commit is contained in:
evanpelle
2026-05-16 19:53:13 -07:00
parent d1651017ea
commit ede0fb7668
3 changed files with 61 additions and 91 deletions
+18
View File
@@ -43,6 +43,7 @@ import {
MouseMoveEvent,
MouseUpEvent,
TickMetricsEvent,
UnitSelectionEvent,
} from "./InputHandler";
import { endGame, startGame, startTime } from "./LocalPersistantStats";
import { terrainMapFileLoader } from "./TerrainMapFileLoader";
@@ -345,6 +346,23 @@ function mountWebGLDebugRenderer(
view.showMoveIndicator(tx, ty, firstUnit.owner().smallID());
});
// Single-unit warship selection box: forward UnitSelectionEvent to the
// renderer's SelectionBoxPass. Multi-selection (event.units.length > 0)
// stays canvas2D for now — SelectionBoxPass only supports one unit.
eventBus.on(UnitSelectionEvent, (e) => {
if (!e.isSelected) {
view.setSelectedUnit(null);
return;
}
if ((e.units ?? []).length > 0) {
// Multi-selection: drop any prior single highlight; canvas2D draws
// the multi outlines in UILayer.
view.setSelectedUnit(null);
return;
}
view.setSelectedUnit(e.unit?.id() ?? null);
});
return { builder: new WebGLFrameBuilder(view), syncCamera };
}