shithub: puzzles

Download patch

ref: 420663d47790a7e34a1662d679a0c00efdb5b7e5
parent: e5604ccf374f5f586bd933413d33fac8b26a16d5
author: Ben Harris <bjh21@bjh21.me.uk>
date: Sun Dec 4 20:16:16 EST 2022

js: Use current_key_label() to label feature phone softkeys

--- a/emcc.c
+++ b/emcc.c
@@ -56,6 +56,7 @@
 extern void js_get_date_64(unsigned *p);
 extern void js_update_permalinks(const char *desc, const char *seed);
 extern void js_enable_undo_redo(bool undo, bool redo);
+extern void js_update_key_labels(const char *lsk, const char *csk);
 extern void js_activate_timer();
 extern void js_deactivate_timer();
 extern void js_canvas_start_draw(void);
@@ -247,6 +248,8 @@
 static void post_move(void)
 {
     js_enable_undo_redo(midend_can_undo(me), midend_can_redo(me));
+    js_update_key_labels(midend_current_key_label(me, CURSOR_SELECT2),
+                         midend_current_key_label(me, CURSOR_SELECT));
 }
 
 /*
--- a/emcclib.js
+++ b/emcclib.js
@@ -221,6 +221,21 @@
     },
 
     /*
+     * void js_enable_undo_redo(bool undo, bool redo);
+     *
+     * Update any labels for the SoftLeft and Enter keys.
+     */
+    js_update_key_labels: function(lsk_ptr, csk_ptr) {
+        var elem;
+        var lsk_text = UTF8ToString(lsk_ptr);
+        var csk_text = UTF8ToString(csk_ptr);
+        for (elem of document.querySelectorAll("#puzzle .lsk"))
+            elem.textContent = lsk_text == csk_text ? "" : lsk_text;
+        for (elem of document.querySelectorAll("#puzzle .csk"))
+            elem.textContent = csk_text;
+    },
+
+    /*
      * void js_activate_timer();
      *
      * Start calling the C timer_callback() function every frame.
--- a/kaios/apppage.pl
+++ b/kaios/apppage.pl
@@ -293,7 +293,9 @@
   </div>
   <div id="statusbar">
   </div>
-  <div class="softkey"><div class="rsk">Menu</div></div>
+  <div class="softkey">
+    <div class="lsk"></div><div class="csk"></div>
+    <div class="rsk">Menu</div></div>
 </div>
 <form id="gamemenu" class="transient">
  <ul>