Skip to content

Add setting for automatically setting "Stop Trading with all setting" for team games#3315

Open
DeLoWaN wants to merge 3 commits intoopenfrontio:mainfrom
DeLoWaN:trading-with-all-setting
Open

Add setting for automatically setting "Stop Trading with all setting" for team games#3315
DeLoWaN wants to merge 3 commits intoopenfrontio:mainfrom
DeLoWaN:trading-with-all-setting

Conversation

@DeLoWaN
Copy link

@DeLoWaN DeLoWaN commented Mar 1, 2026

Description:

In most team games (at least in clans), we disable the trade with all right from the start. This PR introduces a setting that automatically disables trade with all at the beginning of the game for team games only.

The default is unchanged (so trade with all is enabled).

I was also considering setting “stop trade with all” as the default option. If it was up to me I would make stop trading with all the default and I would only manually activate it in specific situations, such as when playing a game with random spawns.

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:

.delovan

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 1, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between dd3c62a and 31a48e2.

📒 Files selected for processing (2)
  • resources/lang/en.json
  • src/client/UserSettingModal.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • resources/lang/en.json
  • src/client/UserSettingModal.ts

Walkthrough

Adds a user setting, UI toggle, localization entries, and client-side game logic that schedules and emits a "Stop Trading with All" embargo automatically at team game start when enabled.

Changes

Cohort / File(s) Summary
Localization
resources/lang/en.json
Added two i18n keys under user_setting: team_stop_trade_all_label and team_stop_trade_all_desc.
Settings Storage
src/core/game/UserSettings.ts
Added stopTradingAllAtStartForTeamGames() getter and setStopTradingAllAtStartForTeamGames(enabled) setter to persist the toggle in localStorage and emit change notifications.
User Interface
src/client/UserSettingModal.ts
Added a private handler to toggle the new setting and injected a new UI toggle into basic settings, initialized from userSettings.
Game Execution
src/client/ClientGameRunner.ts
Extended constructor to accept userSettings; added embargo scheduling state (startTradeEmbargoAtTick, startTradeEmbargoApplied, startTradeModeInitialized); on team game start, lazily schedule embargo (current tick + cooldown) and emit SendEmbargoAllIntentEvent("start") when reached; reset flags on stop.

Sequence Diagram

sequenceDiagram
    participant User
    participant Modal as UserSettingModal
    participant Settings as UserSettings
    participant GameRunner as ClientGameRunner
    participant Game as Game Engine

    User->>Modal: Toggle "Stop Trading with All (Team Games Only)"
    Modal->>Settings: setStopTradingAllAtStartForTeamGames(enabled)
    Settings->>Settings: Write to localStorage
    Settings->>Modal: Emit change notification
    Modal->>Modal: requestUpdate()

    rect rgba(100, 150, 200, 0.5)
    Note over User,Game: Later: Team Game Starts
    Game->>GameRunner: game.start()
    GameRunner->>Settings: stopTradingAllAtStartForTeamGames()
    Settings-->>GameRunner: enabled boolean

    alt Setting enabled AND Team mode
        GameRunner->>GameRunner: Calculate embargo tick (current tick + cooldown)
        GameRunner->>GameRunner: Mark initialized
    end
    end

    rect rgba(100, 150, 200, 0.5)
    Note over GameRunner,Game: During Game Loop
    GameRunner->>GameRunner: Check if current tick reached embargo tick

    alt Tick reached
        GameRunner->>Game: Emit SendEmbargoAllIntentEvent("start")
        GameRunner->>GameRunner: Mark applied & clear tick
    end
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🤝 A toggle set for teammates near,
When team games start, trades disappear,
From modal flip to stored delight,
The runner waits for the right tick's light,
Embargo sent — fair play in sight.

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ 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%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: adding a setting to automatically enable 'Stop Trading with All' for team games.
Description check ✅ Passed The description is clearly related to the changeset, explaining the motivation for the setting, its scope, default behavior, and including UI screenshots and testing confirmation.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

Tip

Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs).
Share your feedback on Discord.


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.

🧹 Nitpick comments (2)
docs/plans/2026-02-14-starting-trade-mode-design.md (1)

31-31: Remove absolute paths from documentation.

The file contains machine-specific paths like /Users/damien/git_perso/OpenFrontIO/.... Use relative paths from the repository root (e.g., src/client/UserSettingModal.ts) for portability.

This applies to lines 31, 53, 75, and 140-143.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@docs/plans/2026-02-14-starting-trade-mode-design.md` at line 31, Remove
machine-specific absolute paths in the document and replace them with
repository-relative paths; for each occurrence of
"/Users/damien/git_perso/OpenFrontIO/src/client/UserSettingModal.ts" (notably
the occurrences reported at lines 31, 53, 75, and 140-143) change them to the
relative path "src/client/UserSettingModal.ts" (or a path relative to the repo
root used elsewhere), and ensure any other absolute paths in this document
follow the same replacement so the doc contains no user-specific file system
references.
docs/plans/2026-02-14-starting-trade-mode-implementation.md (1)

98-158: Test files mentioned do not exist in this PR.

The plan references several test files:

  • tests/core/game/UserSettings.startingTradeMode.test.ts
  • tests/client/UserSettingModal.startingTradeMode.test.ts
  • tests/client/utilities/StartingTradeModeController.test.ts

The PR description notes that tests have not been added yet. Consider adding tests or creating issues to track this work.

Do you want me to help draft test cases for the implemented behavior?

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@docs/plans/2026-02-14-starting-trade-mode-implementation.md` around lines 98
- 158, The PR references test files that are not present; add the missing tests
or track them as issues so CI and reviewers know expected coverage. Create the
three tests mentioned (tests/core/game/UserSettings.startingTradeMode.test.ts,
tests/client/UserSettingModal.startingTradeMode.test.ts,
tests/client/utilities/StartingTradeModeController.test.ts) that assert the new
starting trade mode behavior (unit tests for UserSettings API, integration for
UserSettingModal UI and controller utilities), or alternatively open issue(s)
linking the new feature to the absent tests; ensure tests exercise the
UserSettingModal.renderBasicSettings addition, the setStartingTradeMode method
on UserSettingModal, and the persistence key settings.startingTradeMode, and
include the four i18n keys added to resources/lang/en.json so localization is
validated.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@docs/plans/2026-02-14-starting-trade-mode-design.md`:
- Line 31: Remove machine-specific absolute paths in the document and replace
them with repository-relative paths; for each occurrence of
"/Users/damien/git_perso/OpenFrontIO/src/client/UserSettingModal.ts" (notably
the occurrences reported at lines 31, 53, 75, and 140-143) change them to the
relative path "src/client/UserSettingModal.ts" (or a path relative to the repo
root used elsewhere), and ensure any other absolute paths in this document
follow the same replacement so the doc contains no user-specific file system
references.

In `@docs/plans/2026-02-14-starting-trade-mode-implementation.md`:
- Around line 98-158: The PR references test files that are not present; add the
missing tests or track them as issues so CI and reviewers know expected
coverage. Create the three tests mentioned
(tests/core/game/UserSettings.startingTradeMode.test.ts,
tests/client/UserSettingModal.startingTradeMode.test.ts,
tests/client/utilities/StartingTradeModeController.test.ts) that assert the new
starting trade mode behavior (unit tests for UserSettings API, integration for
UserSettingModal UI and controller utilities), or alternatively open issue(s)
linking the new feature to the absent tests; ensure tests exercise the
UserSettingModal.renderBasicSettings addition, the setStartingTradeMode method
on UserSettingModal, and the persistence key settings.startingTradeMode, and
include the four i18n keys added to resources/lang/en.json so localization is
validated.

ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 802cc7f and 75faaa9.

📒 Files selected for processing (6)
  • docs/plans/2026-02-14-starting-trade-mode-design.md
  • docs/plans/2026-02-14-starting-trade-mode-implementation.md
  • resources/lang/en.json
  • src/client/ClientGameRunner.ts
  • src/client/UserSettingModal.ts
  • src/core/game/UserSettings.ts

coderabbitai[bot]
coderabbitai bot previously approved these changes Mar 1, 2026
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: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/client/ClientGameRunner.ts`:
- Around line 411-423: The current block that sets startTradeModeInitialized and
schedules startTradeEmbargoAtTick uses
userSettings.stopTradingAllAtStartForTeamGames() without checking replay mode,
so viewers of replays may incorrectly schedule an embargo; update the logic in
ClientGameRunner (the block using startTradeModeInitialized,
startTradeEmbargoAtTick, gameView, and
userSettings.stopTradingAllAtStartForTeamGames()) to early-return or skip
scheduling when the view is a replay (e.g., check gameView.isReplay() or
equivalent) so embargo intents are only set during live games, not while
watching replays.

ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 75faaa9 and cfd55e4.

📒 Files selected for processing (4)
  • resources/lang/en.json
  • src/client/ClientGameRunner.ts
  • src/client/UserSettingModal.ts
  • src/core/game/UserSettings.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/client/UserSettingModal.ts
  • resources/lang/en.json

@github-project-automation github-project-automation bot moved this from Triage to Development in OpenFront Release Management Mar 1, 2026
@iiamlewis iiamlewis added this to the v31 milestone Mar 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: Development

Development

Successfully merging this pull request may close these issues.

3 participants