Gankro/Jterniabound — pull request #36 by LtSquigs (2012-09-03 20:19:06+00:00)
Title: Save function updates and Serialization fixes

First off, I fixed some serialization issues with the new AJAX loading (had to save original sources or it would serialize blob urls).

Next, I've updated the save functions to more match what was described in Issue #21

1) The saveStateToStorage function now has the signature saveStateToStorage(description, auto, local) where the description parameter should be a descriptive name for the save (i.e. 'Kankri, 2nd room') and the auto is a boolean flag that indicates if this is an auto save or not (defaults to false)

2) The loadStateFromStorage function now has the signature loadStateFromStorage(auto, local). The auto parameter is a boolean flag, defaults to false. If true loads the auto save, if false loads the manual save. If no save is found (or storage is not supported) return false.

3) Added function getStateDescription(auto). Returns the description of the current saved state (the same string passed to saveStateToStorage). The auto flag defaults to false, if true returns the description for the auto save. Use this function to display save names in the "Load ..." and "Load ... (auto)" dialog box (I know you originally mentioned adding it to the sburb XML, but I don't think thats a good idea as then the XML would need to be decompressed and parsed every time you want to just check the save name)

4) Updated deleteSaveFromStorage to have the signature deleteSaveFromStorage(auto, local). The function now deletes the current save from storage (and also deletes any previous versions save if detected). The auto flag defaults to false, if true this deletes the auto save instead.

5) Added function deleteOldVersionStates(local). When called this deletes all old versions states from storage (the local flag defaults to false, if true this deletes from localStorage instead of session)

6) Changed isStateInStorage to be isStateInStorage(auto, local). Returns true if a state is detected in storage, false otherwise. The auto flag defaults to false and if true checks if an auto save is in storage.

Right now all of these functions default to use session storage. I.e. All the states in storage are deleted when the user closes their browser session. It sounds like the intent with this save system is to be a bit more permanent (and with the compression rates this shouldn't be a big size problem). Do you want me to make it so they all save to local storage as a default instead?