({
take: [
{ type: "number", min: 1, label: "Number of dice" },
{ type: "number", min: 1, label: "Number of sides" },
{ type: "button", action: "make", label: "Roll the dice" },
],
make: ([diceCount, faceCount]) => {
if (diceCount <= 0)
return [{ type: "status", value: 0, message: "No dice!" }]
const result = Array.from({ length: diceCount }, (n, i) => ({
type: "number",
value: 1 + Math.floor(Math.random() * (faceCount - 1)),
label: "Dice " + (i + 1),
}))
if (result.length > 1) {
result.unshift({
type: "number",
value: result.reduce((m, e) => m + e.value, 0),
label: "Total for this dice roll",
})
}
return new Promise((resolve) =>
window.setTimeout(() => resolve(result), 300)
)
},
})