Skip to content

Make setting for go to player on spawn (default on)#3874

Open
frederikja163 wants to merge 4 commits intoopenfrontio:mainfrom
frederikja163:optional-go-to-player-on-spawn
Open

Make setting for go to player on spawn (default on)#3874
frederikja163 wants to merge 4 commits intoopenfrontio:mainfrom
frederikja163:optional-go-to-player-on-spawn

Conversation

@frederikja163
Copy link
Copy Markdown

If this PR fixes an issue, link it below. If not, delete these two lines.
Resolves #3847

Description:

Makes a setting to turn off go to player on spawn.

Most players i have played with are really annoyed about this feature. I understand that some people like it, which is why i have made it default on. But i feel like we should be able to turn it off.

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:

FrederikJA

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 6, 2026

Review Change Stack
No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 9d98e2e2-5028-42be-b612-0bc5349c45cc

📥 Commits

Reviewing files that changed from the base of the PR and between 365a018 and 5235b30.

📒 Files selected for processing (1)
  • src/client/ClientGameRunner.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/client/ClientGameRunner.ts

Walkthrough

Adds a persisted user setting and UI toggle to control whether the client camera auto-zooms to the player on game start. UserSettings exposes the flag and a toggle, two i18n strings were added, the settings modal exposes the toggle, and ClientGameRunner checks the flag when handling the first turn to decide whether to emit the initial GoToPlayerEvent.

Changes

Go-to-Player Toggle Setting

Layer / File(s) Summary
Data Shape / i18n
src/core/game/UserSettings.ts, resources/lang/en.json
Adds goToPlayer() (default true) and toggleGoToPlayer() to persisted settings; adds user_setting.go_to_player_label and user_setting.go_to_player_desc localization keys.
UI Wiring
src/client/UserSettingModal.ts
Inserts a "Go to player" Basic settings setting-toggle bound to userSettings.goToPlayer() and adds a private toggleGoToPlayer() handler that calls userSettings.toggleGoToPlayer() and logs the new state.
Client Runner
src/client/ClientGameRunner.ts
createClientGame now passes userSettings into ClientGameRunner; constructor stores private userSettings: UserSettings; "turn" message handling requires this.userSettings.goToPlayer() (in addition to existing checks) before emitting GoToPlayerEvent for the first eligible turn.

Sequence Diagram

sequenceDiagram
    actor Player
    participant Modal as UserSettingModal
    participant Settings as UserSettings
    participant Runner as ClientGameRunner
    participant Game as GameEngine

    Player->>Modal: Toggle "Go to player"
    Modal->>Settings: toggleGoToPlayer()
    Settings->>Settings: Flip goToPlayer state

    Note over Player,Game: Game starts / turn arrives
    Game->>Runner: "turn" message
    Runner->>Settings: goToPlayer()
    Settings-->>Runner: true / false
    alt goToPlayer() is true
        Runner->>Game: Emit GoToPlayerEvent
        Game->>Game: Zoom to player
    else
        Note over Game: Skip initial zoom
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

A tiny switch to calm the view,
Saved in settings, labeled true,
Modal flips it, runner reads,
Zoom on spawn will heed those deeds,
Gentle starts for players new.

🚥 Pre-merge checks | ✅ 4 | ❌ 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 (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main change: adding a user setting to control go-to-player behavior on spawn with default enabled.
Description check ✅ Passed The description is related to the changeset and explains the motivation: making the go-to-player feature toggleable while defaulting it on.
Linked Issues check ✅ Passed The PR successfully implements the requested feature from issue #3847: provides a user setting to turn off zoom-to-player on spawn while keeping it enabled by default.
Out of Scope Changes check ✅ Passed All changes are scoped to the feature: i18n keys, UserSettings accessor/toggle, UI toggle in UserSettingModal, and integration into ClientGameRunner.

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

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


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
Copy Markdown
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: 3

🧹 Nitpick comments (1)
src/core/game/UserSettings.ts (1)

232-234: 💤 Low value

Consider adding tests per the src/core/ guideline.

The coding guideline requires tests for all src/core/ changes. While no existing UserSettings methods have tests, this PR is a good opportunity to add a small suite covering goToPlayer() default and toggleGoToPlayer() round-trip.

As per coding guidelines: "All changes to src/core/ must include tests."

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/core/game/UserSettings.ts` around lines 232 - 234, Add unit tests for
UserSettings covering the default value of goToPlayer() and that
toggleGoToPlayer() flips the setting and can be toggled back (round-trip);
specifically, create tests that instantiate UserSettings, assert goToPlayer()
default state, call toggleGoToPlayer(), assert the inverted state, call
toggleGoToPlayer() again and assert it returned to the original state, and
include any necessary setup/teardown to isolate state so these tests live
alongside other src/core tests.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/client/ClientGameRunner.ts`:
- Line 457: The logic is inverted: hasGoneToPlayer is intended to mean "the
zoom-to-player action has already happened" but it's initialized directly from
this.userSettings.goToPlayer(), causing the feature to behave backwards; change
the initialization so hasGoneToPlayer is the negation of the user preference
(i.e., set hasGoneToPlayer = !this.userSettings.goToPlayer()) so the guard that
emits GoToPlayerEvent (which checks !hasGoneToPlayer) correctly triggers when
the user enables goToPlayer(); update the initialization near ClientGameRunner's
hasGoneToPlayer declaration accordingly.

In `@src/client/UserSettingModal.ts`:
- Line 849: The second toggle input in the UserSettingModal component reuses
id="territory-patterns-toggle", causing duplicate DOM IDs; update that input's
id to a unique value (e.g., "territory-patterns-toggle-advanced" or similar)
wherever the toggle is rendered (look for the input/label within
UserSettingModal and any helper like renderToggle) and also update any
corresponding label htmlFor attributes and any JS/CSS selectors or tests that
reference the old id so they point to the new unique id.
- Line 851: The template currently calls this.userSettings.toggleGoToPlayer()
during render, causing the setting to flip on every render; change the binding
to pass a function reference instead of invoking it — either add a private
wrapper on the component (e.g. _onToggleGoToPlayer that calls
this.userSettings.toggleGoToPlayer()) and use that in the template, or pass the
method reference/arrow handler (e.g. this.userSettings.toggleGoToPlayer or an
inline () => this.userSettings.toggleGoToPlayer()), mirroring how the other
toggles in UserSettingModal use bound method references.

---

Nitpick comments:
In `@src/core/game/UserSettings.ts`:
- Around line 232-234: Add unit tests for UserSettings covering the default
value of goToPlayer() and that toggleGoToPlayer() flips the setting and can be
toggled back (round-trip); specifically, create tests that instantiate
UserSettings, assert goToPlayer() default state, call toggleGoToPlayer(), assert
the inverted state, call toggleGoToPlayer() again and assert it returned to the
original state, and include any necessary setup/teardown to isolate state so
these tests live alongside other src/core tests.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 5f759a1e-77e7-4bca-9415-62f69164ed31

📥 Commits

Reviewing files that changed from the base of the PR and between 005e1b6 and 4d68986.

📒 Files selected for processing (4)
  • resources/lang/en.json
  • src/client/ClientGameRunner.ts
  • src/client/UserSettingModal.ts
  • src/core/game/UserSettings.ts

Comment thread src/client/ClientGameRunner.ts Outdated
Comment thread src/client/UserSettingModal.ts Outdated
Comment thread src/client/UserSettingModal.ts Outdated
@github-project-automation github-project-automation Bot moved this from Triage to Development in OpenFront Release Management May 6, 2026
Copy link
Copy Markdown
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.

♻️ Duplicate comments (1)
src/client/UserSettingModal.ts (1)

851-851: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Create a local wrapper method for the "Go to Player" toggle to match the established pattern.

At line 851, @change=${this.userSettings.toggleGoToPlayer} passes an unbound method reference. This will lose its this context at runtime and break the toggle. Every other toggle handler in this component (dark mode, emojis, alert frame, fx layer, etc.) uses a local wrapper method. Add the same wrapper pattern here:

+  private toggleGoToPlayer() {
+    this.userSettings.toggleGoToPlayer();
+  }
+
   private togglePerformanceOverlay() {
     this.userSettings.togglePerformanceOverlay();
   }

Then bind it in the template:

-        `@change`=${this.userSettings.toggleGoToPlayer}
+        `@change`=${this.toggleGoToPlayer}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/client/UserSettingModal.ts` at line 851, The template currently passes an
unbound method reference this.userSettings.toggleGoToPlayer which will lose its
this context; create a local wrapper method onToggleGoToPlayer(event) on the
UserSettingModal class that calls this.userSettings.toggleGoToPlayer(event) (or
forwards any needed args) and then change the template binding from
`@change`=${this.userSettings.toggleGoToPlayer} to
`@change`=${this.onToggleGoToPlayer} so the handler keeps the correct instance
context and matches the existing wrapper pattern used by other toggles (e.g.,
dark mode/emojis handlers).
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Duplicate comments:
In `@src/client/UserSettingModal.ts`:
- Line 851: The template currently passes an unbound method reference
this.userSettings.toggleGoToPlayer which will lose its this context; create a
local wrapper method onToggleGoToPlayer(event) on the UserSettingModal class
that calls this.userSettings.toggleGoToPlayer(event) (or forwards any needed
args) and then change the template binding from
`@change`=${this.userSettings.toggleGoToPlayer} to
`@change`=${this.onToggleGoToPlayer} so the handler keeps the correct instance
context and matches the existing wrapper pattern used by other toggles (e.g.,
dark mode/emojis handlers).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 9587dc98-ff5f-4a24-9d43-8b44b6e900f7

📥 Commits

Reviewing files that changed from the base of the PR and between 4d68986 and 56dbbde.

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

coderabbitai[bot]
coderabbitai Bot previously approved these changes May 6, 2026
coderabbitai[bot]
coderabbitai Bot previously approved these changes May 6, 2026
Comment thread src/client/ClientGameRunner.ts Outdated
};

let hasGoneToPlayer = false;
let hasGoneToPlayer = !this.userSettings.goToPlayer();
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think this is a bit confusing, becasue we haven't already gone to the player. instead just return early if gotoplayer is disabled.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

@evanpelle this should be fixed in the latest commit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Development

Development

Successfully merging this pull request may close these issues.

Option to turn zoom to player off

2 participants