updates style & introduces results overlay
This commit is contained in:
39
src/main/resources/templates/results.html
Normal file
39
src/main/resources/templates/results.html
Normal file
@@ -0,0 +1,39 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Results</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="results" style="padding: 25px; font-size: x-large">
|
||||
</div>
|
||||
<script type="module">
|
||||
function url() {
|
||||
return window.location.protocol + '//' + window.location.hostname + (window.location.port?.length > 0 ? ':' + window.location.port : '');
|
||||
}
|
||||
const evtSource = new EventSource(url() + '/dice/{room}/results');
|
||||
evtSource.addEventListener('message', function (event) {
|
||||
let data = JSON.parse(event.data);
|
||||
let name = document.getElementById(data.name) ?? document.createElement('div');
|
||||
name.id = data.name;
|
||||
name.replaceChildren(...[]);
|
||||
let node = document.createElement('p');
|
||||
let resultText = ''
|
||||
if (!data.results) {
|
||||
resultText = ' rolling...'
|
||||
} else {
|
||||
data.results.forEach(result => {
|
||||
let values = []
|
||||
result.rolls.forEach(roll => {
|
||||
values.push(roll.value);
|
||||
})
|
||||
resultText += ' (' + values.join(' + ') + (result.modifier > 0 ? ' <a style="text-decoration: underline">+' + result.modifier + '</a>': result.modifier < 0 ? ' <a style="text-decoration: underline">' + result.modifier + '</a>': '') + ' = <strong style="font-size: x-large">' + result.value + '</strong>) '
|
||||
})
|
||||
}
|
||||
node.innerHTML = '<strong>' + data.name + ':</strong> 🎲 ' + resultText
|
||||
name.appendChild(node)
|
||||
document.getElementById('results').appendChild(name);
|
||||
})
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user