mirror of
https://hacklab.nilfm.cc/felt
synced 2024-10-22 14:31:48 +00:00
35 lines
No EOL
895 B
JavaScript
35 lines
No EOL
895 B
JavaScript
function rollDice() {
|
|
const name = document.getElementById("name_entry");
|
|
const numDice = document.getElementById("num_dice");
|
|
const faces = document.getElementById("dice_faces");
|
|
const note = document.getElementById("dice_note");
|
|
|
|
if (conn == null || table == null) {
|
|
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 = "";
|
|
}
|
|
} |