From 1e46b479e25260cbc73ccda2fc412d60da3585cf Mon Sep 17 00:00:00 2001 From: Le~Kat Date: Sat, 25 Feb 2023 07:52:26 -0500 Subject: [PATCH] toggled the acceleration handler to prevent infinite buzz loop --- apps/multidice/ChangeLog | 1 + apps/multidice/app.js | 236 +++++++++++++++++++---------------- apps/multidice/metadata.json | 2 +- 3 files changed, 127 insertions(+), 112 deletions(-) diff --git a/apps/multidice/ChangeLog b/apps/multidice/ChangeLog index 9bc00d9be..fc6479e98 100644 --- a/apps/multidice/ChangeLog +++ b/apps/multidice/ChangeLog @@ -4,3 +4,4 @@ 1.02: added vibration when dice is rolled 1.03: vibration caused the accelerometer to never stop 1.04: decreased vibration strength +1.05: toggled the acceleration handler to prevent infinite buzz loop diff --git a/apps/multidice/app.js b/apps/multidice/app.js index ef16ca2de..15d9564bc 100644 --- a/apps/multidice/app.js +++ b/apps/multidice/app.js @@ -3,127 +3,141 @@ const DICE_ARRAY = [0, 4, 6, 8, 10, 12, 20, 100]; const SELECTION_ARRAY = [6, 0, 0, 0, 0, 0, 0, 0]; // default to selecting a single d20 function drawMenu() { - - stringArr = new Array ("", "", "", "", "", "", "", ""); - for (i = 0; i < 8; i++) { - - if (SELECTION_ARRAY [i] != 0) { - - stringArr [i] = "" + DICE_ARRAY [SELECTION_ARRAY [i]]; - } - } - - g.clear(); - g.setFont ("Vector", 40); - - g.drawString ((" " + stringArr [0]).slice (-3), 5, 10); - g.drawString ((" " + stringArr [1]).slice (-3), 5, 50); - g.drawString ((" " + stringArr [2]).slice (-3), 5, 90); - g.drawString ((" " + stringArr [3]).slice (-3), 5, 130); - g.drawString ((" " + stringArr [4]).slice (-3), 96, 10); - g.drawString ((" " + stringArr [5]).slice (-3), 96, 50); - g.drawString ((" " + stringArr [6]).slice (-3), 96, 90); - g.drawString ((" " + stringArr [7]).slice (-3), 96, 130); + + stringArr = new Array ("", "", "", "", "", "", "", ""); + for (i = 0; i < 8; i++) { + + if (SELECTION_ARRAY [i] != 0) { + + stringArr [i] = "" + DICE_ARRAY [SELECTION_ARRAY [i]]; + } + } + + g.clear(); + g.setFont ("Vector", 40); + + g.drawString ((" " + stringArr [0]).slice (-3), 5, 10); + g.drawString ((" " + stringArr [1]).slice (-3), 5, 50); + g.drawString ((" " + stringArr [2]).slice (-3), 5, 90); + g.drawString ((" " + stringArr [3]).slice (-3), 5, 130); + g.drawString ((" " + stringArr [4]).slice (-3), 96, 10); + g.drawString ((" " + stringArr [5]).slice (-3), 96, 50); + g.drawString ((" " + stringArr [6]).slice (-3), 96, 90); + g.drawString ((" " + stringArr [7]).slice (-3), 96, 130); } function touchHandler (button, xy) { - - if (! menu) { - - menu = true; - drawMenu(); - return; - } - - if (xy.x <= 87) { // left - - if (xy.y <= 43) { - - selection = 0; - } else if (xy.y <= 87) { - - selection = 1; - } else if (xy.y <= 131) { - - selection = 2; - } else { - - selection = 3; - } - } else { // right - - if (xy.y <= 43) { - - selection = 4; - } else if (xy.y <= 87) { - - selection = 5; - } else if (xy.y <= 131) { - - selection = 6; - } else { - - selection = 7; - } - } - - // increment SELECTION_ARRAY [selection] - if (SELECTION_ARRAY [selection] == 7) { - - SELECTION_ARRAY [selection] = 0; - } else { - - SELECTION_ARRAY [selection] += 1; - } - - drawMenu(); + + if (! menu) { + + menu = true; + drawMenu(); + return; + } + + if (xy.x <= 87) { // left + + if (xy.y <= 43) { + + selection = 0; + } else if (xy.y <= 87) { + + selection = 1; + } else if (xy.y <= 131) { + + selection = 2; + } else { + + selection = 3; + } + } else { // right + + if (xy.y <= 43) { + + selection = 4; + } else if (xy.y <= 87) { + + selection = 5; + } else if (xy.y <= 131) { + + selection = 6; + } else { + + selection = 7; + } + } + + // increment SELECTION_ARRAY [selection] + if (SELECTION_ARRAY [selection] == 7) { + + SELECTION_ARRAY [selection] = 0; + } else { + + SELECTION_ARRAY [selection] += 1; + } + + drawMenu(); +} + +function accelHandler (xyz) { + + if (xyz.diff >= 0.4) { + + menu = false; + rollDice(); + } +} + +function voidFn() { + + return; } function rollDice() { - - resultsArr = new Uint8Array (8); - for (i = 0; i < 8; i++) { - - if (SELECTION_ARRAY [i] != 0) { - - resultsArr [i] = random (DICE_ARRAY [SELECTION_ARRAY [i]]); - } - } - - g.clear(); - g.setFont ("Vector", 40); - - for (i = 0; i < 4; i++) { - - if (SELECTION_ARRAY [i] != 0) { - - g.drawString ((" " + resultsArr [i]).slice (-3), 5, 10 + 40 * i); - } - } - - for (i = 4; i < 8; i++) { - - if (SELECTION_ARRAY [i] != 0) { - - g.drawString ((" " + resultsArr [i]).slice (-3), 96, 10 + 40 * (i - 4)); - } - } - - Bangle.buzz (200, 0.1); + + resultsArr = new Uint8Array (8); + for (i = 0; i < 8; i++) { + + if (SELECTION_ARRAY [i] != 0) { + + resultsArr [i] = random (DICE_ARRAY [SELECTION_ARRAY [i]]); + } + } + + g.clear(); + g.setFont ("Vector", 40); + + for (i = 0; i < 4; i++) { + + if (SELECTION_ARRAY [i] != 0) { + + g.drawString ((" " + resultsArr [i]).slice (-3), 5, 10 + 40 * i); + } + } + + for (i = 4; i < 8; i++) { + + if (SELECTION_ARRAY [i] != 0) { + + g.drawString ((" " + resultsArr [i]).slice (-3), 96, 10 + 40 * (i - 4)); + } + } } function random (max) { - - return Math.round (Math.random() * (max - 1) + 1); + + return Math.round (Math.random() * (max - 1) + 1); +} + +function vibrate() { + + Bangle.on ('accel', voidFn); + Bangle.buzz (200, 0.1).then( + + Bangle.on ('accel', accelHandler) + ); } drawMenu(); Bangle.on ('touch', touchHandler); -Bangle.on ('accel', function (xyz) { - - if (xyz.diff >= 0.4) { - - menu = false; - rollDice(); - } -}); +Bangle.on ('accel', accelHandler); diff --git a/apps/multidice/metadata.json b/apps/multidice/metadata.json index ef5841877..82af0ef8b 100644 --- a/apps/multidice/metadata.json +++ b/apps/multidice/metadata.json @@ -1,7 +1,7 @@ { "id": "multidice", "name": "multiple dice roller", "shortName":"multidice", - "version":"1.04", + "version":"1.05", "description": "roll anywhere from 1-8 dice at the same time", "icon": "app.png", "tags": "tool,game",