Skip to content

Conversation

@bijx
Copy link
Contributor

@bijx bijx commented Dec 16, 2025

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

image

Alternative View (spacebar)

image

Other nation colors remain unchanged

image

Please complete the following:

  • I have added screenshots for all UI updates
  • I process any text displayed to the user through translateText() and I've added it to the en.json file
  • I have added relevant tests to the test directory
  • 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

@bijx bijx requested a review from a team as a code owner December 16, 2025 07:55
@CLAassistant
Copy link

CLAassistant commented Dec 16, 2025

CLA assistant check
All committers have signed the CLA.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 16, 2025

Walkthrough

EventBus 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

Cohort / File(s) Summary
RailroadLayer EventBus Integration
src/client/graphics/GameRenderer.ts, src/client/graphics/layers/RailroadLayer.ts
Constructor signature updated to accept eventBus parameter. RailroadLayer now subscribes to AlternateViewEvent during initialization. Conditional color logic added: rails owned by current user display green when alternative view is active; otherwise, normal owner color is applied.

Sequence Diagram

sequenceDiagram
    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
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Verify EventBus subscription and proper event handling in RailroadLayer constructor
  • Confirm the conditional color logic correctly identifies current user ownership and applies green override
  • Check that the alternativeView flag state is correctly maintained across repainting operations
  • Ensure no memory leaks from event subscription (consider if unsubscribe is needed on cleanup)

Possibly related PRs

Poem

🚂 The rails now listen to events on the breeze,
When worlds flip and twist, users see with ease—
Rails glow green for those whose hands guide the track,
A visual dance of control, never held back. 🟢

Pre-merge checks

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description check ✅ Passed The pull request description clearly explains the feature: adding bright green highlighting to railway tracks for the user's own factories in alternate view to improve visibility on difficult terrain. It includes relevant context, screenshots, and references to community feedback.
Title check ✅ Passed The title clearly and concisely summarizes the main change: adding green highlighting to railway tracks in alternate view for better visibility.

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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 Colord instance on each paint call:

+const ALTERNATE_VIEW_RAIL_COLOR = colord("#00ff00");
+
 export class RailroadLayer implements Layer {

Then use ALTERNATE_VIEW_RAIL_COLOR instead of colord("#00ff00"). This is a small optimization and not required.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f256f49 and c00653a.

📒 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.ts
  • src/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 eventBus to RailroadLayer, matching the new constructor signature. The parameter order is consistent with other layers like TerritoryLayer.

src/client/graphics/layers/RailroadLayer.ts (3)

3-3: LGTM!

Imports for EventBus and AlternateViewEvent are correctly added and used.

Also applies to: 13-13


28-28: LGTM!

The alternativeView flag is properly initialized, and the constructor correctly accepts eventBus as 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.

@bijx
Copy link
Contributor Author

bijx commented Dec 16, 2025

Another screenshot to show the better contrast now even in cold terrains:

image

@bijx bijx changed the title Factory Railway Tracks become more visible in Alternate View feat: Factory Railway Tracks become more visible in Alternate View Dec 16, 2025
Copy link
Collaborator

@evanpelle evanpelle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks!

@evanpelle evanpelle merged commit c9f00a5 into openfrontio:main Dec 18, 2025
6 of 7 checks passed
evanpelle pushed a commit that referenced this pull request Dec 23, 2025
…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
@evanpelle evanpelle added this to the v29 milestone Jan 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants