Skip to content

Fix timer reset on resume by restoring normalized elapsed time - #26

Merged
ssfinney merged 2 commits into
mainfrom
codex/fix-timer-reset-on-game-resume
Mar 22, 2026
Merged

Fix timer reset on resume by restoring normalized elapsed time#26
ssfinney merged 2 commits into
mainfrom
codex/fix-timer-reset-on-game-resume

Conversation

@ssfinney

Copy link
Copy Markdown
Owner

Motivation

Description

  • Add a normalizeElapsed helper to coerce persisted timer values into a safe non-negative integer.
  • Update formatTime to use normalizeElapsed so displayed times are stable for malformed or legacy values.
  • Restore elapsed in applyLoadedData using elapsed with backward-compatible fallbacks timeElapsed, timer, and timeSeconds before defaulting to zero.
  • Use the same fallback lookup for the resume modal preview so the shown resume time matches the restored timer.

Testing

  • Ran node --check script.js and it succeeded.

Codex Task

@github-actions

github-actions Bot commented Mar 22, 2026

Copy link
Copy Markdown

🌸 Diff Haiku

Timer lost and reset,
normalize time restored—
resume counts once more.


Generated by spit-the-diff

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses an issue where the game timer would reset to zero upon resuming a saved game due to missing or inconsistently stored elapsed time data. The changes introduce a robust mechanism to parse, validate, and restore the timer from various potential storage keys, ensuring a consistent and accurate display and restoration of game progress.

Highlights

  • Robust Timer Normalization: Added a new normalizeElapsed helper function to safely parse and validate elapsed time values, ensuring they are non-negative integers.
  • Consistent Time Formatting: Updated the formatTime utility to use normalizeElapsed, providing stable and correct display for potentially malformed or legacy timer data.
  • Backward-Compatible Timer Restoration: Modified the applyLoadedData function to restore the game's elapsed time by checking multiple legacy keys (timeElapsed, timer, timeSeconds) before defaulting to zero, all while normalizing the value.
  • Synchronized Resume Preview: Ensured the resume modal preview displays the saved time using the same robust fallback and normalization logic, matching the actual restored timer.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request effectively addresses the timer reset issue by introducing a normalizeElapsed function to handle invalid or missing timer values, and by adding backward-compatible fallbacks for legacy data keys. The changes are logical and correctly implemented. I have one suggestion to further improve maintainability by extracting the duplicated fallback logic into a helper function.

Comment thread script.js Outdated
notes=data.notes.map(row=>row.map(arr=>new Set(arr)));
selected=data.selected;
elapsed=data.elapsed||0;
elapsed=normalizeElapsed(data.elapsed ?? data.timeElapsed ?? data.timer ?? data.timeSeconds);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

This logic for retrieving the elapsed time by checking multiple legacy keys is also used on line 956. To improve maintainability and avoid future inconsistencies where one location is updated but the other is not, consider extracting this logic into a dedicated helper function.

For example, you could create a function:

function getPersistedElapsedTime(data) {
  return data.elapsed ?? data.timeElapsed ?? data.timer ?? data.timeSeconds;
}

And then use it here and on line 956:

// line 576
elapsed = normalizeElapsed(getPersistedElapsedTime(data));

// line 956
timeStat.textContent = formatTime(getPersistedElapsedTime(saved));

This would make the code more DRY (Don't Repeat Yourself) and easier to maintain.

@ssfinney
ssfinney merged commit 6c72a83 into main Mar 22, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant