Skip to content

Conversation

@jrouillard
Copy link
Contributor

@jrouillard jrouillard commented Jun 27, 2025

Description:

Adds a max timer setting
The timer starts at max timer and goes down, becoming red if reaching < 1 min
The player with the biggest territory wins at the end of the timer

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

Vivacious Box

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jun 27, 2025

Walkthrough

A new optional "max timer" feature was added to the game. This allows users to set a maximum game duration in minutes through the UI, which is enforced in both single-player and host lobbies. The timer is integrated into game logic, server configuration, and visual display, with supporting tests and localization.

Changes

File(s) Change Summary
resources/lang/en.json Added "max_timer" localization string in three sections for UI labels.
src/client/HostLobbyModal.ts
src/client/SinglePlayerModal.ts
Added UI controls and state for enabling/disabling max timer and inputting timer value; updated logic to include timer in config.
src/client/graphics/layers/OptionsMenu.ts Updated timer logic to use configurable max timer; changed timer display color when timer is low.
src/core/Schemas.ts Added optional maxTimerValue (1–120) to GameConfigSchema.
src/core/execution/WinCheckExecution.ts Added timer property; decrements timer; triggers win when timer reaches zero; updated win checks.
src/server/GameManager.ts
src/server/GameServer.ts
src/server/MapPlaylist.ts
Added/propagated optional maxTimerValue in game config creation and updates.
tests/core/execution/WinCheckExecution.test.ts Added tests for timer initialization, decrement, and win condition logic in WinCheckExecution.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant UI (Host/Single Modal)
    participant Server
    participant Game Logic

    User->>UI (Host/Single Modal): Enable Max Timer, input value
    UI (Host/Single Modal)->>Server: Send maxTimerValue in config
    Server->>Game Logic: Store maxTimerValue
    Game Logic->>Game Logic: On spawn phase, set timer = maxTimerValue * 60
    Game Logic->>Game Logic: Every 10 ticks, decrement timer
    Game Logic->>Game Logic: If timer == 0, trigger win condition
    Game Logic->>UI (Options Menu): Update timer display (red if < 60s)
Loading

Suggested labels

Feature - New, UI/UX

Suggested reviewers

  • evanpelle
  • scottanderson

Poem

⏲️ A timer ticks, a new game's pace,
Now minutes cap the endless race!
With UI checked and logic tight,
The countdown's red, the end in sight.
Code and tests in sweet accord—
Max timer's here, let games be scored!


📜 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 eb64a3d and 66e5408.

📒 Files selected for processing (1)
  • resources/lang/en.json (2 hunks)
✅ Files skipped from review due to trivial changes (1)
  • resources/lang/en.json
⏰ Context from checks skipped due to timeout of 90000ms (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.

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

🧹 Nitpick comments (2)
src/core/execution/WinCheckExecution.ts (1)

22-22: Remove the unnecessary empty constructor.

Static analysis correctly identifies this constructor as unnecessary since it does nothing.

-  constructor() {}
-
src/client/HostLobbyModal.ts (1)

496-513: Consider extracting shared validation logic.

The input validation handlers are identical to SinglePlayerModal. This duplication could be extracted into a shared utility function to follow DRY principles.

Create a shared utility like:

// utils/TimerInputValidation.ts
export const handleTimerKeyDown = (e: KeyboardEvent) => {
  if (["-", "+", "e"].includes(e.key)) {
    e.preventDefault();
  }
};

export const handleTimerInput = (e: Event): number | undefined => {
  const input = e.target as HTMLInputElement;
  input.value = input.value.replace(/[e\+\-]/gi, "");
  const value = parseInt(input.value);
  return (isNaN(value) || value < 0 || value > 400) ? undefined : value;
};
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between c1bf01d and d5aaca7.

📒 Files selected for processing (10)
  • resources/lang/en.json (2 hunks)
  • src/client/HostLobbyModal.ts (4 hunks)
  • src/client/SinglePlayerModal.ts (4 hunks)
  • src/client/graphics/layers/OptionsMenu.ts (2 hunks)
  • src/core/Schemas.ts (1 hunks)
  • src/core/execution/WinCheckExecution.ts (3 hunks)
  • src/server/GameManager.ts (1 hunks)
  • src/server/GameServer.ts (1 hunks)
  • src/server/MapPlaylist.ts (1 hunks)
  • tests/core/execution/WinCheckExecution.test.ts (1 hunks)
🧰 Additional context used
🧠 Learnings (5)
src/core/Schemas.ts (3)
Learnt from: scottanderson
PR: openfrontio/OpenFrontIO#784
File: src/core/game/StatsImpl.ts:34-38
Timestamp: 2025-05-21T04:10:33.435Z
Learning: In the codebase, PlayerStats is defined as `z.infer<typeof PlayerStatsSchema>` where PlayerStatsSchema has `.optional()` applied at the object level, making PlayerStats a union type that already includes undefined (PlayerStats | undefined).
Learnt from: scottanderson
PR: openfrontio/OpenFrontIO#784
File: src/core/game/StatsImpl.ts:34-38
Timestamp: 2025-05-21T04:10:33.435Z
Learning: In the codebase, PlayerStats is defined as a type inferred from a Zod schema that is marked as optional, which means PlayerStats already includes undefined as a possible type (PlayerStats | undefined).
Learnt from: 1brucben
PR: openfrontio/OpenFrontIO#977
File: src/core/execution/AttackExecution.ts:123-125
Timestamp: 2025-05-31T18:15:03.445Z
Learning: The removeTroops function in PlayerImpl.ts already prevents negative troop counts by using minInt(this._troops, toInt(troops)) to ensure it never removes more troops than available.
src/client/graphics/layers/OptionsMenu.ts (1)
Learnt from: VariableVince
PR: openfrontio/OpenFrontIO#1110
File: src/client/Main.ts:293-295
Timestamp: 2025-06-09T02:20:43.637Z
Learning: In src/client/Main.ts, during game start in the handleJoinLobby callback, UI elements are hidden using direct DOM manipulation with classList.add("hidden") for consistency. This includes modals, buttons, and error divs. The codebase follows this pattern rather than using component APIs for hiding elements during game transitions.
resources/lang/en.json (2)
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: scottanderson
PR: openfrontio/OpenFrontIO#949
File: resources/lang/en.json:8-10
Timestamp: 2025-05-30T03:53:52.231Z
Learning: For the OpenFrontIO project, do not suggest updating translation files in resources/lang/*.json except for en.json. The project has a dedicated translation team that handles all other locale files.
src/client/HostLobbyModal.ts (2)
Learnt from: VariableVince
PR: openfrontio/OpenFrontIO#1110
File: src/client/Main.ts:293-295
Timestamp: 2025-06-09T02:20:43.637Z
Learning: In src/client/Main.ts, during game start in the handleJoinLobby callback, UI elements are hidden using direct DOM manipulation with classList.add("hidden") for consistency. This includes modals, buttons, and error divs. The codebase follows this pattern rather than using component APIs for hiding elements during game transitions.
Learnt from: 1brucben
PR: openfrontio/OpenFrontIO#977
File: src/core/execution/AttackExecution.ts:123-125
Timestamp: 2025-05-31T18:15:03.445Z
Learning: The removeTroops function in PlayerImpl.ts already prevents negative troop counts by using minInt(this._troops, toInt(troops)) to ensure it never removes more troops than available.
src/client/SinglePlayerModal.ts (2)
Learnt from: VariableVince
PR: openfrontio/OpenFrontIO#1110
File: src/client/Main.ts:293-295
Timestamp: 2025-06-09T02:20:43.637Z
Learning: In src/client/Main.ts, during game start in the handleJoinLobby callback, UI elements are hidden using direct DOM manipulation with classList.add("hidden") for consistency. This includes modals, buttons, and error divs. The codebase follows this pattern rather than using component APIs for hiding elements during game transitions.
Learnt from: 1brucben
PR: openfrontio/OpenFrontIO#977
File: src/core/execution/AttackExecution.ts:123-125
Timestamp: 2025-05-31T18:15:03.445Z
Learning: The removeTroops function in PlayerImpl.ts already prevents negative troop counts by using minInt(this._troops, toInt(troops)) to ensure it never removes more troops than available.
🧬 Code Graph Analysis (3)
tests/core/execution/WinCheckExecution.test.ts (2)
src/core/execution/WinCheckExecution.ts (1)
  • WinCheckExecution (15-111)
tests/util/Setup.ts (1)
  • setup (22-83)
src/client/HostLobbyModal.ts (2)
src/client/LangSelector.ts (1)
  • translateText (222-242)
src/client/Utils.ts (1)
  • translateText (79-98)
src/client/SinglePlayerModal.ts (2)
src/client/LangSelector.ts (1)
  • translateText (222-242)
src/client/Utils.ts (1)
  • translateText (79-98)
🪛 GitHub Actions: 🧪 CI
tests/core/execution/WinCheckExecution.test.ts

[error] 45-45: ENOENT: no such file or directory, open '/home/runner/work/OpenFrontIO/OpenFrontIO/tests/testdata/maps/BigPlains/map.bin'. This caused multiple test failures in WinCheckExecution tests.

🪛 Biome (1.9.4)
src/core/execution/WinCheckExecution.ts

[error] 22-23: This constructor is unnecessary.

Unsafe fix: Remove the unnecessary constructor.

(lint/complexity/noUselessConstructor)

🔇 Additional comments (17)
src/server/GameManager.ts (1)

39-39: LGTM: Max timer property added correctly.

The addition follows the established pattern for optional configuration properties and aligns with the schema definition.

src/core/Schemas.ts (1)

143-143: Good validation range for timer feature.

The 1-120 minute range provides sensible bounds for game timers. The validation correctly enforces integer values and marks the field as optional.

src/server/MapPlaylist.ts (1)

59-59: Consistent implementation across configuration objects.

The max timer property is properly included in the map playlist configuration, maintaining consistency with other configuration files.

resources/lang/en.json (1)

126-126: Clear and descriptive localization text.

The "Max timer (minutes)" text is simple and clear for users. Good practice including the unit in the label to avoid confusion.

Also applies to: 198-198

src/server/GameServer.ts (1)

93-95: Update logic follows established pattern.

The max timer update implementation is consistent with other configuration properties in the method. Clean and predictable code structure.

src/client/graphics/layers/OptionsMenu.ts (2)

151-164: Timer logic implementation looks solid.

The countdown timer logic correctly initializes to maxTimerValue * 60 seconds during spawn phase and decrements every 10 ticks. The fallback to original count-up behavior when maxTimerValue is undefined maintains backward compatibility.


193-196: Good visual feedback for timer urgency.

The red color (#ff8080) when timer drops below 60 seconds provides clear visual warning to players. The conditional styling is implemented correctly.

tests/core/execution/WinCheckExecution.test.ts (1)

21-91: Comprehensive test coverage for timer functionality.

The test suite properly covers:

  • Timer initialization from maxTimerValue
  • Timer decrement behavior every 10 ticks
  • Game mode routing to correct win check methods
  • Win conditions for both tile percentage and timer expiration
  • Edge cases like no players

The mocking approach using jest.fn() and spies is clean and effective.

src/client/SinglePlayerModal.ts (3)

38-39: Clean state management for max timer feature.

The reactive state properties maxTimer and maxTimerValue follow the established pattern in the component.


388-404: Good input validation preventing invalid characters.

The keydown handler blocks problematic characters (-, +, e) and the input handler removes them via regex. The range validation is also properly implemented.


479-479: Correct conditional inclusion in game config.

The ternary operator properly includes maxTimerValue only when maxTimer is enabled, otherwise undefined to exclude it from the config.

src/core/execution/WinCheckExecution.ts (4)

19-20: Good documentation for the timer property.

The comment clearly explains the timer represents remaining seconds and is undefined when disabled.


26-29: Timer initialization logic is correct.

Properly converts minutes to seconds (maxTimerValue * 60) and only initializes when maxTimerValue is defined.


38-40: Safe timer decrement implementation.

Using Math.max(0, this.timer - 1) prevents the timer from going negative, which is the correct behavior.


62-63: Timer-based win condition properly integrated.

Both FFA and Team win check methods correctly include this.timer === 0 as an additional win condition alongside the existing tile percentage logic.

Also applies to: 93-96

src/client/HostLobbyModal.ts (2)

37-38: Consistent state management with SinglePlayerModal.

The same reactive state properties maintain consistency between single-player and multiplayer hosting experiences.


551-552: Correct conditional config inclusion matches SinglePlayerModal.

The ternary logic properly includes maxTimerValue only when enabled, maintaining consistency across both modals.

@github-project-automation github-project-automation bot moved this from Triage to Development in OpenFront Release Management Jun 27, 2025
coderabbitai[bot]
coderabbitai bot previously approved these changes Jun 27, 2025
@evanpelle evanpelle added this to the v24 milestone Jun 27, 2025
Copy link
Collaborator

Choose a reason for hiding this comment

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

please revert

@CLAassistant
Copy link

CLAassistant commented Jul 16, 2025

CLA assistant check
All committers have signed the CLA.

@drillskibo
Copy link
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, especially about reverting?

Copy link
Contributor

@drillskibo drillskibo left a comment

Choose a reason for hiding this comment

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

Please remove unrelated commits, make the requested changes above, and fix potential conflicts.

@drillskibo drillskibo changed the base branch from v24 to main July 28, 2025 15:01
@drillskibo drillskibo dismissed coderabbitai[bot]’s stale review July 28, 2025 15:01

The base branch was changed.

@drillskibo drillskibo requested a review from a team as a code owner July 28, 2025 15:01
@drillskibo drillskibo modified the milestones: v24, v25 Jul 28, 2025
@drillskibo drillskibo added the Feature - Backend An entirely new feature, or changes to an existing feature. Not user facing label Jul 28, 2025
@drillskibo drillskibo added the Feature - Frontend An entirely new feature, or changes to existing feature. User facing. label Jul 28, 2025
@drillskibo drillskibo modified the milestones: v25, v26 Aug 5, 2025
coderabbitai[bot]
coderabbitai bot previously approved these changes Oct 12, 2025
coderabbitai[bot]
coderabbitai bot previously approved these changes Oct 12, 2025
@TheGiraffe3
Copy link
Member

If we want this in v26 it needs to be rebased into that branch.

}
} else {
if (this.game.inSpawnPhase()) {
this.timer = 0;
Copy link
Collaborator

Choose a reason for hiding this comment

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

instead of a seperate timer field, i think we can just calculate it in render:

const timeLeft = this.game.config().gameConfig().maxTimerValue - this.game.ticks() - this.game.config().spawnDuration()

Copy link
Collaborator

@evanpelle evanpelle left a comment

Choose a reason for hiding this comment

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

Thanks!

@github-project-automation github-project-automation bot moved this from Development to Final Review in OpenFront Release Management Oct 18, 2025
@evanpelle evanpelle merged commit f161c94 into openfrontio:main Oct 18, 2025
8 checks passed
@github-project-automation github-project-automation bot moved this from Final Review to Complete in OpenFront Release Management Oct 18, 2025
@coderabbitai coderabbitai bot mentioned this pull request Oct 18, 2025
4 tasks
DevelopingTom pushed a commit to DevelopingTom/OpenFrontIO that referenced this pull request Oct 24, 2025
## Description:

Adds a max timer setting
The timer starts at max timer and goes down, becoming red if reaching <
1 min
The player with the biggest territory wins at the end of the timer


![image](https://github.com/user-attachments/assets/888099fc-95ae-4303-8c80-c850e58d36e2)

## Please complete the following:

- [x] I have added screenshots for all UI updates
- [x] I process any text displayed to the user through translateText()
and I've added it to the en.json file
- [x] I have added relevant tests to the test directory
- [x] I confirm I have thoroughly tested these changes and take full
responsibility for any bugs introduced
- [x] 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:

Vivacious Box

---------

Co-authored-by: Loymdayddaud <[email protected]>
@coderabbitai coderabbitai bot mentioned this pull request Nov 16, 2025
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Feature - Backend An entirely new feature, or changes to an existing feature. Not user facing Feature - Frontend An entirely new feature, or changes to existing feature. User facing.

Projects

Status: Complete

Development

Successfully merging this pull request may close these issues.

6 participants