forgot to switch from hard tabs to soft tabs

pull/2623/head
Le~Kat 2023-02-09 20:10:09 -05:00
parent c4bd98b35d
commit 44dd494c5b
1 changed files with 139 additions and 139 deletions

View File

@ -3,166 +3,166 @@ var diceOpts = {amount: 2, selected: 5}; // TODO: grab values from settings
const DICE_ARRAY = [4, 6, 8, 10, 12, 20, 100]; // TODO: place in settings const DICE_ARRAY = [4, 6, 8, 10, 12, 20, 100]; // TODO: place in settings
function drawMenu() { function drawMenu() {
g.clear(); g.clear();
g.setFont ("6x8", 2); g.setFont ("6x8", 2);
g.drawString ("# of dice:", 5, 5); g.drawString ("# of dice:", 5, 5);
g.drawString (diceOpts.amount, 137, 5); g.drawString (diceOpts.amount, 137, 5);
g.drawString ("dice:", 5, 32); g.drawString ("dice:", 5, 32);
g.drawString (DICE_ARRAY [diceOpts.selected], 137, 32); g.drawString (DICE_ARRAY [diceOpts.selected], 137, 32);
} }
function touchHandler (button, xy) { function touchHandler (button, xy) {
if (menu) { if (menu) {
if (xy.y <= 26) { // selecting number of dice if (xy.y <= 26) { // selecting number of dice
if (xy.x <= 87) { // left edge: decrease if (xy.x <= 87) { // left edge: decrease
if (diceOpts.amount > 1) if (diceOpts.amount > 1)
diceOpts.amount--; diceOpts.amount--;
} else { // right edge: increase } else { // right edge: increase
if (diceOpts.amount < 6) if (diceOpts.amount < 6)
diceOpts.amount++; diceOpts.amount++;
} }
drawMenu(); drawMenu();
} else if (xy.y <= 53) { // selecting dice type } else if (xy.y <= 53) { // selecting dice type
if (xy.x <= 87) { // left edge: decrease if (xy.x <= 87) { // left edge: decrease
if (diceOpts.selected > 0) if (diceOpts.selected > 0)
diceOpts.selected--; diceOpts.selected--;
} else { // right edge: increase } else { // right edge: increase
if (diceOpts.selected < DICE_ARRAY.length - 1) if (diceOpts.selected < DICE_ARRAY.length - 1)
diceOpts.selected++; diceOpts.selected++;
} }
drawMenu(); drawMenu();
} else { } else {
rollDice(); rollDice();
} }
} else { // return to menu screen } else { // return to menu screen
menu = true; menu = true;
drawMenu (); drawMenu ();
} }
} }
function rollDice() { function rollDice() {
menu = false; menu = false;
if (diceOpts.amount == 1) { if (diceOpts.amount == 1) {
let output = random (DICE_ARRAY [diceOpts.selected]); let output = random (DICE_ARRAY [diceOpts.selected]);
g.clear(); g.clear();
g.setFont ("Vector", 90); g.setFont ("Vector", 90);
g.drawString ((" " + output).slice (-3), 10, 0); g.drawString ((" " + output).slice (-3), 10, 0);
} else { } else {
let output = new Int8Array ([-1, -1, -1, -1, -1, -1]); let output = new Int8Array ([-1, -1, -1, -1, -1, -1]);
for (let i = 0; i < diceOpts.amount; i++) { for (let i = 0; i < diceOpts.amount; i++) {
output [i] = random (DICE_ARRAY [diceOpts.selected]); output [i] = random (DICE_ARRAY [diceOpts.selected]);
} }
g.clear(); g.clear();
g.setFont ("Vector", 40); g.setFont ("Vector", 40);
for (let i = 0; i < 3; i++) { // draws all the numbers in two rows for (let i = 0; i < 3; i++) { // draws all the numbers in two rows
if (output [i * 2 + 0] == -1) { if (output [i * 2 + 0] == -1) {
break; break;
} else if (output [i * 2 + 1] == -1) { } else if (output [i * 2 + 1] == -1) {
g.drawString ((" " + output [i * 2]).slice (-3), 5, 5 + i * 40); g.drawString ((" " + output [i * 2]).slice (-3), 5, 5 + i * 40);
} else { } else {
g.drawString ((" " + output [i * 2]).slice (-3) + " " + (" " + output [i * 2 + 1]).slice (-3), 5, 5 + i * 40); g.drawString ((" " + output [i * 2]).slice (-3) + " " + (" " + output [i * 2 + 1]).slice (-3), 5, 5 + i * 40);
} }
} }
g.setFont ("Vector", 20); g.setFont ("Vector", 20);
g.drawString ("H: " + (" " + max (output)).slice (-3), 5, 130); g.drawString ("H: " + (" " + max (output)).slice (-3), 5, 130);
g.drawString ("L: " + (" " + min (output)).slice (-3), 110, 130); g.drawString ("L: " + (" " + min (output)).slice (-3), 110, 130);
g.drawString ("T: " + (" " + total (output)).slice (-3), 5, 150); g.drawString ("T: " + (" " + total (output)).slice (-3), 5, 150);
g.drawString ("A: " + (" " + average (output)).slice (-3), 110, 150); g.drawString ("A: " + (" " + average (output)).slice (-3), 110, 150);
} }
} }
function random (max) { // number is always between 1 and max function random (max) { // number is always between 1 and max
return Math.round (Math.random() * (max - 1) + 1); return Math.round (Math.random() * (max - 1) + 1);
} }
function max (array) { function max (array) {
let max = 0; let max = 0;
for (let i = 0; i < 6; i++) { for (let i = 0; i < 6; i++) {
if (array [i] == -1) if (array [i] == -1)
break; break;
if (array [i] > max) if (array [i] > max)
max = array [i]; max = array [i];
} }
return max; return max;
} }
function min (array) { function min (array) {
let min = array [0]; let min = array [0];
for (let i = 1; i < 6; i++) { for (let i = 1; i < 6; i++) {
if (array [i] == -1) if (array [i] == -1)
break; break;
if (array [i] < min) if (array [i] < min)
min = array [i]; min = array [i];
} }
return min; return min;
} }
function total (array) { function total (array) {
let total = 0; let total = 0;
for (let i = 0; i < 6; i++) { for (let i = 0; i < 6; i++) {
if (array [i] == -1) if (array [i] == -1)
break; break;
total += array [i]; total += array [i];
} }
return total; return total;
} }
function average (array) { function average (array) {
let average = 0; let average = 0;
let rounds = 0; let rounds = 0;
for (let i = 0; i < 6; i++) { for (let i = 0; i < 6; i++) {
if (array [i] == -1) if (array [i] == -1)
break; break;
average += array [i]; average += array [i];
rounds++; rounds++;
} }
return Math.round (average / rounds); return Math.round (average / rounds);
} }
drawMenu(); drawMenu();