Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add save/load #1

Open
david-a-wheeler opened this issue Jul 25, 2015 · 2 comments
Open

Add save/load #1

david-a-wheeler opened this issue Jul 25, 2015 · 2 comments

Comments

@david-a-wheeler
Copy link
Owner

Add the ability to save/load games (stories) in progress.

@david-a-wheeler
Copy link
Owner Author

Save/load requires a place to store data, and a way to represent data that can be reloaded later. Let's deal with a place to store data first.

The easy way to store data is client-side. Storing data client-side can be done with cookies, but the amount of storage allowed is limited. More storage is available on clients via the Web storage API (use "local" not "session" mode); these are now widely supported. More info:
http://www.w3schools.com/html/html5_webstorage.asp
https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API
http://www.w3.org/TR/webstorage/
http://html5doctor.com/storing-data-the-simple-html5-way-and-a-few-tricks-you-might-not-have-known/
http://diveintohtml5.info/storage.html

A separate comment will focus on how to represent the data.

@david-a-wheeler
Copy link
Owner Author

Data representation in Javascript is often done with JSON, but that won't work directly. The data to be represented includes function definitions and recursive/cyclic object references; JSON supports neither.

If all we needed was JSON+function function definitions, those are easy. Jsonfn at https://github.com/vkiryukhin/jsonfn shows how. (MIT license, Copyright (c) 2014 Vadim Kiryukhin ( vkiryukhin @ gmail.com )). In short:

   jsonlike_stringify_old: function(obj) {
           return JSON.stringify(obj, function (key, value) {
                   if (value instanceof Function ||
                       typeof value == 'function') {
                           return value.toString();
                   }
                   if (value instanceof RegExp) {
                           return '_PxEgEr_' + value;
                   }
                   return value;
           });
   },

That's not enough for cyclic references, though. A discussion on how to also deal with cyclic references is here:
http://stackoverflow.com/questions/9382167/serializing-object-that-contains-cyclic-object-value

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

No branches or pull requests

1 participant