diff options
| author | Simon Tatham <anakin@pobox.com> | 2017-09-05 20:48:42 +0100 |
|---|---|---|
| committer | Simon Tatham <anakin@pobox.com> | 2017-09-05 20:58:05 +0100 |
| commit | 721119e4a61cbb261b456dfd134811d7beb5ce98 (patch) | |
| tree | c31c90e57d7cb002fcfc9f09bc15b505836ae422 /emccpre.js | |
| parent | 1bf591a5735068d1853be13c5a4255962835d5fe (diff) | |
| download | puzzles-721119e4a61cbb261b456dfd134811d7beb5ce98.zip puzzles-721119e4a61cbb261b456dfd134811d7beb5ce98.tar.gz puzzles-721119e4a61cbb261b456dfd134811d7beb5ce98.tar.bz2 puzzles-721119e4a61cbb261b456dfd134811d7beb5ce98.tar.xz | |
Support for loading games in Javascript puzzles.
This is done by showing a dialog containing an <input type="file">
through which the user can 'upload' a save file - though, of course,
the 'upload' doesn't go to any HTTP server, but only into the mind of
the Javascript running in the same browser.
It would be even nicer to support drag-and-drop as an alternative UI
for getting the save file into the browser, but that isn't critical to
getting the first version of this feature out of the door.
Diffstat (limited to 'emccpre.js')
| -rw-r--r-- | emccpre.js | 26 |
1 files changed, 26 insertions, 0 deletions
@@ -299,6 +299,7 @@ function initPuzzle() { // 'number' is used for C pointers get_save_file = Module.cwrap('get_save_file', 'number', []); free_save_file = Module.cwrap('free_save_file', 'void', ['number']); + load_game = Module.cwrap('load_game', 'void', ['string', 'number']); document.getElementById("save").onclick = function(event) { if (dlg_dimmer === null) { @@ -322,6 +323,31 @@ function initPuzzle() { } }; + document.getElementById("load").onclick = function(event) { + if (dlg_dimmer === null) { + dialog_init("Upload saved-game file"); + var input = document.createElement("input"); + input.type = "file"; + input.multiple = false; + dlg_form.appendChild(input); + dlg_form.appendChild(document.createElement("br")); + dialog_launch(function(event) { + if (input.files.length == 1) { + var file = input.files.item(0); + var reader = new FileReader(); + reader.addEventListener("loadend", function() { + var string = reader.result; + load_game(string, string.length); + }); + reader.readAsBinaryString(file); + } + dialog_cleanup(); + }, function(event) { + dialog_cleanup(); + }); + } + }; + gametypelist = document.getElementById("gametype"); gametypesubmenus.push(gametypelist); |