35 lines
No EOL
801 B
JavaScript
35 lines
No EOL
801 B
JavaScript
function rollDice() {
|
|
const name = $("name_entry");
|
|
const numDice = $("num_dice");
|
|
const faces = $("dice_faces");
|
|
const note = $("dice_note");
|
|
|
|
if (!conn || !tableKey.name) {
|
|
setErr("Looks like you haven't joined a table yet.");
|
|
return;
|
|
}
|
|
|
|
if (!name || name.value.length < 1) {
|
|
setErr("Who are you? What's your name? Super brother?");
|
|
return;
|
|
}
|
|
|
|
if (numDice && faces && note) {
|
|
const n = Number(numDice.value);
|
|
const d = Number(faces.value);
|
|
r = new Uint8Array(n);
|
|
crypto.getRandomValues(r);
|
|
const rolls = [];
|
|
for (const i of r) {
|
|
rolls.push(i%d + 1)
|
|
}
|
|
publish({diceRoll: {
|
|
faces: d,
|
|
roll: rolls,
|
|
player: name.value,
|
|
note: note.value,
|
|
timestamp: new Date(),
|
|
}});
|
|
note.value = "";
|
|
}
|
|
} |