mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-08-18 09:14:09 +00:00
Fix railroad glowing green for non-snapping structures (#4281)
## Problem When placing a building near a railroad, the railroad glows green to show the building would snap to it. This should only apply to **City**, **Port**, and **Factory** — but missile silos, SAMs, and defense posts (which cannot be placed on railroads) were also triggering the green highlight. ## Root cause The core's `overlappingRailroads()` populated snap tiles for *every* buildable type. In v31 the green highlight didn't leak because the client renderer (`RailroadLayer.ts`) gated it with a `SNAPPABLE_STRUCTURES = [Port, City, Factory]` allowlist: ```ts if (!SNAPPABLE_STRUCTURES.includes(this.uiState.ghostStructure)) return; ``` That guard was lost when the rendering was rewritten into the WebGL `RailroadPass`, which now unconditionally highlights every tile in `overlappingRailroads`. The data was always there; only the renderer's filter was protecting it. ## Fix Filter by unit type inside `overlappingRailroads()`, mirroring the existing guard in `computeGhostRailPaths()`. This keeps the snap-eligible type list defined once in the core (`RailNetworkImpl`) and fixes the leak regardless of which renderer consumes the data — rather than re-adding a client-side allowlist a future rewrite could drop again. ## Tests Updated `tests/core/game/RailNetwork.test.ts` for the new signature and added a case asserting `MissileSilo`/`DefensePost`/`SAMLauncher` return `[]` (and don't even query the rail grid). All 23 tests pass. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -178,7 +178,7 @@ describe("RailNetworkImpl", () => {
|
||||
};
|
||||
(network as any).railGrid = railGridMock;
|
||||
|
||||
const result = network.overlappingRailroads(tile);
|
||||
const result = network.overlappingRailroads(UnitType.City, tile);
|
||||
|
||||
expect(railGridMock.query).toHaveBeenCalledWith(tile, 3);
|
||||
expect(result).toEqual([42, 45, 50, 60]); // Deduplicated and sorted
|
||||
@@ -189,10 +189,30 @@ describe("RailNetworkImpl", () => {
|
||||
const railGridMock = { query: vi.fn(() => new Set()) };
|
||||
(network as any).railGrid = railGridMock;
|
||||
|
||||
const result = network.overlappingRailroads(tile);
|
||||
const result = network.overlappingRailroads(UnitType.City, tile);
|
||||
|
||||
expect(result).toEqual([]);
|
||||
});
|
||||
|
||||
test.each([
|
||||
UnitType.MissileSilo,
|
||||
UnitType.DefensePost,
|
||||
UnitType.SAMLauncher,
|
||||
])(
|
||||
"returns empty array for %s which cannot snap to railroads",
|
||||
(unitType) => {
|
||||
const tile = 42 as any;
|
||||
const railGridMock = {
|
||||
query: vi.fn(() => new Set([{ tiles: [50, 42, 60] }])),
|
||||
};
|
||||
(network as any).railGrid = railGridMock;
|
||||
|
||||
const result = network.overlappingRailroads(unitType, tile);
|
||||
|
||||
expect(result).toEqual([]);
|
||||
expect(railGridMock.query).not.toHaveBeenCalled();
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
describe("computeGhostRailPaths", () => {
|
||||
|
||||
Reference in New Issue
Block a user