added a drawWidgets command to see if I have the padding right

master
Le~Kat 2023-02-25 20:50:45 -05:00
parent f17c270353
commit ac22a2a2cf
3 changed files with 117 additions and 115 deletions

View File

@ -20,3 +20,4 @@
1.18: decided to keep around the button even while testing, disabled all safety round the accelHandler self-triggering 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.19: added longer delay before resetting accelHandler
1.20: removed all traces of accel b/c I've given up 1.20: removed all traces of accel b/c I've given up
1.21: added a drawWidgets command to see if I have the padding right

View File

@ -4,137 +4,138 @@ const SELECTION_ARRAY = [6, 0, 0, 0, 0, 0, 0, 0]; // default to selecting a sing
function drawMenu() { function drawMenu() {
stringArr = new Array ("", "", "", "", "", "", "", ""); stringArr = new Array ("", "", "", "", "", "", "", "");
for (i = 0; i < 8; i++) { for (i = 0; i < 8; i++) {
if (SELECTION_ARRAY [i] != 0) { if (SELECTION_ARRAY [i] != 0) {
stringArr [i] = "" + DICE_ARRAY [SELECTION_ARRAY [i]]; stringArr [i] = "" + DICE_ARRAY [SELECTION_ARRAY [i]];
} }
} }
g.clear(); g.clear();
g.setFont ("Vector", 40); g.setFont ("Vector", 40);
Bangle.drawWidgets();
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);
g.drawString ((" " + stringArr [3]).slice (-3), 5, 130); g.drawString ((" " + stringArr [3]).slice (-3), 5, 130);
g.drawString ((" " + stringArr [4]).slice (-3), 96, 10); g.drawString ((" " + stringArr [4]).slice (-3), 96, 10);
g.drawString ((" " + stringArr [5]).slice (-3), 96, 50); g.drawString ((" " + stringArr [5]).slice (-3), 96, 50);
g.drawString ((" " + stringArr [6]).slice (-3), 96, 90); g.drawString ((" " + stringArr [6]).slice (-3), 96, 90);
g.drawString ((" " + stringArr [7]).slice (-3), 96, 130); g.drawString ((" " + stringArr [7]).slice (-3), 96, 130);
} }
function touchHandler (button, xy) { function touchHandler (button, xy) {
if (! menu) { if (! menu) {
menu = true; menu = true;
drawMenu(); drawMenu();
return; return;
} }
if (xy.x <= 87) { // left if (xy.x <= 87) { // left
if (xy.y <= 43) { if (xy.y <= 43) {
selection = 0; selection = 0;
} else if (xy.y <= 87) { } else if (xy.y <= 87) {
selection = 1; selection = 1;
} else if (xy.y <= 131) { } else if (xy.y <= 131) {
selection = 2; selection = 2;
} else { } else {
selection = 3; selection = 3;
} }
} else { // right } else { // right
if (xy.y <= 43) { if (xy.y <= 43) {
selection = 4; selection = 4;
} else if (xy.y <= 87) { } else if (xy.y <= 87) {
selection = 5; selection = 5;
} else if (xy.y <= 131) { } else if (xy.y <= 131) {
selection = 6; selection = 6;
} else { } else {
selection = 7; selection = 7;
} }
} }
// increment SELECTION_ARRAY [selection] // increment SELECTION_ARRAY [selection]
if (SELECTION_ARRAY [selection] == 7) { if (SELECTION_ARRAY [selection] == 7) {
SELECTION_ARRAY [selection] = 0; SELECTION_ARRAY [selection] = 0;
} else { } else {
SELECTION_ARRAY [selection] += 1; SELECTION_ARRAY [selection] += 1;
} }
drawMenu(); drawMenu();
} }
function voidFn() { function voidFn() {
return; return;
} }
function rollDice (timeoutFunctionRef) { function rollDice (timeoutFunctionRef) {
resultsArr = new Uint8Array (8); resultsArr = new Uint8Array (8);
for (i = 0; i < 8; i++) { for (i = 0; i < 8; i++) {
if (SELECTION_ARRAY [i] != 0) { if (SELECTION_ARRAY [i] != 0) {
resultsArr [i] = random (DICE_ARRAY [SELECTION_ARRAY [i]]); resultsArr [i] = random (DICE_ARRAY [SELECTION_ARRAY [i]]);
} }
} }
g.clear(); g.clear();
g.setFont ("Vector", 40); g.setFont ("Vector", 40);
for (i = 0; i < 4; i++) { for (i = 0; i < 4; i++) {
if (SELECTION_ARRAY [i] != 0) { if (SELECTION_ARRAY [i] != 0) {
g.drawString ((" " + resultsArr [i]).slice (-3), 5, 10 + 40 * i); g.drawString ((" " + resultsArr [i]).slice (-3), 5, 10 + 40 * i);
} }
} }
for (i = 4; i < 8; i++) { for (i = 4; i < 8; i++) {
if (SELECTION_ARRAY [i] != 0) { if (SELECTION_ARRAY [i] != 0) {
g.drawString ((" " + resultsArr [i]).slice (-3), 96, 10 + 40 * (i - 4)); g.drawString ((" " + resultsArr [i]).slice (-3), 96, 10 + 40 * (i - 4));
} }
} }
vibrate (timeoutFunctionRef); vibrate (timeoutFunctionRef);
} }
function vibrate (timeoutFunctionRef) { function vibrate (timeoutFunctionRef) {
Bangle.buzz(50, 0.5).then (() => { Bangle.buzz(50, 0.5).then (() => {
setTimeout (timeoutFunctionRef, 150); setTimeout (timeoutFunctionRef, 150);
}); });
} }
function random (max) { function random (max) {
return Math.round (Math.random() * (max - 1) + 1); return Math.round (Math.random() * (max - 1) + 1);
} }
drawMenu(); drawMenu();
Bangle.on ('touch', touchHandler); Bangle.on ('touch', touchHandler);
setWatch (function() { setWatch (function() {
menu = false; menu = false;
rollDice (voidFn); rollDice (voidFn);
}, BTN, {repeat: true, edge: "falling", debounce: 10}); }, BTN, {repeat: true, edge: "falling", debounce: 10});

View File

@ -1,7 +1,7 @@
{ "id": "multidice", { "id": "multidice",
"name": "multiple dice roller", "name": "multiple dice roller",
"shortName":"multidice", "shortName":"multidice",
"version":"1.20", "version":"1.21",
"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",