diff game/js/input.js @ 8:2c4fed8baed9

art update, persistent sound setting, tower selling as double action
author ark
date 2026-10-19 13:37 +0200
parents 910b26feca76
children a77857594150
line wrap: on
line diff
--- a/game/js/input.js	Mon Oct 19 11:50:24 2026 +0200
+++ b/game/js/input.js	Mon Oct 19 13:37:52 2026 +0200
@@ -1,4 +1,5 @@
-// pointer events: mouse and touch alike, nothing relies on hover
+// pointer events: mouse and touch alike. hover only highlights the screen
+// buttons and sets the cursor; nothing relies on it
 
 window.MM = window.MM || {};
 
@@ -19,6 +20,19 @@
             var r = c.getBoundingClientRect();
             tap(app, e.clientX - r.left, e.clientY - r.top);
         });
+        // mouse only: the position for the hover highlight, and the pointer
+        // cursor over buttons
+        c.addEventListener("pointermove", function (e) {
+            if (e.pointerType !== "mouse" || !app.game()) return;
+            var r = c.getBoundingClientRect();
+            var h = { x: e.clientX - r.left, y: e.clientY - r.top };
+            app.view.hover = h;
+            c.style.cursor = MM.ui.hit(app.game(), app.layout(), h.x, h.y) ? "pointer" : "";
+        });
+        c.addEventListener("pointerleave", function () {
+            app.view.hover = null;
+            c.style.cursor = "";
+        });
         // browsers count only some events as a user interaction that may
         // start sound: pointerdown for the mouse, pointerup and touchend
         // for touch
@@ -35,9 +49,13 @@
         var game = app.game(), L = app.layout();
         var b = MM.ui.hit(game, L, x, y);
         if (b) {
-            // the play button starts the sound
+            // the play button starts the sound. switching sound on or off
+            // comes first, so the tap is heard when it goes on
             if (b.id === "play") MM.audio.start();
+            if (b.id === "sound") MM.audio.toggle();
             MM.audio.play("button_tap");
+            // any other button cancels an armed sell
+            if (b.id !== "sell") game.sellArmed = false;
             if (b.id === "play") app.play();
             else if (b.id === "next") app.next();
             else if (b.id === "retry") app.retry();