shithub: puzzles

Download patch

ref: 85b00e56a034713a8e34f9e10423ae14dbc810e0
parent: 26a3b98f4f30de1f3faf0bb97eeeb8403864b5d3
author: Ben Harris <bjh21@bjh21.me.uk>
date: Mon Aug 21 18:03:18 EDT 2023

js: prefer some puzzle size even if loading isn't complete

The js_canvas_get_preferred_size() function was declining to suggest a
size for the puzzle if document.readyState wasn't "complete".  I think
my idea here was that if the document wasn't fully loaded then I
couldn't trust the size of the containing <div>.  While this was true,
declining to provide a size didn't help much since the puzzle still
needed a size, and the size of the containing <div> was the best guess
we had.

Now that function always returns the size of the containing <div> if
it exists.  This appears to mean that puzzles don't show a brief flash
of being the wrong size on KaiOS.  That was particularly visible with
Flood, where the wrong-size version had borders around the tiles that
the right-size version lacked.  The containing <div> isn't used on the
standard Web versions, so there's no change to behaviour there.

--- a/emcclib.js
+++ b/emcclib.js
@@ -612,7 +612,7 @@
      * alone and return false.
      */
     js_canvas_get_preferred_size: function(wp, hp) {
-        if (document.readyState == "complete" && containing_div !== null) {
+        if (containing_div !== null) {
             var dpr = window.devicePixelRatio || 1;
             setValue(wp, containing_div.clientWidth * dpr, "i32");
             setValue(hp, containing_div.clientHeight * dpr, "i32");