Repository navigation
Players on the same team get a distinct color based on the team color - #1297
Conversation
WalkthroughThe changes introduce a new system for team color management by generating 64 color variations for each team instead of using single static colors. Color assignment for players within teams is now deterministic and unique per player, using a hash of the player ID. Theme classes are updated to use this new color allocation logic, and tests are expanded accordingly. Changes
Sequence Diagram(s)sequenceDiagram
participant ThemeClass
participant ColorAllocator
participant Colors
participant Player
ThemeClass->>Player: Get team and player ID
ThemeClass->>ColorAllocator: assignTeamPlayerColor(team, playerId)
ColorAllocator->>Colors: Get team color variations
ColorAllocator->>ColorAllocator: Hash playerId, select color
ColorAllocator-->>ThemeClass: Return assigned color
Estimated code review effort🎯 2 (Simple) | ⏱️ ~7 minutes Possibly related PRs
Suggested reviewers
Poem
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
npm error Exit handler never called! Note ⚡️ Unit Test Generation is now available in beta!Learn more here, or try it out under "Finishing Touches" below. 📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
…mColor cannot be found so we have that transparent.
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (2)
src/core/configuration/Colors.ts (2)
334-382: Color generation logic is solid with room for enhancement.The function correctly generates 64 color variations using intensity and lightness adjustments. The RGB value bounding with
Math.minis appropriate.Consider enhancing color variety for darker base colors by using both additive and subtractive lightness adjustments:
if (group === 0) { // Pure vibrant colors: base color with moderate lightness (16 colors) - const lightness = indexInGroup * 10; + const lightness = indexInGroup < 8 ? indexInGroup * 10 : -(indexInGroup - 8) * 10; return colord({ - r: Math.min(255, baseColorRed + lightness), - g: Math.min(255, baseColorGreen + lightness), - b: Math.min(255, baseColorBlue + lightness), + r: Math.max(0, Math.min(255, baseColorRed + lightness)), + g: Math.max(0, Math.min(255, baseColorGreen + lightness)), + b: Math.max(0, Math.min(255, baseColorBlue + lightness)), }); }This would create both lighter and darker variations, providing better visual distinction.
420-441: Method implementation is correct with minor enhancement opportunity.The
getTeamColorVariationsmethod provides a clean interface for retrieving team color palettes.Consider making the error message more descriptive:
default: - throw new Error(`Unknown team color: ${team}`); + throw new Error(`Unknown team color: ${team}. Valid teams are: ${Object.values(ColoredTeams).join(', ')}`);This would help with debugging invalid team assignments.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
src/core/configuration/Colors.ts(3 hunks)tests/Colors.test.ts(2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- tests/Colors.test.ts
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: Ble4Ch
PR: openfrontio/OpenFrontIO#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.
Learnt from: Ble4Ch
PR: openfrontio/OpenFrontIO#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.
Learnt from: andrewNiziolek
PR: openfrontio/OpenFrontIO#1007
File: resources/lang/de.json:115-115
Timestamp: 2025-06-02T14:27:37.609Z
Learning: For OpenFrontIO project: When localization keys are renamed in language JSON files, the maintainers separate technical changes from translation content updates. They wait for community translators to update the actual translation values rather than attempting to translate in the same PR. This allows technical changes to proceed while ensuring accurate translations from native speakers.
Learnt from: Ble4Ch
PR: openfrontio/OpenFrontIO#1063
File: src/core/configuration/Colors.ts:398-411
Timestamp: 2025-06-06T21:43:15.706Z
Learning: In ColorAllocator class, the assignPlayerColor method intentionally allows color duplicates when the humanColors palette is exhausted by resetting availableColors to the full humanColors array. This is done on purpose as an acceptable temporary limitation, with potential palette improvements planned for later.
Learnt from: Ble4Ch
PR: openfrontio/OpenFrontIO#1063
File: src/core/configuration/PastelThemeDark.ts:20-21
Timestamp: 2025-06-06T15:42:21.903Z
Learning: In ColorAllocator class, all methods (assignBotColor, assignPlayerColor, assignTeamColor) use the constructor colors from this.availableColors. Only the predefined team cases in assignTeamColor use hardcoded global colors, while the default case uses constructor colors.
src/core/configuration/Colors.ts (7)
Learnt from: Ble4Ch
PR: openfrontio/OpenFrontIO#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.
Learnt from: Ble4Ch
PR: openfrontio/OpenFrontIO#1063
File: src/core/configuration/PastelThemeDark.ts:20-21
Timestamp: 2025-06-06T15:42:21.903Z
Learning: In ColorAllocator class, all methods (assignBotColor, assignPlayerColor, assignTeamColor) use the constructor colors from this.availableColors. Only the predefined team cases in assignTeamColor use hardcoded global colors, while the default case uses constructor colors.
Learnt from: Ble4Ch
PR: openfrontio/OpenFrontIO#1063
File: src/core/configuration/Colors.ts:398-411
Timestamp: 2025-06-06T21:43:15.706Z
Learning: In ColorAllocator class, the assignPlayerColor method intentionally allows color duplicates when the humanColors palette is exhausted by resetting availableColors to the full humanColors array. This is done on purpose as an acceptable temporary limitation, with potential palette improvements planned for later.
Learnt from: Ble4Ch
PR: openfrontio/OpenFrontIO#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.
Learnt from: scottanderson
PR: openfrontio/OpenFrontIO#992
File: src/core/configuration/DefaultConfig.ts:0-0
Timestamp: 2025-06-01T04:56:16.870Z
Learning: In the OpenFrontIO codebase, the number of player teams (`numPlayerTeams`) will never be higher than the minimum team size, so the modulo operation in `lobbyMaxPlayers()` will not result in zero players.
Learnt from: El-Magico777
PR: openfrontio/OpenFrontIO#1166
File: src/core/Schemas.ts:50-56
Timestamp: 2025-06-13T20:57:49.599Z
Learning: In the OpenFrontIO codebase, player identification primarily uses numeric smallIDs throughout the system (e.g., playerBySmallID). When adding new intents or schemas, maintain consistency with this existing pattern rather than introducing mixed ID types, even if string IDs might be more standard elsewhere.
Learnt from: devalnor
PR: openfrontio/OpenFrontIO#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.
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: 🏗️ Build
🔇 Additional comments (5)
src/core/configuration/Colors.ts (5)
6-7: Import addition looks good.The
simpleHashimport is correctly added and necessary for the player color assignment functionality.
384-408: Team color definitions are well-structured.The approach of defining base colors and generating variations is clean and maintainable. The special handling for bot team colors (single color) is appropriate.
413-413: Cache addition improves performance.The
teamPlayerColorsmap correctly caches player color assignments, addressing the hot path optimization mentioned in previous reviews.
474-477: Simplified team color assignment is appropriate.The method correctly returns the first color from the team's palette, which serves as the base team color.
334-496: Excellent implementation of team-based player color assignment.This implementation successfully addresses the PR objective by:
- Generating 64 distinct color variations per team
- Providing consistent color assignment for players using hash-based selection
- Implementing proper caching for performance optimization
- Maintaining clean TypeScript code with good separation of concerns
The approach aligns well with the project's incremental color improvement strategy and addresses the hot path optimization concerns from previous reviews.
|
Could also make multiple clients using the same IP address have same color as well. |
|
|
|
What is the state of this PR now that v24 is about to be released? What about the changes that were requested? |
drillskibo
left a comment
There was a problem hiding this comment.
In terms of functionality, can we use hsl() or lch() instead of this complicated rbg math?
Can we simplify the variance so that it just changes the hue slightly, or the saturation, or using the lch ?
colord supports these calculations that would just need a +- small random value to reach the same effectiveness.
|
@scottanderson Sorry for some of the lack-of-quality changes such as the colors which I wanted to keep in an original state but ultimately did not keep. I will keep a better eye for such things in future Everything should be ok now :-) |
scottanderson
left a comment
There was a problem hiding this comment.
I see that you clicked resolve, but my comment has not been addressed.
|
@scottanderson please let me know if it's good now, see my comment on the marked change |
Description:
Instead of all teams having the same color, they get a different color.
2 teams
All teams
Please complete the following:
Please put your Discord username so you can be contacted if a bug or regression is found:
pineappleprince