This commit is contained in:
parent
18bb994a0f
commit
de0246cd33
@ -15,6 +15,16 @@
|
|||||||
|
|
||||||
import DiceBox from "/vendor/dice-box/dice-box-threejs.es.js";
|
import DiceBox from "/vendor/dice-box/dice-box-threejs.es.js";
|
||||||
|
|
||||||
|
function until(conditionFunction) {
|
||||||
|
|
||||||
|
const poll = resolve => {
|
||||||
|
if(conditionFunction()) resolve();
|
||||||
|
else setTimeout(_ => poll(resolve), 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Promise(poll);
|
||||||
|
}
|
||||||
|
|
||||||
const evtSource = new EventSource(url() + "/dice/{diceid??}/stream");
|
const evtSource = new EventSource(url() + "/dice/{diceid??}/stream");
|
||||||
const diceBox = new DiceBox("#dice-box", {
|
const diceBox = new DiceBox("#dice-box", {
|
||||||
assetPath: "/vendor/dice-box/",
|
assetPath: "/vendor/dice-box/",
|
||||||
@ -25,10 +35,12 @@
|
|||||||
});
|
});
|
||||||
diceBox.initialize();
|
diceBox.initialize();
|
||||||
let timeout = 0;
|
let timeout = 0;
|
||||||
|
let finished = true;
|
||||||
evtSource.addEventListener("message", function (event) {
|
evtSource.addEventListener("message", function (event) {
|
||||||
clearInterval(timeout);
|
clearInterval(timeout);
|
||||||
let data = JSON.parse(event.data);
|
let data = JSON.parse(event.data);
|
||||||
diceBox.onRollComplete = () => {
|
diceBox.onRollComplete = () => {
|
||||||
|
finished = true;
|
||||||
if ({clearAfter} > 0) {
|
if ({clearAfter} > 0) {
|
||||||
timeout = setTimeout(() => diceBox.clearDice(), {clearAfter} * 1000)
|
timeout = setTimeout(() => diceBox.clearDice(), {clearAfter} * 1000)
|
||||||
}
|
}
|
||||||
@ -39,8 +51,9 @@
|
|||||||
background: data.faceColor,
|
background: data.faceColor,
|
||||||
foreground: data.numberColor
|
foreground: data.numberColor
|
||||||
}
|
}
|
||||||
}).then(() => {
|
}).then(async () => {
|
||||||
diceBox.roll(data.roll.filter(it => it.split('@')[0].split('d')[1] !== "2").join('&'));
|
await until(_ => finished)
|
||||||
|
diceBox.add(data.roll.filter(it => it.split('@')[0].split('d')[1] !== "2").join('&'));
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user