AluminumAngel / gloom

Gloomhaven Monster Mover
MIT License
36 stars 6 forks source link

share scenario button / basically, allow scenario to be encoded in URL #2

Closed dieck closed 5 years ago

dieck commented 5 years ago

Hi!

I am not quite sure, but if you store everything in localStorage anyway, wouldn't is be the easiest way to export and import that whole thing?

// Export localStorage to Base64 encoded JSON to present to user var toExport = window.btoa( unescape( encodeURIComponent( JSON.stringify( JSON.stringify( localStorage)))));

and

// Import Base64 encoded JSON into localStorage var tmpdata = JSON.parse( decodeURIComponent( escape( window.atob( toImport)))); Object.keys(tmpdata).forEach(function (k) { localStorage.setItem(k, data[k]); });

I am not that familiar with React, otherwise I might have tried to create a pull request :)

Possible enhancements: Compression, e.g. https://github.com/pieroxy/lz-string/ or https://github.com/tcorral/JSONC

AluminumAngel commented 5 years ago

What are the advantages of that approach?

How does your code slot into the functions storeState() and restoreState()?

dieck commented 5 years ago

Well, storeState() and restoreState() work only locally in your browser. The lines above* can be used to export to a (long) string and import from that, to present to the user and thus traverse browsers and computers.

(* They are untested, and maybe not very efficient or elegant, but should do the trick)

I am just setting up a flask environment to take a look at the system myself, maybe I can propose a pull after all

AluminumAngel commented 5 years ago

I see what you are saying. Encoding the scenario in a URL, to allow sharing, is a very good idea.

omireault commented 5 years ago

This could be used to crowd-source the scenario implementations. You can curate a bookmarked URL list that will load each scenario, room by room. Once someone trustworthy has validated the URL does correspond to the scenario, it can be added under a new Bookmark button or something in the app itself for everyone to use.

AluminumAngel commented 5 years ago

Agreed. This can be a powerful feature. Got me excited enough to pick the project back up again.

I did a test of the naive solution, and unfortunately it resulted in 10K URLs. I've got something more sophisticated working. Need to add validation and clean it up. Soon.

AluminumAngel commented 5 years ago

Great idea! Feature added at fb270772996cd567e5590d1631c6d09ae09098f0.

Deploying now.