increased vibration strength, added some comments, & some QOL
parent
16bcc2ca6c
commit
c3f5fbbd28
|
|
@ -27,3 +27,4 @@
|
||||||
1.25: god I hope this works
|
1.25: god I hope this works
|
||||||
1.26: trying to add timeout after it's done buzzing... again
|
1.26: trying to add timeout after it's done buzzing... again
|
||||||
1.27: OH GOD IT FINALLY WORKS
|
1.27: OH GOD IT FINALLY WORKS
|
||||||
|
1.28: increased vibration strength, added some comments, & some QOL
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,8 @@
|
||||||
var menu = true;
|
var menu = true; // default to have the selection menu open
|
||||||
const DICE_ARRAY = [0, 4, 6, 8, 10, 12, 20, 100];
|
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
|
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() {
|
function drawMenu() {
|
||||||
|
|
||||||
stringArr = new Array ("", "", "", "", "", "", "", "");
|
stringArr = new Array ("", "", "", "", "", "", "", "");
|
||||||
|
|
@ -10,12 +11,16 @@ function drawMenu() {
|
||||||
if (SELECTION_ARRAY [i] != 0) {
|
if (SELECTION_ARRAY [i] != 0) {
|
||||||
|
|
||||||
stringArr [i] = "" + DICE_ARRAY [SELECTION_ARRAY [i]];
|
stringArr [i] = "" + DICE_ARRAY [SELECTION_ARRAY [i]];
|
||||||
|
} else {
|
||||||
|
|
||||||
|
stringArr [i] = " . "; // more clearly defines where the user can tap
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
g.clear();
|
g.clear();
|
||||||
g.setFont ("Vector", 40);
|
g.setFont ("Vector", 40);
|
||||||
|
|
||||||
|
// " ".slice(-3) left-pads all numbers with spaces
|
||||||
g.drawString ((" " + stringArr [0]).slice (-3), 5, 10);
|
g.drawString ((" " + stringArr [0]).slice (-3), 5, 10);
|
||||||
g.drawString ((" " + stringArr [1]).slice (-3), 5, 50);
|
g.drawString ((" " + stringArr [1]).slice (-3), 5, 50);
|
||||||
g.drawString ((" " + stringArr [2]).slice (-3), 5, 90);
|
g.drawString ((" " + stringArr [2]).slice (-3), 5, 90);
|
||||||
|
|
@ -26,9 +31,10 @@ function drawMenu() {
|
||||||
g.drawString ((" " + stringArr [7]).slice (-3), 96, 130);
|
g.drawString ((" " + stringArr [7]).slice (-3), 96, 130);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// function to change what dice is selected in the menu
|
||||||
function touchHandler (button, xy) {
|
function touchHandler (button, xy) {
|
||||||
|
|
||||||
if (! menu) {
|
if (! menu) { // if menu isn't open, open it & return
|
||||||
|
|
||||||
menu = true;
|
menu = true;
|
||||||
drawMenu();
|
drawMenu();
|
||||||
|
|
@ -37,38 +43,37 @@ function touchHandler (button, xy) {
|
||||||
|
|
||||||
if (xy.x <= 87) { // left
|
if (xy.x <= 87) { // left
|
||||||
|
|
||||||
if (xy.y <= 43) {
|
if (xy.y <= 43) { // first
|
||||||
|
|
||||||
selection = 0;
|
selection = 0;
|
||||||
} else if (xy.y <= 87) {
|
} else if (xy.y <= 87) { // second
|
||||||
|
|
||||||
selection = 1;
|
selection = 1;
|
||||||
} else if (xy.y <= 131) {
|
} else if (xy.y <= 131) { // third
|
||||||
|
|
||||||
selection = 2;
|
selection = 2;
|
||||||
} else {
|
} else { // fourth
|
||||||
|
|
||||||
selection = 3;
|
selection = 3;
|
||||||
}
|
}
|
||||||
} else { // right
|
} else { // right
|
||||||
|
|
||||||
if (xy.y <= 43) {
|
if (xy.y <= 43) { // first
|
||||||
|
|
||||||
selection = 4;
|
selection = 4;
|
||||||
} else if (xy.y <= 87) {
|
} else if (xy.y <= 87) { // second
|
||||||
|
|
||||||
selection = 5;
|
selection = 5;
|
||||||
} else if (xy.y <= 131) {
|
} else if (xy.y <= 131) { // third
|
||||||
|
|
||||||
selection = 6;
|
selection = 6;
|
||||||
} else {
|
} else { // fourth
|
||||||
|
|
||||||
selection = 7;
|
selection = 7;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// increment SELECTION_ARRAY [selection]
|
if (SELECTION_ARRAY [selection] == SELECTION_ARRAY.length - 1) { // if last dice is selected, go back to first
|
||||||
if (SELECTION_ARRAY [selection] == 7) {
|
|
||||||
|
|
||||||
SELECTION_ARRAY [selection] = 0;
|
SELECTION_ARRAY [selection] = 0;
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -84,10 +89,14 @@ function accelHandler (xyz) {
|
||||||
if (xyz.diff >= 0.3) {
|
if (xyz.diff >= 0.3) {
|
||||||
|
|
||||||
menu = false;
|
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;
|
let lock = false;
|
||||||
function mutex (functionRef) {
|
function mutex (functionRef) {
|
||||||
|
|
||||||
|
|
@ -111,6 +120,7 @@ function mutex (functionRef) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// function to roll all selected dice, and display them
|
||||||
function rollDice() {
|
function rollDice() {
|
||||||
|
|
||||||
resultsArr = new Uint8Array (8);
|
resultsArr = new Uint8Array (8);
|
||||||
|
|
@ -144,16 +154,17 @@ function rollDice() {
|
||||||
return vibrate();
|
return vibrate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// triggers the vibration, then pauses before returning
|
||||||
function vibrate() {
|
function vibrate() {
|
||||||
|
|
||||||
return new Promise ((resolve, reject) => {
|
return new Promise ((resolve, reject) => {
|
||||||
|
|
||||||
return Bangle.buzz (50, 0.5).then ((value) => {
|
return Bangle.buzz (50, 1).then ((value) => {
|
||||||
|
|
||||||
setTimeout (() => {
|
setTimeout (() => {
|
||||||
|
|
||||||
resolve (value);
|
resolve (value);
|
||||||
}, 150);
|
}, 200);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
{ "id": "multidice",
|
{ "id": "multidice",
|
||||||
"name": "multiple dice roller",
|
"name": "multiple dice roller",
|
||||||
"shortName":"multidice",
|
"shortName":"multidice",
|
||||||
"version":"1.27",
|
"version":"1.28",
|
||||||
"description": "roll anywhere from 1-8 dice at the same time",
|
"description": "roll anywhere from 1-8 dice at the same time",
|
||||||
"icon": "app.png",
|
"icon": "app.png",
|
||||||
"tags": "tool,game",
|
"tags": "tool,game",
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue