diff --git a/apps/multidice/ChangeLog b/apps/multidice/ChangeLog index c47d4c8ff..ba0f62269 100644 --- a/apps/multidice/ChangeLog +++ b/apps/multidice/ChangeLog @@ -19,3 +19,4 @@ 1.17: made changes to when accelHandler gets overwritten, temporarily disabled button usage 1.18: decided to keep around the button even while testing, disabled all safety round the accelHandler self-triggering 1.19: added longer delay before resetting accelHandler +1.20: removed all traces of accel b/c I've given up diff --git a/apps/multidice/README.md b/apps/multidice/README.md index 2d28ef33f..d80ed7ef1 100644 --- a/apps/multidice/README.md +++ b/apps/multidice/README.md @@ -5,8 +5,8 @@ roll anywhere from 1-8 dice at the same time. ## Usage -On the menu screen: tap on the dice to change what variant is selected, & shake the watch in order to roll those dice -On the dice screen: tap anywhere on the screen to go back to the menu, or shake to roll the dice again +On the menu screen: tap on the dice to change what variant is selected, & press the button to roll the dice +On the dice screen: tap anywhere on the screen to go back to the menu, or press the button to roll the dice ## Features @@ -14,4 +14,5 @@ roll anywhere from 1-8 dice (d4, d6, d8, d10, d12, d20, & d percentile). You can ## Controls -No button is used in the app, it simply uses touch controls & the accelerometor +App uses touchscreen to cycle through different dice, and BTN to roll them +(W.I.P. using acceleration to roll dice) diff --git a/apps/multidice/app.js b/apps/multidice/app.js index 82561853e..01f39751d 100644 --- a/apps/multidice/app.js +++ b/apps/multidice/app.js @@ -3,153 +3,138 @@ 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(); -} - -function accelHandler (xyz) { - - if (xyz.diff >= 0.3) { - - Bangle.on ('accel', voidFn); // temporarily disable more acceleration events - - menu = false; - rollDice (function() { - - Bangle.on ('accel', accelHandler); // re-enable acceleration events - }); - } + + 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 voidFn() { - - return; + + return; } function rollDice (timeoutFunctionRef) { - - 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)); - } - } - - vibrate (timeoutFunctionRef); + + 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)); + } + } + + vibrate (timeoutFunctionRef); } function vibrate (timeoutFunctionRef) { - - Bangle.buzz(50, 0.5).then (() => { - - setTimeout (timeoutFunctionRef, 150); - }); + + Bangle.buzz(50, 0.5).then (() => { + + setTimeout (timeoutFunctionRef, 150); + }); } function random (max) { - - return Math.round (Math.random() * (max - 1) + 1); + + return Math.round (Math.random() * (max - 1) + 1); } drawMenu(); Bangle.on ('touch', touchHandler); -Bangle.on ('accel', accelHandler); setWatch (function() { - - menu = false; - rollDice (voidFn); - + + menu = false; + rollDice (voidFn); + }, BTN, {repeat: true, edge: "falling", debounce: 10});