Allow resetting game data from existing disk data - #85
Conversation
…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>
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>
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>
…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>
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.
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).
|
I integrated this locally (useful addition!) and found two edge cases worth handling:
|
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()