diff game/js/input.js @ 13:8df95050fc8b

no more build during pause; tower popup closes on any click outside it
author ark
date 2026-10-19 21:59 +0200
parents a77857594150
children c1c7e4f54bf6
line wrap: on
line diff
--- a/game/js/input.js	Mon Oct 19 20:41:45 2026 +0200
+++ b/game/js/input.js	Mon Oct 19 21:59:53 2026 +0200
@@ -100,8 +100,10 @@
             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
+            // any other button cancels an armed sell, and any button outside
+            // the tower menu closes it
             if (b.id !== "sell") game.sellArmed = false;
+            if (b.id !== "sell" && b.id !== "upgrade") game.selected = null;
             if (b.id === "play") app.play();
             else if (b.id === "next") app.next();
             else if (b.id === "retry") app.retry();
@@ -109,14 +111,18 @@
             else if (b.id === "pause") game.togglePause();
             else if (b.id === "speed") game.speedIndex = (game.speedIndex + 1) % game.speeds.length;
             else if (b.id === "early") game.startEarly();
-            else if (b.id === "shop" && game.canAfford(MM.config.tower[b.tower].cost)) game.chooseShop(b.tower);
+            else if (b.id === "shop" && !game.paused && game.canAfford(MM.config.tower[b.tower].cost)) game.chooseShop(b.tower);
             else if (b.id === "upgrade") game.upgrade();
             else if (b.id === "sell") game.sell();
             return null;
         }
-        if (game.result || game.splash) return null;
+        if (game.result || game.paused) return null;
         var m = mapPos(game, L, x, y);
-        if (!m) return null;
+        if (!m) {
+            game.sellArmed = false;
+            game.selected = null;
+            return null;
+        }
         var hitR = Math.max(MM.config.placement.footprint_radius, PREVIEW_HIT / L.scale);
         var kind = game.pressMap(m.x, m.y, hitR);
         if (!kind) return null;
@@ -150,7 +156,7 @@
     // preview builds; a drag that never found a legal position is refused
     function release(app, d, x, y) {
         var game = app.game(), L = app.layout();
-        if (game !== d.game || game.result) return;
+        if (game !== d.game || game.result || game.paused) return;
         var ok = d.onPreview && !d.moved ? game.build() : d.found;
         if (ok) return;
         MM.audio.play("placement_refused");