{"action":"created","issue":{"url":"https://api.github.com/repos/vorple/vorple/issues/35","repository_url":"https://api.github.com/repos/vorple/vorple","labels_url":"https://api.github.com/repos/vorple/vorple/issues/35/labels{/name}","comments_url":"https://api.github.com/repos/vorple/vorple/issues/35/comments","events_url":"https://api.github.com/repos/vorple/vorple/issues/35/events","html_url":"https://github.com/vorple/vorple/issues/35","id":368421369,"node_id":"MDU6SXNzdWUzNjg0MjEzNjk=","number":35,"title":"Help needed to integrate Vorple save/restore in Electron","user":{"login":"Natrium729","id":24978378,"node_id":"MDQ6VXNlcjI0OTc4Mzc4","avatar_url":"https://avatars3.githubusercontent.com/u/24978378?v=4","gravatar_id":"","url":"https://api.github.com/users/Natrium729","html_url":"https://github.com/Natrium729","followers_url":"https://api.github.com/users/Natrium729/followers","following_url":"https://api.github.com/users/Natrium729/following{/other_user}","gists_url":"https://api.github.com/users/Natrium729/gists{/gist_id}","starred_url":"https://api.github.com/users/Natrium729/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Natrium729/subscriptions","organizations_url":"https://api.github.com/users/Natrium729/orgs","repos_url":"https://api.github.com/users/Natrium729/repos","events_url":"https://api.github.com/users/Natrium729/events{/privacy}","received_events_url":"https://api.github.com/users/Natrium729/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":4,"created_at":"2018-10-09T22:20:36Z","updated_at":"2018-11-06T20:00:47Z","closed_at":null,"author_association":"NONE","body":"I'm writing a boilerplate to easily release a Vorple project with Electron:\r\n\r\nhttps://bitbucket.org/Natrium729/vorplectron\r\n\r\nI could manage most of its features, but I can't manage to use [Electron native dialogs](https://electronjs.org/docs/api/dialog#dialogshowopendialogbrowserwindow-options-callback) when saving and restoring the game.\r\n\r\nFollowing is an explanation of what I tried.\r\n\r\nSince I didn't want to delve into Vorple's low-level working, I thought I would use [an extension I wrote](https://bitbucket.org/Natrium729/extensions-inform-7/src/default/Save%20File%20Control.i7x), \"Save File Control\", that make it possible to save the game's state into an Inform external file. ([It is in fact code that comes from *Kerkerkruip*.](https://github.com/i7/kerkerkruip/blob/master/Kerkerkruip.materials/Extensions/Victor%20Gijsbers/Kerkerkruip%20Permadeath.i7x))\r\n\r\nThe plan was this. Within the game, I save the game state into an Inform external file and I use Emscripten file system to read its data, that I send to Electron; Electron then opens the dialog and write the data to the selected location using Node.js file system. I do that the other way around when restoring the game.\r\n\r\nThis work fine when using normal external files (with text inside), but not with an external holding a save: restoring a file that was saved on the hard disk fails. Using the Save File Control extension directly within the story (such as in its \"Permadeath\" exemple) without messing with Electron works fine.\r\n\r\nIf you want to see the code that I wrote:\r\n\r\n* [The Inform side is in this extension.](https://bitbucket.org/Natrium729/extensions-inform-7/src/26989f3b7de70f77439bd1f90fc610df7962ef10/Vorplectron.i7x#lines-86)\r\n* [The Electron side is here.](https://bitbucket.org/Natrium729/vorplectron/src/4a217a873169aa58d15e97f397cdb661fb6f9627/listeners.js#lines-47)\r\n\r\nSo I'm asking what my other options to use Electron native dialogs to save and restore the game are. It would be great if there were a way to ask Vorple to return an object (or a string or whatever) containing the encoded game state and a way to send back an encoded state to Vorple.\r\n\r\nIt's not that urgent, but a friend of mine will soon release a preview of his Vorple game. While not having the possibility to save and restore in the demo is not critical, this is the only blocking issue remaining. So even a temporary workaround would be appreciated.\r\n\r\nThanks!"},"comment":{"url":"https://api.github.com/repos/vorple/vorple/issues/comments/436388739","html_url":"https://github.com/vorple/vorple/issues/35#issuecomment-436388739","issue_url":"https://api.github.com/repos/vorple/vorple/issues/35","id":436388739,"node_id":"MDEyOklzc3VlQ29tbWVudDQzNjM4ODczOQ==","user":{"login":"Natrium729","id":24978378,"node_id":"MDQ6VXNlcjI0OTc4Mzc4","avatar_url":"https://avatars3.githubusercontent.com/u/24978378?v=4","gravatar_id":"","url":"https://api.github.com/users/Natrium729","html_url":"https://github.com/Natrium729","followers_url":"https://api.github.com/users/Natrium729/followers","following_url":"https://api.github.com/users/Natrium729/following{/other_user}","gists_url":"https://api.github.com/users/Natrium729/gists{/gist_id}","starred_url":"https://api.github.com/users/Natrium729/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Natrium729/subscriptions","organizations_url":"https://api.github.com/users/Natrium729/orgs","repos_url":"https://api.github.com/users/Natrium729/repos","events_url":"https://api.github.com/users/Natrium729/events{/privacy}","received_events_url":"https://api.github.com/users/Natrium729/received_events","type":"User","site_admin":false},"created_at":"2018-11-06T20:00:47Z","updated_at":"2018-11-06T20:00:47Z","author_association":"NONE","body":"So the latest release fixed the saving/restoring bug. Does it add an easy way to hook a custom dialog?\r\n\r\nI dug a bit in haven's source code, and I think I could hook a restore dialog in haven/file.js, in the function `prompt`. (I would replace `window.prompt` with Electron's `dialog.showOpenDialog`, read the data at the opened path, write it with Emscripten FS to `/gamedata_${checksum}/savename.glksave`.)\r\n\r\nHowever, it wouldn't work when saving, because then the dialog has to be opened *after* the save has occured (so that we can read the data and write it to the user's computer.) Another problem is that it is not possible to detect what kind of file is being processed (a save, a transcript, etc.).\r\n\r\nWe would need another hook at the end of `glk_fileref_create_by_prompt` in cheapglk/cgfref.c, but then there would be a lot to refactor, I think.\r\n\r\nOr maybe I'm just looking too far and an easier way exists?\r\n\r\n(By the way, the documentation for the function `prompt` in haven/file.js is not correct. It states that the argument `why` has to be one of \"for command recording\", \"for command playback\", \"to restore\", \"to save\" or \"to begin transcription (or printer name)\", which is not the case since in cheapglk/cgfref.c, the argument used in `EM_ASM` is `prompt2`, which can only be \"to store\" or \"to load\".)"}}
{"actor":{"display_login":"Natrium729"}}