Skip to content

store pattern by key #1766

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

Draft
wants to merge 1 commit into
base: v25
Choose a base branch
from
Draft

store pattern by key #1766

wants to merge 1 commit into from

Conversation

evanpelle
Copy link
Collaborator

Description:

Describe the PR.

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 have read and accepted the CLA agreement (only required once).

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

DISCORD_USERNAME

Copy link
Contributor

coderabbitai bot commented Aug 9, 2025

Walkthrough

This change updates how pattern data is handled and referenced throughout the codebase. It renames properties and types related to patterns for clarity, shifts from using raw strings or arrays to structured objects and maps, and updates interfaces, schemas, and logic in both client and server code to use these new conventions. Error handling and privilege checks for patterns are also improved.

Changes

Cohort / File(s) Change Summary
Pattern Property Renaming (Client)
src/client/ClientGameRunner.ts, src/client/Main.ts, src/client/Transport.ts
Renamed pattern property to patternName in lobby config and related method calls; updated references accordingly.
Pattern Data Handling (Client)
src/client/SinglePlayerModal.ts, src/client/graphics/layers/TerritoryLayer.ts
Changed from passing or using full pattern objects to just the pattern data string; renamed local variables for clarity.
Pattern Collection Refactor
src/client/Cosmetics.ts, src/client/TerritoryPatternsModal.ts
Changed from arrays to Map<string, Pattern> for storing patterns; updated iteration and selection logic; improved error handling for pattern preview generation.
Pattern Schema and Data Types
src/core/CosmeticSchemas.ts, src/core/Schemas.ts
Renamed and exported pattern schemas; updated field and type names from pattern/PatternSchema to patternData/PatternDataSchema.
User Settings Pattern Storage
src/core/game/UserSettings.ts
Changed pattern storage from base64 string to JSON object; updated get/set methods to use pattern objects and schema validation.
Game View and Cosmetics
src/core/game/GameView.ts
Renamed pattern property to patternData in PlayerCosmetics; updated all references accordingly.
Server Pattern Handling
src/server/Client.ts, src/server/GameServer.ts, src/server/Worker.ts
Updated constructor and method parameters from pattern to patternData; improved pattern validation and connection handling.
Pattern Privilege Checking
src/server/Privilege.ts
Refactored isPatternAllowed to return a discriminated union type (PatternResult); improved pattern lookup, validation, and error reporting.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant UserSettings
    participant Server
    participant PrivilegeChecker

    Client->>UserSettings: getSelectedPattern()
    UserSettings->>UserSettings: Parse and validate pattern JSON
    UserSettings-->>Client: Pattern object or undefined

    Client->>Server: joinLobby({ patternName })
    Server->>PrivilegeChecker: isPatternAllowed(patternName, flares)
    PrivilegeChecker-->>Server: PatternResult (allowed/unknown/forbidden)
    alt allowed
        Server->>Client: Accept and assign patternData
    else forbidden
        Server->>Client: Reject with error and close connection
    else unknown
        Server->>Client: Log warning, allow without patternData
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • Patterns #1318: Also modifies TerritoryPatternsModal.ts and pattern preview logic, indicating a direct connection in pattern data handling.
  • Patterned territory #786: Introduces the original pattern property in LobbyConfig, which this PR renames and updates.
  • Refactor cosmetics.json #1263: Refactors cosmetics and pattern schema, affecting how patterns are represented and validated, directly relating to this PR’s changes.

Suggested labels

Feature - Frontend, Premium

Suggested reviewers

  • scottanderson

Poem

Patterns now have names, not just a string,
With maps and schemas, order they bring.
Privileges checked, errors handled with care,
Data is clearer everywhere!
From client to server, the journey is neat,
Patterns march forward on tidy new feet. 🧵✨

Note

🔌 MCP (Model Context Protocol) integration is now available in Early Access!

Pro users can now connect to remote MCP servers under the Integrations page to get reviews and chat conversations that understand additional development context.


📜 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 9dceac1 and f00e65a.

📒 Files selected for processing (15)
  • src/client/ClientGameRunner.ts (1 hunks)
  • src/client/Cosmetics.ts (2 hunks)
  • src/client/Main.ts (1 hunks)
  • src/client/SinglePlayerModal.ts (1 hunks)
  • src/client/TerritoryPatternsModal.ts (8 hunks)
  • src/client/Transport.ts (1 hunks)
  • src/client/graphics/layers/TerritoryLayer.ts (1 hunks)
  • src/core/CosmeticSchemas.ts (1 hunks)
  • src/core/Schemas.ts (5 hunks)
  • src/core/game/GameView.ts (3 hunks)
  • src/core/game/UserSettings.ts (2 hunks)
  • src/server/Client.ts (1 hunks)
  • src/server/GameServer.ts (1 hunks)
  • src/server/Privilege.ts (2 hunks)
  • src/server/Worker.ts (3 hunks)
✅ Files skipped from review due to trivial changes (1)
  • src/client/graphics/layers/TerritoryLayer.ts
🚧 Files skipped from review as they are similar to previous changes (14)
  • src/server/Client.ts
  • src/client/ClientGameRunner.ts
  • src/client/SinglePlayerModal.ts
  • src/core/CosmeticSchemas.ts
  • src/client/Cosmetics.ts
  • src/server/GameServer.ts
  • src/client/Transport.ts
  • src/core/game/GameView.ts
  • src/client/Main.ts
  • src/core/Schemas.ts
  • src/server/Worker.ts
  • src/core/game/UserSettings.ts
  • src/server/Privilege.ts
  • src/client/TerritoryPatternsModal.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). (2)
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: Deploy to openfront.dev

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.
  • 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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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.

@evanpelle evanpelle changed the base branch from main to v25 August 9, 2025 20:50
@evanpelle evanpelle force-pushed the evan-store-pattern-by-key branch from 9dceac1 to cb4b74b Compare August 9, 2025 20:55
@evanpelle evanpelle force-pushed the evan-store-pattern-by-key branch from cb4b74b to f00e65a Compare August 9, 2025 21:00
@@ -203,7 +203,7 @@ export const FlagSchema = z
},
{ message: "Invalid flag: must be a valid country code or start with !" },
);
export const RequiredPatternSchema = z
export const RequiredPatternDataSchema = z
Copy link
Contributor

Choose a reason for hiding this comment

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

these renames makes it hard to read the diff

@github-project-automation github-project-automation bot moved this from Triage to Development in OpenFront Release Management Aug 9, 2025
@@ -47,7 +47,7 @@ import { createRenderer, GameRenderer } from "./graphics/GameRenderer";

export interface LobbyConfig {
serverConfig: ServerConfig;
pattern: string | undefined;
patternName: string | undefined;
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you please check to make sure we're aligned on the desired outcome of #1602 ?

The conversion from pattern -> name and back only needs to happen at the localStorage boundary; everywhere else should continue to use the b64 pattern.

@scottanderson scottanderson linked an issue Aug 9, 2025 that may be closed by this pull request
@scottanderson scottanderson added this to the v26 milestone Aug 9, 2025
@scottanderson scottanderson added Premium Is or includes aspects that will be restricted to premium users. UI/UX UI/UX changes including assets, menus, QoL, etc. Feature - Frontend An entirely new feature, or changes to existing feature. User facing. labels Aug 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature - Frontend An entirely new feature, or changes to existing feature. User facing. Premium Is or includes aspects that will be restricted to premium users. UI/UX UI/UX changes including assets, menus, QoL, etc.
Projects
Status: Development
Development

Successfully merging this pull request may close these issues.

Store patterns by translation key
2 participants