From 43db4aa38e83595dc6df245cb952795f9f306ed0 Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Mon, 24 Apr 2023 10:17:33 +0100 Subject: Support user preferences in the Emscripten frontend. Here, user preferences are stored in localStorage, so that they can persist when you come back to the same puzzle page later. localStorage is global across a whole web server, which means we need to take care to put our uses of it in a namespace reasonably unlikely to collide with unrelated web pages on the same server. Ben suggested that a good way to do this would be to store things in localStorage under keys derived from location.pathname. In this case I've appended a fragment id "#preferences" to that, so that space alongside it remains for storing other things we might want in future (such as serialised saved-game files used as quick-save slots). When loading preferences, I've chosen to pass the whole serialised preferences buffer from Javascript to C as a single C string argument to a callback, rather than reusing the existing system for C to read the save file a chunk at a time. Partly that's because preferences data is bounded in size whereas saved games can keep growing; also it's because the way I'm storing preferences data means it will be a UTF-8 string, and I didn't fancy trying to figure out byte offsets in the data on the JS side. I think at this point I should stop keeping a list in the docs of which frontends support preferences. Most of the in-tree ones do now, and that means the remaining interesting frontends are ones I don't have a full list of. At this moment I guess no out-of-tree frontends support preferences (unless someone is _very_ quick off the mark), but as and when that changes, I won't necessarily know, and don't want to have to keep updating the docs when I find out. --- cmake/platforms/emscripten.cmake | 2 ++ 1 file changed, 2 insertions(+) (limited to 'cmake') diff --git a/cmake/platforms/emscripten.cmake b/cmake/platforms/emscripten.cmake index c84a3c7..d74217f 100644 --- a/cmake/platforms/emscripten.cmake +++ b/cmake/platforms/emscripten.cmake @@ -47,6 +47,8 @@ set(emcc_export_list _restore_puzzle_size # Callback when device pixel ratio changes _rescale_puzzle + # Callback for loading user preferences + _prefs_load_callback # Main program, run at initialisation time _main) -- cgit v1.1