diff --git a/apps/multidice/ChangeLog b/apps/multidice/ChangeLog index 55ed99b4f..6b773d96b 100644 --- a/apps/multidice/ChangeLog +++ b/apps/multidice/ChangeLog @@ -27,3 +27,4 @@ 1.25: god I hope this works 1.26: trying to add timeout after it's done buzzing... again 1.27: OH GOD IT FINALLY WORKS +1.28: increased vibration strength, added some comments, & some QOL diff --git a/apps/multidice/app.js b/apps/multidice/app.js index 474d8fb7c..d0f13ae7c 100644 --- a/apps/multidice/app.js +++ b/apps/multidice/app.js @@ -1,7 +1,8 @@ -var menu = true; -const DICE_ARRAY = [0, 4, 6, 8, 10, 12, 20, 100]; +var menu = true; // default to have the selection menu open +const DICE_ARRAY = [0, 4, 6, 8, 10, 12, 20, 100]; // 0 means nothing selected const SELECTION_ARRAY = [6, 0, 0, 0, 0, 0, 0, 0]; // default to selecting a single d20 +// function to draw the selection menu function drawMenu() { stringArr = new Array ("", "", "", "", "", "", "", ""); @@ -10,12 +11,16 @@ function drawMenu() { if (SELECTION_ARRAY [i] != 0) { stringArr [i] = "" + DICE_ARRAY [SELECTION_ARRAY [i]]; + } else { + + stringArr [i] = " . "; // more clearly defines where the user can tap } } g.clear(); g.setFont ("Vector", 40); + // " ".slice(-3) left-pads all numbers with spaces g.drawString ((" " + stringArr [0]).slice (-3), 5, 10); g.drawString ((" " + stringArr [1]).slice (-3), 5, 50); g.drawString ((" " + stringArr [2]).slice (-3), 5, 90); @@ -26,9 +31,10 @@ function drawMenu() { g.drawString ((" " + stringArr [7]).slice (-3), 96, 130); } +// function to change what dice is selected in the menu function touchHandler (button, xy) { - if (! menu) { + if (! menu) { // if menu isn't open, open it & return menu = true; drawMenu(); @@ -37,38 +43,37 @@ function touchHandler (button, xy) { if (xy.x <= 87) { // left - if (xy.y <= 43) { + if (xy.y <= 43) { // first selection = 0; - } else if (xy.y <= 87) { + } else if (xy.y <= 87) { // second selection = 1; - } else if (xy.y <= 131) { + } else if (xy.y <= 131) { // third selection = 2; - } else { + } else { // fourth selection = 3; } } else { // right - if (xy.y <= 43) { + if (xy.y <= 43) { // first selection = 4; - } else if (xy.y <= 87) { + } else if (xy.y <= 87) { // second selection = 5; - } else if (xy.y <= 131) { + } else if (xy.y <= 131) { // third selection = 6; - } else { + } else { // fourth selection = 7; } } - // increment SELECTION_ARRAY [selection] - if (SELECTION_ARRAY [selection] == 7) { + if (SELECTION_ARRAY [selection] == SELECTION_ARRAY.length - 1) { // if last dice is selected, go back to first SELECTION_ARRAY [selection] = 0; } else { @@ -84,10 +89,14 @@ function accelHandler (xyz) { if (xyz.diff >= 0.3) { menu = false; - mutex (rollDice); + mutex (rollDice).catch (() => { + + return; // not necessary, but prevents spamming the logs + }); } } +// returns a resolved promise if no other mutex call is active, all further ones return a rejected one let lock = false; function mutex (functionRef) { @@ -111,6 +120,7 @@ function mutex (functionRef) { }); } +// function to roll all selected dice, and display them function rollDice() { resultsArr = new Uint8Array (8); @@ -144,16 +154,17 @@ function rollDice() { return vibrate(); } +// triggers the vibration, then pauses before returning function vibrate() { return new Promise ((resolve, reject) => { - return Bangle.buzz (50, 0.5).then ((value) => { + return Bangle.buzz (50, 1).then ((value) => { setTimeout (() => { resolve (value); - }, 150); + }, 200); }); }); } diff --git a/apps/multidice/metadata.json b/apps/multidice/metadata.json index f77e5fab8..c3c144890 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.27", + "version":"1.28", "description": "roll anywhere from 1-8 dice at the same time", "icon": "app.png", "tags": "tool,game",