mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-21 09:20:47 +00:00
move multi-unit warship selection box to WebGL SelectionBoxPass
SelectionBoxPass now stores an array of selections and renders one quad per entry. GPURenderer gains setSelectedUnits(ids) — the single-unit setSelectedUnit becomes a wrapper. Position + color are rebuilt each frame from lastUnits; dead unit IDs get pruned in place. ClientGameRunner's UnitSelectionEvent listener forwards both single and multi to view.setSelectedUnits — no more single/multi split. UILayer drops everything canvas2D-related: the offscreen canvas + context, theme, selectionAnimTime, multiSelectionBoxCenters, SELECTION_BOX_SIZE, drawSelectionBoxMulti, paintSelectionBoxAt, clearSelectionBox, paintCell, clearCell, and renderLayer / redraw / shouldTransform. tick() now only prunes destroyed warships from the selection list; the layer is purely state + click handling. ~120 LOC gone. Tests: UILayer.test.ts updated — drops the canvas/redraw asserts, adds a multi-selection state assertion.
This commit is contained in:
@@ -28,17 +28,8 @@ describe("UILayer", () => {
|
||||
transformHandler = {};
|
||||
});
|
||||
|
||||
it("should initialize and redraw canvas", () => {
|
||||
const ui = new UILayer(game, eventBus, transformHandler);
|
||||
ui.redraw();
|
||||
expect(ui["canvas"].width).toBe(100);
|
||||
expect(ui["canvas"].height).toBe(100);
|
||||
expect(ui["context"]).not.toBeNull();
|
||||
});
|
||||
|
||||
it("tracks the selected unit on single-unit selection (rendering is WebGL)", () => {
|
||||
const ui = new UILayer(game, eventBus, transformHandler);
|
||||
ui.redraw();
|
||||
const unit = {
|
||||
type: () => "Warship",
|
||||
isActive: () => true,
|
||||
@@ -48,14 +39,13 @@ describe("UILayer", () => {
|
||||
const event = { isSelected: true, unit };
|
||||
ui["onUnitSelection"](event as UnitSelectionEvent);
|
||||
// selectedUnit is held for game-logic callers (the click handlers). The
|
||||
// visual selection box is now drawn by WebGL SelectionBoxPass — wired
|
||||
// from ClientGameRunner via view.setSelectedUnit(unit.id()).
|
||||
// visual selection box is drawn by WebGL SelectionBoxPass — wired from
|
||||
// ClientGameRunner via view.setSelectedUnits([unit.id()]).
|
||||
expect(ui["selectedUnit"]).toBe(unit);
|
||||
});
|
||||
|
||||
it("clears selection on deselect", () => {
|
||||
const ui = new UILayer(game, eventBus, transformHandler);
|
||||
ui.redraw();
|
||||
const unit = {
|
||||
type: () => "Warship",
|
||||
isActive: () => true,
|
||||
@@ -69,4 +59,19 @@ describe("UILayer", () => {
|
||||
} as unknown as UnitSelectionEvent);
|
||||
expect(ui["selectedUnit"]).toBeNull();
|
||||
});
|
||||
|
||||
it("tracks multi-selection list", () => {
|
||||
const ui = new UILayer(game, eventBus, transformHandler);
|
||||
const units = [
|
||||
{ id: () => 1, isActive: () => true },
|
||||
{ id: () => 2, isActive: () => true },
|
||||
];
|
||||
ui["onUnitSelection"]({
|
||||
isSelected: true,
|
||||
unit: null,
|
||||
units,
|
||||
} as unknown as UnitSelectionEvent);
|
||||
expect(ui["multiSelectedWarships"]).toEqual(units);
|
||||
expect(ui["selectedUnit"]).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user