changes to dice-box-threejs
All checks were successful
CI / deploy (push) Successful in 5m29s
CI / deploy (pull_request) Successful in 5m36s

This commit is contained in:
2025-02-16 11:06:25 +01:00
parent 5d15976c9f
commit 8524a8674d
122 changed files with 17740 additions and 53839 deletions

View File

@@ -13,56 +13,34 @@
return window.location.protocol + '//' + window.location.hostname + (window.location.port?.length > 0 ? ':' + window.location.port : '');
}
import DiceBox from "/vendor/dice-box/dice-box.es.js";
import DiceBox from "/vendor/dice-box/dice-box-threejs.es.js";
const evtSource = new EventSource(url() + "/dice/{diceid??}/stream");
const diceBox = new DiceBox("#dice-box", {
assetPath: "/vendor/assets/",
theme: 'default',
preloadThemes: [
'default',
'blueGreenMetal',
'diceOfRolling',
'gemstone',
'gemstoneMarble',
'rock',
'rust',
'smooth',
'wooden'
],
scale: {scale}
assetPath: "/vendor/dice-box/",
light_intensity: 2,
gravity_multiplier: 600,
baseScale: {scale} * 10,
strength: Math.floor(Math.random() * 4),
});
document.addEventListener("DOMContentLoaded", async () => {
await diceBox.init()
let timeout = 0;
evtSource.addEventListener("message", function (event) {
clearInterval(timeout);
let data = JSON.parse(event.data);
diceBox.onRollComplete = (rollResult) => {
let httpRequest = new XMLHttpRequest();
httpRequest.open('POST', url() + '/dice/' + data.room + '/results')
httpRequest.setRequestHeader('Content-Type', 'application/json')
httpRequest.send(JSON.stringify({
name: data.name,
user: data.user,
themeColor: data.themeColor,
results: rollResult,
}))
if ({clearAfter} >
0
)
{
timeout = setTimeout(() => diceBox.clear(), {clearAfter} * 1000
)
}
diceBox.initialize();
let timeout = 0;
evtSource.addEventListener("message", function (event) {
clearInterval(timeout);
let data = JSON.parse(event.data);
diceBox.onRollComplete = () => {
if ({clearAfter} > 0) {
timeout = setTimeout(() => diceBox.clearDice(), {clearAfter} * 1000)
}
diceBox.roll(data.roll, {
theme: data.theme?.length > 0 ? data.theme : 'default',
themeColor: data.themeColor.length > 0 ? data.themeColor : '#4545FF'
});
}
diceBox.updateConfig({
theme_customColorset: {
texture: data.theme,
background: data.faceColor,
foreground: data.numberColor
}
}).then(() => {
diceBox.roll(data.roll.join('&'));
})
})
</script>