Skip to content

Players on the same team get a distinct color based on the team color - #1297

Merged
scottanderson merged 18 commits into
openfrontio:v0.25.xfrom
sidneyprins:new-colors
Jul 25, 2025
Merged

scottanderson merged 18 commits into
openfrontio:v0.25.xfrom
sidneyprins:new-colors

Conversation

@sidneyprins

@sidneyprins sidneyprins commented Jun 28, 2025 •

Copy link
Copy Markdown
Contributor

Description:

Instead of all teams having the same color, they get a different color.

2 teams

blue-red

All teams

all-teams

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
  • I understand that submitting code with bugs that could have been caught through manual testing blocks releases and new features for all contributors

Please put your Discord username so you can be contacted if a bug or regression is found:

pineappleprince

@coderabbitai

coderabbitai Bot commented Jun 28, 2025 •

Copy link
Copy Markdown
Contributor

Walkthrough

The 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

File(s) Change Summary
src/core/configuration/Colors.ts Changed base team colors from RGB to HSL; added function to generate 64 color variations per team; added arrays for team color palettes.
src/core/configuration/ColorAllocator.ts Refactored to use arrays of team colors; added caching and hashing to assign unique colors per player within a team.
src/core/configuration/PastelTheme.ts
src/core/configuration/PastelThemeDark.ts
Updated territoryColor method to assign colors per player using new allocator method.
tests/Colors.test.ts Expanded tests to cover all team colors and verify per-player color assignment consistency and uniqueness.

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
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~7 minutes

Possibly related PRs

Suggested reviewers

  • evanpelle
  • scottanderson

Poem

🎨
Sixty-four shades for every team,
No more just red or blue,
Each player shines with their own gleam—
A palette fresh and new!
Colors dance and colors play,
In code, the rainbow leads the way.
🌈

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

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

npm error Exit handler never called!
npm error This is an error with npm itself. Please report this error at:
npm error https://github.com/npm/cli/issues
npm error A complete log of this run can be found in: /.npm/_logs/2025-07-25T17_07_28_938Z-debug-0.log

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 92ddbb6 and 685e160.

📒 Files selected for processing (1)
  • src/core/configuration/Colors.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/core/configuration/Colors.ts
⏰ 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)
  • GitHub Check: 🏗️ Build

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need 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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@sidneyprins
sidneyprins marked this pull request as ready for review June 29, 2025 07:59
@sidneyprins
sidneyprins requested a review from a team as a code owner June 29, 2025 07:59
@sidneyprins
sidneyprins requested a review from evanpelle June 29, 2025 07:59
Comment thread src/core/configuration/Config.ts Resolved
Comment thread src/core/configuration/Colors.ts Resolved
@evanpelle evanpelle added this to the v24 milestone Jul 2, 2025
Comment thread src/core/configuration/Colors.ts Resolved
Comment thread src/core/configuration/PastelTheme.ts Resolved
Comment thread src/core/configuration/Colors.ts Resolved
Comment thread tests/Colors.test.ts Resolved

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.min is 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 getTeamColorVariations method 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

📥 Commits

Reviewing files that changed from the base of the PR and between d81b184 and 603fbdc.

📒 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 simpleHash import 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 teamPlayerColors map 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.

Comment thread src/core/configuration/Colors.ts Resolved
@github-project-automation github-project-automation Bot moved this from Triage to Development in OpenFront Release Management Jul 3, 2025
@sidneyprins
sidneyprins requested a review from scottanderson July 4, 2025 16:07
@huntergregal

Copy link
Copy Markdown

Could also make multiple clients using the same IP address have same color as well.

@CLAassistant

CLAassistant commented Jul 16, 2025 •

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
0 out of 3 committers have signed the CLA.

❌ drillskibo
❌ scottanderson
❌ sidneyprins
You have signed the CLA already but the status is still pending? Let us recheck it.

@drillskibo

Copy link
Copy Markdown
Contributor

What is the state of this PR now that v24 is about to be released?
Is there still an issue to work on here? Are there blockers?

What about the changes that were requested?
@evanpelle @scottanderson at first glance it seems like requested changes have been put in place, can you confirm and give it another pass?

@drillskibo drillskibo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

@sidneyprins
sidneyprins requested a review from a team as a code owner July 24, 2025 18:00
@sidneyprins

Copy link
Copy Markdown
Contributor Author

@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 scottanderson left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I see that you clicked resolve, but my comment has not been addressed.

@sidneyprins

Copy link
Copy Markdown
Contributor Author

@scottanderson please let me know if it's good now, see my comment on the marked change

@github-project-automation github-project-automation Bot moved this from Development to Final Review in OpenFront Release Management Jul 25, 2025
@scottanderson
scottanderson changed the base branch from main to v0.25.x July 25, 2025 22:50
@scottanderson
scottanderson requested a review from a team as a code owner July 25, 2025 22:50
@scottanderson
scottanderson merged commit 79c638c into openfrontio:v0.25.x Jul 25, 2025
@github-project-automation github-project-automation Bot moved this from Final Review to Complete in OpenFront Release Management Jul 25, 2025
@scottanderson scottanderson added Feature - Frontend UI/UX UI/UX changes including assets, menus, QoL, etc. labels Jul 25, 2025
@coderabbitai coderabbitai Bot mentioned this pull request Aug 27, 2025
4 tasks done
@coderabbitai coderabbitai Bot mentioned this pull request Oct 22, 2025
4 tasks done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

UI/UX UI/UX changes including assets, menus, QoL, etc.

Projects

Status: Complete

Development

Successfully merging this pull request may close these issues.

6 participants