Skip to content

Added button to restart single-player games#3960

Open
sardidefcon wants to merge 1 commit into
openfrontio:mainfrom
sardidefcon:feature-restart-button
Open

Added button to restart single-player games#3960
sardidefcon wants to merge 1 commit into
openfrontio:mainfrom
sardidefcon:feature-restart-button

Conversation

@sardidefcon
Copy link
Copy Markdown
Contributor

@sardidefcon sardidefcon commented May 18, 2026

Description:

A button has been added to restart single-player games. Due to the individual ID system for each game, the game isn't actually restarted; instead, an identical game is created with the same parameters the user set when starting the game.

restart button

I've tested the functionality, adding custom options, disabling buildings, etc. Everything seems to be working correctly.

During development, I encountered a bug: when restarting a game and the "confirm" dialog appears, the background sound and sound effects stop playing. This bug has been fixed, but it also occurs with the "Exit" button. If you cancel, the background sound and sound effects stop playing for the remainder of the game. I'm submitting a pull request to fix this bug in another pull request.

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:

sardidefcon

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 18, 2026

Review Change Stack

Walkthrough

This PR adds a singleplayer game restart feature. A new restart button appears in the game sidebar (visible only for singleplayer, non-replay games), dispatches a custom event on confirmation, persists game configuration to sessionStorage, stops gameplay, and reloads the page. On reload, the persisted configuration is recovered and the game automatically rejoins with a fresh game ID.

Changes

Singleplayer restart flow

Layer / File(s) Summary
Restart button UI in game sidebar
src/client/graphics/layers/GameRightSidebar.ts
Adds a restart button visible only in singleplayer games. Imports Howler to handle Web Audio context state. Defines _canRestart state (enabled during singleplayer, disabled for replays), implements onRestartButtonClick() to confirm and dispatch the restart event, and renders the button conditionally with wired click handler and localized text.
Restart event handling and state management
src/client/Main.ts
Extends DocumentEventMap to type the new "restart-lobby" event. Introduces SINGLEPLAYER_RESTART_KEY constant for sessionStorage. Tracks the most recent singleplayer lobby in lastSingleplayerLobby. Registers a document listener for "restart-lobby" that triggers handleRestartLobby (persists game config, stops gameplay, reloads to /). Implements consumeSingleplayerRestart (runs on reload to recover config, generate a fresh game ID, rebuild the join event, and re-dispatch to rejoin). Modifies handleJoinLobby to save singleplayer-only lobbies and updates URL handling to invoke restart recovery.
Restart button text and confirmation message
resources/lang/en.json
Adds restart_game (button label) and restart_confirmation (dialog warning) English localization strings under the help_modal section.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Poem

A fresh start awaits when the player says "go"—
Save the state, reload the page, let it flow.
New game ID springs, the lobby's reborn,
Singleplayer restarts from the break of dawn. 🎮✨

🚥 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 'Added button to restart single-player games' directly and clearly summarizes the main change in the changeset.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description check ✅ Passed The PR description clearly explains the feature: a restart button for single-player games that creates a new identical game with the same parameters. It includes testing details, UI screenshots, and proper translation handling.

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


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.

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

Labels

None yet

Projects

Status: Triage

Development

Successfully merging this pull request may close these issues.

1 participant