Skip to content

Allow resetting game data from existing disk data - #85

Open
xendke wants to merge 1 commit into
NobleRobot:mainfrom
xendke:patch-3
Open

Allow resetting game data from existing disk data#85
xendke wants to merge 1 commit into
NobleRobot:mainfrom
xendke:patch-3

Conversation

@xendke

@xendke xendke commented Jul 2, 2024

Copy link
Copy Markdown
Contributor

I was using this in a game I'm working on and was wondering if there's any interest in merging this into the repo.

This PR would allow devs to reset game data back to the value that is currently saved to disk instead of the default values provided in Noble.GameData.setup()

ericlewis added a commit to ericlewis/NobleEngine that referenced this pull request Aug 11, 2026
…k(). (upstream PR NobleRobot#85)

These restore in-memory GameData values from the last-saved disk
values, instead of the setup() defaults. Purely additive.
Applies upstream PR NobleRobot#85.

Co-authored-by: Juan Xavier Gomez <xendke@users.noreply.github.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
ericlewis added a commit to ericlewis/NobleEngine that referenced this pull request Aug 11, 2026
Two fixes for the functions added in 7aa010a (upstream PR NobleRobot#85):

Noble.GameData.resetAllFromDisk() skipped the exists() slot validation
used by every other function in this module. An invalid slot number
either crashed with "attempt to index a nil value" (when a stray save
file for that slot happened to exist on disk) or produced the
misleading "No GameData found on disk" error, in both cases leaving
currentSlot pointing at the invalid slot. It now validates the slot
via exists(), mirroring resetFromDisk() and save().

Both resetFromDisk() and resetAllFromDisk() copied disk values
verbatim. If the save on disk predates a key (e.g. it was written by
an older version of the game), the nil disk value deleted the key from
the live GameData - despite setup()'s warning never to use nil values -
making every later get/set/reset of that item throw the "Game Datum
does not exist" error. Keys missing from the disk copy now fall back
to their default values, matching setup()'s key-migration behavior.

Refs upstream PR NobleRobot#85.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
ericlewis added a commit to ericlewis/NobleEngine that referenced this pull request Aug 11, 2026
Hand-patch the LDoc-generated HTML (as done in d781092 for
NobleSprite.html) to cover changes the earlier commits missed:

- Noble.html: add the missing sidebar index entry for
  Noble.performTransition (the body entry was added in 50be77b, but
  the function was undiscoverable from the nav).
- Noble.GameData.html: add sidebar and body entries for
  resetFromDisk() and resetAllFromDisk() (added in 7aa010a,
  upstream PR NobleRobot#85).
- Noble.Transition.html: replace the stale "panelImage property is
  locked" notes for DipToBlack/DipToWhite with tilePattern and point
  their See references at DipTile; add the new DipTile submodule and
  its defaultProperties table (47f83cf, upstream PR NobleRobot#92); document the
  per-invocation callback properties on the onStart/onMidpoint/
  onHoldTimeElapsed/onComplete entries (50be77b).
- NobleScene.html: add the debugColor property, enableDebug/
  disableDebug methods, and drawDebug callback (b587cd8, upstream
  PR NobleRobot#54), plus the gameWillTerminate/deviceWillSleep/deviceWillLock/
  deviceDidUnlock callbacks (b034f38, upstream issue NobleRobot#55).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
ericlewis added a commit to ericlewis/NobleEngine that referenced this pull request Aug 11, 2026
…k(). (upstream PR NobleRobot#85)

These restore in-memory GameData values from the last-saved disk
values, instead of the setup() defaults. Purely additive.
Applies upstream PR NobleRobot#85.

Co-authored-by: Juan Xavier Gomez <xendke@users.noreply.github.com>
ericlewis added a commit to ericlewis/NobleEngine that referenced this pull request Aug 11, 2026
Two fixes for the functions added in 7aa010a (upstream PR NobleRobot#85):

Noble.GameData.resetAllFromDisk() skipped the exists() slot validation
used by every other function in this module. An invalid slot number
either crashed with "attempt to index a nil value" (when a stray save
file for that slot happened to exist on disk) or produced the
misleading "No GameData found on disk" error, in both cases leaving
currentSlot pointing at the invalid slot. It now validates the slot
via exists(), mirroring resetFromDisk() and save().

Both resetFromDisk() and resetAllFromDisk() copied disk values
verbatim. If the save on disk predates a key (e.g. it was written by
an older version of the game), the nil disk value deleted the key from
the live GameData - despite setup()'s warning never to use nil values -
making every later get/set/reset of that item throw the "Game Datum
does not exist" error. Keys missing from the disk copy now fall back
to their default values, matching setup()'s key-migration behavior.

Refs upstream PR NobleRobot#85.
ericlewis added a commit to ericlewis/NobleEngine that referenced this pull request Aug 11, 2026
Hand-patch the LDoc-generated HTML (as done in d781092 for
NobleSprite.html) to cover changes the earlier commits missed:

- Noble.html: add the missing sidebar index entry for
  Noble.performTransition (the body entry was added in 50be77b, but
  the function was undiscoverable from the nav).
- Noble.GameData.html: add sidebar and body entries for
  resetFromDisk() and resetAllFromDisk() (added in 7aa010a,
  upstream PR NobleRobot#85).
- Noble.Transition.html: replace the stale "panelImage property is
  locked" notes for DipToBlack/DipToWhite with tilePattern and point
  their See references at DipTile; add the new DipTile submodule and
  its defaultProperties table (47f83cf, upstream PR NobleRobot#92); document the
  per-invocation callback properties on the onStart/onMidpoint/
  onHoldTimeElapsed/onComplete entries (50be77b).
- NobleScene.html: add the debugColor property, enableDebug/
  disableDebug methods, and drawDebug callback (b587cd8, upstream
  PR NobleRobot#54), plus the gameWillTerminate/deviceWillSleep/deviceWillLock/
  deviceDidUnlock callbacks (b034f38, upstream issue NobleRobot#55).
@ericlewis

Copy link
Copy Markdown

I integrated this locally (useful addition!) and found two edge cases worth handling:

  1. resetAllFromDisk() skips slot validation. Every other function in this module validates the slot via exists(), but resetAllFromDisk() assigns currentSlot = __gameDataSlot or currentSlot and reads directly. An invalid slot number either crashes with "attempt to index a nil value" (when a stray save file for that slot happens to exist on disk) or produces the misleading "No GameData found on disk" error — and in both cases currentSlot is left pointing at the invalid slot for subsequent calls.

  2. Keys missing from the disk save get deleted from the live GameData. Both functions copy disk values verbatim. If the save on disk was written by an older version of the game that didn't have a key yet, gameData.data[key] is nil, and assigning it deletes the key — after which every get/set/reset of that item throws "Game Datum does not exist" (despite setup()'s warning never to use nil values). Falling back to the setup() defaults for keys missing on disk would match setup()'s existing key-migration behavior.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants