ogallagher / tejos_textiles

An online arts journal for publishing works in a new medium
MIT License
1 stars 0 forks source link

Save partial play data in sessions #58

Closed ogallagher closed 4 years ago

ogallagher commented 4 years ago

Currently, when a visitor signs in, their db account can store data of their puzzle completions (full plays), but not their progress (partial plays). Partial plays will be ephimeral and variable so they’ll be stored in the session file as an array of objects taking the following structure:

partial_plays = [{
    puzzle_id: 1,
    completes: [true,false,false,true], //whether each shape in the textile was complete
    duration: 1000 //milliseconds
}]

A partial play is stored/updated using $(window).on('unload',handler). When the user leaves the page, the partial play is stored in the server’s session file.

A partial play is optionally restored when the puzzle loads; a button appears in the textile title bar with the oi-cloud-download logo, which opens a modal confirming progress restore. It’s automatically triggered when the page loads.

EDIT: Partial play restore is not optional, it just restores automatically when the puzzle loads.

ogallagher commented 4 years ago

The major issue I ran into doing this was attempting to use an http request to post the partial play to the session server; these calls are not consistently supported in event handlers for window.onbeforeunload. So I added a save-progress button to invoke the sending of the play, rather than trigger automatically when the user leaves a page.

ogallagher commented 4 years ago

Done.