-
Notifications
You must be signed in to change notification settings - Fork 705
Tint territory borders based on player relationships. #2439
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
base: main
Are you sure you want to change the base?
Conversation
- Pre-compute border color variants (neutral, friendly, embargo) per player - Tint borders based on neighbor relationships (embargo → red, friendly → green) - Apply tinting before theme checkerboard for defended borders - Simplify border color selection logic
WalkthroughPlayerView's border color logic now considers neighbor relationships. The changes introduce pre-computed color variants for Neutral, Friendly, and Embargo states, plus separate defended variants. The borderColor() method dynamically selects colors based on whether neighbors have embargo or friendly relations, then applies appropriate defended tinting when needed. Changes
Sequence Diagram(s)sequenceDiagram
participant Caller
participant borderColor as borderColor(tile, isDefended)
participant neighbors as Neighbor Check
participant colorSelect as Color Selection
Caller->>borderColor: Request border color
borderColor->>borderColor: tile === undefined?
alt Tile Undefined
borderColor-->>Caller: Return base border color
else Tile Defined
borderColor->>neighbors: Check tile neighbors
neighbors-->>borderColor: Relations identified
borderColor->>colorSelect: Embargo relation found?
alt Embargo Relation
colorSelect-->>borderColor: Use Embargo colors
else Friendly Relation
colorSelect-->>borderColor: Use Friendly colors
else Neutral
colorSelect-->>borderColor: Use Neutral colors
end
borderColor->>borderColor: isDefended?
alt Not Defended
borderColor-->>Caller: Return base color
else Defended
borderColor->>borderColor: Check light/dark pattern
borderColor-->>Caller: Return appropriate defended variant
end
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes
Possibly related issues
Suggested reviewers
Poem
Pre-merge checks✅ Passed checks (3 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/core/game/GameView.ts (1)
262-293: Extract duplicated tinting formula into a helper function.The color tinting formula is duplicated for friendly (lines 262-276) and embargo (lines 279-293). Consider extracting into a helper:
function applyTint(base: Colord, target: {r: number, g: number, b: number}, ratio: number): Colord { const baseRgb = base.toRgb(); return colord({ r: Math.round(baseRgb.r * (1 - ratio) + target.r * ratio), g: Math.round(baseRgb.g * (1 - ratio) + target.g * ratio), b: Math.round(baseRgb.b * (1 - ratio) + target.b * ratio), a: baseRgb.a, }); }Then use it:
this._borderColorFriendly = applyTint(this._borderColor, FRIENDLY_TINT_TARGET, BORDER_TINT_RATIO); this._borderColorEmbargo = applyTint(this._borderColor, EMBARGO_TINT_TARGET, BORDER_TINT_RATIO);
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/core/game/GameView.ts(4 hunks)
🧰 Additional context used
🧠 Learnings (5)
📓 Common learnings
Learnt from: Ble4Ch
Repo: openfrontio/OpenFrontIO PR: 1063
File: src/core/configuration/Colors.ts:114-330
Timestamp: 2025-06-06T15:36:31.739Z
Learning: In the OpenFrontIO project, color improvements are implemented incrementally. The current focus for player colors is ensuring sufficient unique color availability rather than optimizing for visual distinction or accessibility features.
📚 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/core/game/GameView.ts
📚 Learning: 2025-10-26T15:37:07.732Z
Learnt from: GlacialDrift
Repo: openfrontio/OpenFrontIO PR: 2298
File: src/client/graphics/layers/TerritoryLayer.ts:200-210
Timestamp: 2025-10-26T15:37:07.732Z
Learning: In GameImpl.ts lines 124-139, team assignment logic varies by number of teams: when numPlayerTeams < 8, teams are assigned ColoredTeams values (Red, Blue, Yellow, Green, Purple, Orange, Teal); when numPlayerTeams >= 8, teams are assigned generic string identifiers like "Team 1", "Team 2", etc., which are not members of ColoredTeams.
Applied to files:
src/core/game/GameView.ts
📚 Learning: 2025-06-06T15:36:31.739Z
Learnt from: Ble4Ch
Repo: openfrontio/OpenFrontIO PR: 1063
File: src/core/configuration/Colors.ts:114-330
Timestamp: 2025-06-06T15:36:31.739Z
Learning: In the OpenFrontIO project, color improvements are implemented incrementally. The current focus for player colors is ensuring sufficient unique color availability rather than optimizing for visual distinction or accessibility features.
Applied to files:
src/core/game/GameView.ts
📚 Learning: 2025-06-22T21:51:14.990Z
Learnt from: devalnor
Repo: openfrontio/OpenFrontIO PR: 1248
File: src/client/graphics/layers/TerritoryInfoLayer.ts:20-20
Timestamp: 2025-06-22T21:51:14.990Z
Learning: In TerritoryInfoLayer.ts, the highlightedTerritory field uses both null and undefined intentionally: undefined represents initial state or inactive layer (Ctrl released), while null represents active layer with no territory being highlighted at cursor position. This distinction is important for proper state change detection.
Applied to files:
src/core/game/GameView.ts
🧬 Code graph analysis (1)
src/core/game/GameView.ts (3)
src/core/configuration/DefaultConfig.ts (1)
theme(637-641)src/core/game/GameMap.ts (3)
TileRef(3-3)x(122-124)y(126-128)src/core/game/GameImpl.ts (2)
x(798-800)y(801-803)
🔇 Additional comments (3)
src/core/game/GameView.ts (3)
44-46: LGTM - Clear tinting constants.The 35% blend ratio provides visual distinction while preserving the base border color identity.
192-198: LGTM - Pre-computed variants improve performance.Storing all color variants upfront avoids repeated computation during rendering.
323-380: LGTM - Relationship-based border tinting logic is correct.The implementation correctly:
- Prioritizes embargo over friendly (line 349 breaks early)
- Checks both directions for friendly relationships (line 352) to handle non-symmetric alliances during transitions
- Applies type narrowing safely (line 343)
- Handles edge cases (no neighbors → neutral colors)
- Uses standard checkerboard pattern for defended borders
|
should I review this or wait for the webgl version? |
|
Depends, do you want to keep the non-webgl renderer? do we need a fallback? |
Description:
Add visual indicators to territory borders that reflect diplomatic relationships between players, making it easier to identify relations at a glance.
Problem Statement
Currently, players must check diplomatic status through other UI elements. There's no immediate visual feedback on the map showing which borders represent embargo or friendly relationships.
Benefits
Proposed Solution
Tint territory borders based on neighbor relationships: embargo red, friendly green
Implementation Details
Please complete the following: