-
Notifications
You must be signed in to change notification settings - Fork 755
feat: Factory Railway Tracks become more visible in Alternate View #2626
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
WalkthroughEventBus integration added to RailroadLayer to subscribe to AlternateViewEvent. When the alternative view is activated, rails owned by the current user are recolored green. The constructor now receives eventBus as a second parameter, passed from GameRenderer during layer initialization. Changes
Sequence DiagramsequenceDiagram
participant EB as EventBus
participant RL as RailroadLayer
participant GR as GameRenderer
GR->>RL: Initialize with eventBus parameter
RL->>EB: Subscribe to AlternateViewEvent
Note over RL: Store reference to eventBus
EB->>RL: Emit AlternateViewEvent
RL->>RL: Update alternativeView flag
RL->>RL: Repaint rails with<br/>conditional color logic
Note over RL: If currentUser owner +<br/>alternativeView active<br/>→ color = green<br/>else → normal owner color
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Possibly related PRs
Poem
Pre-merge checks❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
src/client/graphics/layers/RailroadLayer.ts (1)
257-266: LGTM!The color logic correctly applies green only to the user's own rails in alternate view while preserving original colors for other players. The null-safe
recipient?.isMe()check is clean.Minor: Consider extracting the green color to a constant to avoid creating a new
Colordinstance on each paint call:+const ALTERNATE_VIEW_RAIL_COLOR = colord("#00ff00"); + export class RailroadLayer implements Layer {Then use
ALTERNATE_VIEW_RAIL_COLORinstead ofcolord("#00ff00"). This is a small optimization and not required.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
src/client/graphics/GameRenderer.ts(1 hunks)src/client/graphics/layers/RailroadLayer.ts(6 hunks)
🧰 Additional context used
🧠 Learnings (3)
📚 Learning: 2025-10-18T11:00:57.142Z
Learnt from: NewYearNewPhil
Repo: openfrontio/OpenFrontIO PR: 2230
File: src/client/graphics/GameRenderer.ts:269-277
Timestamp: 2025-10-18T11:00:57.142Z
Learning: In src/client/graphics/GameRenderer.ts, the GameRecapCapture implementation does not use setCaptureRenderEnabled on layers. Instead, it uses RecapCaptureSurface.capture() to render capture layers (TerrainLayer, TerritoryLayer, RailroadLayer, StructureIconsLayer, UnitLayer) directly to an off-screen canvas without requiring layer-level capture mode methods.
Applied to files:
src/client/graphics/GameRenderer.ts
📚 Learning: 2025-11-21T22:30:12.246Z
Learnt from: scamiv
Repo: openfrontio/OpenFrontIO PR: 2493
File: src/core/game/TrainStation.ts:79-80
Timestamp: 2025-11-21T22:30:12.246Z
Learning: In src/core/game/TrainStation.ts and RailNetworkImpl.ts, the railroad network maintains a system invariant of at most one railroad between any two stations. RailNetworkImpl.connect is private and only called from connectToNearbyStations during initial station connection, which iterates over unique nearby units without duplicates. The Map<TrainStation, Railroad> structure in railroadByNeighbor correctly reflects this 1-to-1 relationship and should not be flagged as potentially allowing silent overwrites.
Applied to files:
src/client/graphics/GameRenderer.tssrc/client/graphics/layers/RailroadLayer.ts
📚 Learning: 2025-06-10T09:56:44.473Z
Learnt from: Ble4Ch
Repo: openfrontio/OpenFrontIO PR: 1063
File: src/core/configuration/PastelThemeDark.ts:53-53
Timestamp: 2025-06-10T09:56:44.473Z
Learning: In ColorAllocator class in src/core/configuration/Colors.ts, the correct method names are assignColor(id: string): Colord for general color assignment and assignTeamColor(team: Team): Colord for team-specific colors. There are no assignPlayerColor() or assignBotColor() methods.
Applied to files:
src/client/graphics/layers/RailroadLayer.ts
🧬 Code graph analysis (2)
src/client/graphics/GameRenderer.ts (1)
src/client/graphics/layers/RailroadLayer.ts (1)
RailroadLayer(24-295)
src/client/graphics/layers/RailroadLayer.ts (5)
src/core/EventBus.ts (1)
EventBus(7-44)src/client/InputHandler.ts (1)
AlternateViewEvent(74-76)src/core/game/GameView.ts (1)
tile(106-108)src/core/game/UnitImpl.ts (1)
tile(177-179)src/core/game/TrainStation.ts (1)
tile(141-143)
🔇 Additional comments (4)
src/client/graphics/GameRenderer.ts (1)
242-242: LGTM!The updated instantiation correctly passes
eventBustoRailroadLayer, matching the new constructor signature. The parameter order is consistent with other layers likeTerritoryLayer.src/client/graphics/layers/RailroadLayer.ts (3)
3-3: LGTM!Imports for
EventBusandAlternateViewEventare correctly added and used.Also applies to: 13-13
28-28: LGTM!The
alternativeViewflag is properly initialized, and the constructor correctly acceptseventBusas a parameter with automatic property assignment.Also applies to: 37-43
94-102: LGTM!The event subscription correctly updates the view state and repaints all rails on toggle. Since layers live for the entire game session, the lack of explicit cleanup is acceptable here.
evanpelle
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks!
…2626) ## Description: Adds network bright green highlighting to Railway tracks connecting _your_ factories and buildings together when in the alternate view (spacebar view). It is sometimes hard to see your own tracks on certain areas of the map (mountain terrains for example), so this change will highlight the tracks the same color as your border outline in the alternate view (#00FF00). Also suggested by [this comment](https://discord.com/channels/1284581928254701718/1445984695752855562/1445984695752855562) in the Discord. ### Normal Railway Connection <img width="1009" height="872" alt="image" src="https://github.com/user-attachments/assets/31c028a8-13d8-4d82-ba4a-385b8372c9ac" /> ### Alternative View (spacebar) <img width="1124" height="956" alt="image" src="https://github.com/user-attachments/assets/f4f3bb38-7233-4f2c-9bbf-a407196b0124" /> ### Other nation colors remain unchanged <img width="1566" height="1447" alt="image" src="https://github.com/user-attachments/assets/c4dde970-20f1-480b-959d-876d4eb0f32b" /> ## Please complete the following: - [x] I have added screenshots for all UI updates - [x] I process any text displayed to the user through translateText() and I've added it to the en.json file - [x] I have added relevant tests to the test directory - [x] I confirm I have thoroughly tested these changes and take full responsibility for any bugs introduced ## Please put your Discord username so you can be contacted if a bug or regression is found: bijx

Description:
Adds network bright green highlighting to Railway tracks connecting your factories and buildings together when in the alternate view (spacebar view). It is sometimes hard to see your own tracks on certain areas of the map (mountain terrains for example), so this change will highlight the tracks the same color as your border outline in the alternate view (#00FF00). Also suggested by this comment in the Discord.
Normal Railway Connection
Alternative View (spacebar)
Other nation colors remain unchanged
Please complete the following:
Please put your Discord username so you can be contacted if a bug or regression is found:
bijx