Compare commits
16 Commits
c8541b209d
...
1.0.0
| Author | SHA1 | Date | |
|---|---|---|---|
| 0299f89901 | |||
|
|
7f7a27a178 | ||
| d9caee420a | |||
|
|
f9893e2a17 | ||
| fdd06978d8 | |||
|
|
13f206ae97 | ||
|
|
827b74ebf1 | ||
| 80d331cdd3 | |||
|
|
0e3d88cd4a | ||
|
|
cb077b50de | ||
|
|
9def3240b2 | ||
|
|
13eacc886d | ||
| af41ff5d78 | |||
|
|
153b25e53f | ||
|
|
2e6267e7b4 | ||
| 7ee16d5f3e |
@@ -26,9 +26,6 @@ final class DiceResource(@Context val sse: Sse) {
|
|||||||
@POST
|
@POST
|
||||||
@Consumes(MediaType.APPLICATION_JSON)
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
fun parseCommand(@PathParam("id") id: String, data: RollPayload) {
|
fun parseCommand(@PathParam("id") id: String, data: RollPayload) {
|
||||||
if (!sseBroadcasters.containsKey(id)) {
|
|
||||||
sseBroadcasters[id] = sse.newBroadcaster()
|
|
||||||
}
|
|
||||||
data.roll = data.command.split(" ", "&", "and").filter { it.isNotEmpty() }.map { it.trim() }.toTypedArray<String>()
|
data.roll = data.command.split(" ", "&", "and").filter { it.isNotEmpty() }.map { it.trim() }.toTypedArray<String>()
|
||||||
data.room = id.split(":")[0]
|
data.room = id.split(":")[0]
|
||||||
data.user = id.split(":")[1]
|
data.user = id.split(":")[1]
|
||||||
@@ -41,6 +38,17 @@ final class DiceResource(@Context val sse: Sse) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@POST
|
||||||
|
@Path("/register")
|
||||||
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
|
fun register(@PathParam("id") id: String, data: Any) {
|
||||||
|
println("id = [${id}], data = [${data}]")
|
||||||
|
sseBroadcasters["register:$id"]?.broadcast(
|
||||||
|
eventBuilder.id((UUID.randomUUID()).toString())
|
||||||
|
.mediaType(MediaType.APPLICATION_JSON_TYPE).data(data).build())
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@POST
|
@POST
|
||||||
@Path("/results")
|
@Path("/results")
|
||||||
@Consumes(MediaType.APPLICATION_JSON)
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
@@ -55,9 +63,7 @@ final class DiceResource(@Context val sse: Sse) {
|
|||||||
@Path("/stream")
|
@Path("/stream")
|
||||||
@Produces(MediaType.SERVER_SENT_EVENTS)
|
@Produces(MediaType.SERVER_SENT_EVENTS)
|
||||||
fun stream(@PathParam("id") id: String, @Context sseEventSink: SseEventSink) {
|
fun stream(@PathParam("id") id: String, @Context sseEventSink: SseEventSink) {
|
||||||
if (!sseBroadcasters.containsKey(id)) {
|
sseBroadcasters[id] = sse.newBroadcaster()
|
||||||
sseBroadcasters[id] = sse.newBroadcaster()
|
|
||||||
}
|
|
||||||
sseBroadcasters[id]?.register(sseEventSink)
|
sseBroadcasters[id]?.register(sseEventSink)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -71,7 +77,17 @@ final class DiceResource(@Context val sse: Sse) {
|
|||||||
sseBroadcasters[id]?.register(sseEventSink)
|
sseBroadcasters[id]?.register(sseEventSink)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GET
|
||||||
|
@Path("/users")
|
||||||
|
@Produces(MediaType.SERVER_SENT_EVENTS)
|
||||||
|
fun users(@PathParam("id") id: String, @Context sseEventSink: SseEventSink) {
|
||||||
|
if (!sseBroadcasters.containsKey("register:$id")) {
|
||||||
|
sseBroadcasters["register:$id"] = sse.newBroadcaster()
|
||||||
|
}
|
||||||
|
sseBroadcasters["register:$id"]?.register(sseEventSink)
|
||||||
|
}
|
||||||
|
|
||||||
@RegisterForReflection
|
@RegisterForReflection
|
||||||
data class Result(val name: String, val user: String, val themeColor: String) {}
|
data class Result(val name: String, val user: String, val themeColor: String)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -61,7 +61,9 @@
|
|||||||
document.addEventListener("DOMContentLoaded", async() => {
|
document.addEventListener("DOMContentLoaded", async() => {
|
||||||
await diceBox.init()
|
await diceBox.init()
|
||||||
|
|
||||||
|
let timeout = 0;
|
||||||
evtSource.addEventListener("message", function (event) {
|
evtSource.addEventListener("message", function (event) {
|
||||||
|
clearInterval(timeout);
|
||||||
let data = JSON.parse(event.data);
|
let data = JSON.parse(event.data);
|
||||||
diceBox.onRollComplete = (rollResult) => {
|
diceBox.onRollComplete = (rollResult) => {
|
||||||
let httpRequest = new XMLHttpRequest();
|
let httpRequest = new XMLHttpRequest();
|
||||||
@@ -74,7 +76,7 @@
|
|||||||
results: rollResult,
|
results: rollResult,
|
||||||
} ))
|
} ))
|
||||||
if ({clearAfter} > 0) {
|
if ({clearAfter} > 0) {
|
||||||
setTimeout(() => diceBox.clear(), {clearAfter} * 1000)
|
timeout = setTimeout(() => diceBox.clear(), {clearAfter} * 1000)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,13 +7,27 @@
|
|||||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
|
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
|
||||||
<script src="/vendor/color-picker.js"></script>
|
<script src="/vendor/color-picker.js"></script>
|
||||||
<style>
|
<style>
|
||||||
.w3-theme-l6 { color:#000 !important; background-color:#999999 !important}
|
.w3-theme-l6 {
|
||||||
.w3-theme-l4 { color:#fff !important; background-color:#666666 !important}
|
color: #000 !important;
|
||||||
.w3-theme-l1 { color:#fff !important; background-color:#333333 !important}
|
background-color: #999999 !important;
|
||||||
|
border-radius: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.w3-theme-l4 {
|
||||||
|
color: #fff !important;
|
||||||
|
background-color: #666666 !important;
|
||||||
|
border-radius: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.w3-theme-l1 {
|
||||||
|
color: #fff !important;
|
||||||
|
background-color: #333333 !important;
|
||||||
|
border-radius: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
.collapsible {
|
.collapsible {
|
||||||
background-color: #333333;
|
background-color: #333333;
|
||||||
color: black;
|
color: black;
|
||||||
cursor: pointer;
|
|
||||||
margin-top: 10px;
|
margin-top: 10px;
|
||||||
padding: 18px;
|
padding: 18px;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
@@ -28,12 +42,26 @@
|
|||||||
display: none;
|
display: none;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
background-color: #999999;
|
background-color: #999999;
|
||||||
color: #000
|
color: #000;
|
||||||
|
border-radius: 10px;
|
||||||
}
|
}
|
||||||
|
|
||||||
button {
|
button {
|
||||||
padding: 10px;
|
padding: 10px;
|
||||||
|
border: #333333 3px solid;
|
||||||
|
border-radius: 10px;
|
||||||
|
background: #333333;
|
||||||
|
color: #fff
|
||||||
}
|
}
|
||||||
|
|
||||||
|
button:hover {
|
||||||
|
background: #444444;
|
||||||
|
}
|
||||||
|
|
||||||
|
button:active {
|
||||||
|
background: #222222;
|
||||||
|
}
|
||||||
|
|
||||||
input {
|
input {
|
||||||
margin: 10px;
|
margin: 10px;
|
||||||
}
|
}
|
||||||
@@ -98,14 +126,20 @@
|
|||||||
width: 5px;
|
width: 5px;
|
||||||
height: 5px;
|
height: 5px;
|
||||||
font-size: large;
|
font-size: large;
|
||||||
|
color: #000
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
.overlayButton:hover {
|
||||||
|
background: transparent;
|
||||||
}
|
}
|
||||||
|
|
||||||
.tooltip {
|
.tooltip {
|
||||||
position: fixed;
|
position: fixed;
|
||||||
border-radius: 0.5rem;
|
border-radius: 0.5rem;
|
||||||
padding: 15px;
|
padding: 15px;
|
||||||
color:#fff !important;
|
color: #fff !important;
|
||||||
background-color:#333333dd !important
|
background-color: #333333dd !important
|
||||||
}
|
}
|
||||||
|
|
||||||
#dice-box {
|
#dice-box {
|
||||||
@@ -122,33 +156,150 @@
|
|||||||
height: 100%;
|
height: 100%;
|
||||||
margin: 20px
|
margin: 20px
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.checkbox {
|
||||||
|
position: relative;
|
||||||
|
padding-left: 100px;
|
||||||
|
margin-bottom: 12px;
|
||||||
|
margin-left: 10px;
|
||||||
|
cursor: pointer;
|
||||||
|
-webkit-user-select: none;
|
||||||
|
-moz-user-select: none;
|
||||||
|
-ms-user-select: none;
|
||||||
|
user-select: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.checkbox input {
|
||||||
|
position: absolute;
|
||||||
|
opacity: 0;
|
||||||
|
cursor: pointer;
|
||||||
|
height: 0;
|
||||||
|
width: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.checkmark {
|
||||||
|
margin-left: 75px;
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
height: 15px;
|
||||||
|
width: 15px;
|
||||||
|
background-color: #eee;
|
||||||
|
}
|
||||||
|
|
||||||
|
.checkbox:hover input ~ .checkmark {
|
||||||
|
background-color: #ccc;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* When the checkbox is checked, add a blue background */
|
||||||
|
.checkbox input:checked ~ .checkmark {
|
||||||
|
background-color: #333333;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Create the checkmark/indicator (hidden when not checked) */
|
||||||
|
.checkmark:after {
|
||||||
|
content: "";
|
||||||
|
position: absolute;
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Show the checkmark when checked */
|
||||||
|
.checkbox input:checked ~ .checkmark:after {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Style the checkmark/indicator */
|
||||||
|
.checkbox .checkmark:after {
|
||||||
|
left: 5px;
|
||||||
|
top: 2px;
|
||||||
|
width: 5px;
|
||||||
|
height: 10px;
|
||||||
|
border: solid white;
|
||||||
|
border-width: 0 3px 3px 0;
|
||||||
|
-webkit-transform: rotate(45deg);
|
||||||
|
-ms-transform: rotate(45deg);
|
||||||
|
transform: rotate(45deg);
|
||||||
|
}
|
||||||
|
|
||||||
|
#snackbar-container {
|
||||||
|
visibility: hidden;
|
||||||
|
position: fixed;
|
||||||
|
width: 100%;
|
||||||
|
z-index: 1;
|
||||||
|
bottom: 200px;
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
#snackbar {
|
||||||
|
visibility: hidden;
|
||||||
|
text-align: center;
|
||||||
|
border-radius: 0.5rem;
|
||||||
|
padding: 15px;
|
||||||
|
color: #fff !important;
|
||||||
|
border: #fff 5px solid;
|
||||||
|
background-color: #333333dd !important
|
||||||
|
}
|
||||||
|
|
||||||
|
#snackbar-container.show {
|
||||||
|
visibility: visible;
|
||||||
|
}
|
||||||
|
|
||||||
|
#snackbar.show {
|
||||||
|
visibility: visible;
|
||||||
|
-webkit-animation: fadein 0.5s, fadeout 0.5s 2.5s;
|
||||||
|
animation: fadein 0.5s, fadeout 0.5s 2.5s;
|
||||||
|
}
|
||||||
|
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body class="w3-theme-l1">
|
<body class="w3-theme-l1">
|
||||||
<div class="w3-container w3-content" style="height: 95vh; display: flex; flex-direction: column; justify-content: space-between; padding: 25px">
|
<div class="w3-container w3-content"
|
||||||
|
style="height: 95vh; display: flex; flex-direction: column; justify-content: space-between; padding: 25px">
|
||||||
<h1 style="text-align: center">Dice-Tower</h1>
|
<h1 style="text-align: center">Dice-Tower</h1>
|
||||||
<div class="w3-panel w3-theme-l4 w3-card w3-display-container" style="padding: 25px; text-align: center; margin-bottom: auto">
|
<div class="w3-panel w3-theme-l4 w3-card w3-display-container"
|
||||||
<label for="name" id="nameLabel">Name </label><input type="text" id="name" style="width: 75%" required onkeyup="start(event)"/><br/>
|
style="padding: 25px; text-align: center; margin-bottom: auto;">
|
||||||
<label for="room" id="roomLabel">Room </label><input type="text" id="room" style="width: 75%" required onkeyup="start(event)"/><br/>
|
<label for="name" id="nameLabel">Name </label><input type="text" id="name" style="width: 50%; margin-top: 20px"
|
||||||
<button id="start" onclick="start()" style="align-self: center">Start</button>
|
required onkeyup="start(event)"/><br/>
|
||||||
|
<label for="room" id="roomLabel">Room </label><input type="text" id="room" style="width: 50%" required
|
||||||
|
onkeyup="start(event)"/><br/>
|
||||||
|
<div>
|
||||||
|
<button id="start" onclick="start()" style="align-self: center; margin-top: 20px">Start 🞂</button>
|
||||||
|
<label class="checkbox" id="gm-container">Join as GM
|
||||||
|
<input type="checkbox" id="gm" style="margin-left: 50px">
|
||||||
|
<span class="checkmark"></span>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div id="dice-tower" hidden class="w3-panel w3-theme-l4 w3-card w3-display-container" style="padding: 25px; margin-bottom: auto">
|
<div id="dice-tower" hidden class="w3-panel w3-theme-l4 w3-card w3-display-container"
|
||||||
<button type="button" class="collapsible" style="color: white; font-weight: bold">Overlay URLs <a>🞃</a></button>
|
style="padding: 25px; margin-bottom: auto">
|
||||||
|
<button type="button" class="collapsible" style="color: white; font-weight: bold">Overlay URLs <a>🞃</a></button>
|
||||||
|
|
||||||
<div class="content">
|
<div class="content">
|
||||||
<div style="display: flex; flex-direction: row; justify-content: space-between; align-items: baseline;">
|
<div id="overlay-urls">
|
||||||
<label for="overlayId">Dice-Overlay <a style="color: red"> (Only open once) </a> </label>
|
<div style="display: flex; flex-direction: row; justify-content: space-between; align-items: baseline;">
|
||||||
<input type="text" readonly id="overlayId" style="flex-grow: 1"/>
|
<label for="overlayId" id="overlayLabel">Dice-Overlay </label>
|
||||||
<button popovertarget="overlay-hint" data-trigger="hover" class="overlayButton">?</button>
|
<input type="text" readonly id="overlayId" style="flex-grow: 1" onclick="copyToClipboard(this.id)"/>
|
||||||
|
<button id="overlay-hint-button" popovertarget="overlay-hint" data-trigger="hover"
|
||||||
|
class="overlayButton">🛈
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div style="display: flex; flex-direction: row; justify-content: space-between; align-items: baseline;"
|
||||||
|
hidden id="all-results-urls">
|
||||||
|
<label for="resultsId">All-Results-Overlay </label>
|
||||||
|
<input type="text" readonly id="resultsId" style="flex-grow: 1" onclick="copyToClipboard(this.id)"/>
|
||||||
|
<button popovertarget="all-results-hint" data-trigger="hover" class="overlayButton">🛈</button>
|
||||||
</div>
|
</div>
|
||||||
<div style="display: flex; flex-direction: row; justify-content: space-between; align-items: baseline;">
|
<div style="display: flex; flex-direction: row; justify-content: space-between; align-items: baseline;">
|
||||||
<label for="resultsId">All-Results-Overlay </label><input type="text" readonly id="resultsId" style="flex-grow: 1"/><button popovertarget="all-results-hint" data-trigger="hover" class="overlayButton">?</button>
|
<label for="myResultsId">My-Results-Overlay </label>
|
||||||
</div>
|
<input type="text" readonly id="myResultsId" style="flex-grow: 1" onclick="copyToClipboard(this.id)"/>
|
||||||
<div style="display: flex; flex-direction: row; justify-content: space-between; align-items: baseline;">
|
<button popovertarget="my-results-hint" data-trigger="hover" class="overlayButton">🛈</button>
|
||||||
<label for="myResultsId">My-Results-Overlay </label><input type="text" readonly id="myResultsId" style="flex-grow: 1"/><button popovertarget="my-results-hint" data-trigger="hover" class="overlayButton">?</button>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<button type="button" class="collapsible" style="color: white; font-weight: bold">Customize Dice <a>🞃</a></button>
|
<button type="button" class="collapsible" style="color: white; font-weight: bold">Customize Dice <a>🞃</a>
|
||||||
|
</button>
|
||||||
<div class="content">
|
<div class="content">
|
||||||
<label for="theme">Theme </label>
|
<label for="theme">Theme </label>
|
||||||
<select name="theme" id="theme" style="margin: 25px">
|
<select name="theme" id="theme" style="margin: 25px">
|
||||||
@@ -162,33 +313,59 @@
|
|||||||
<option value="smooth">Smooth</option>
|
<option value="smooth">Smooth</option>
|
||||||
<option value="wooden">Wooden</option>
|
<option value="wooden">Wooden</option>
|
||||||
</select>
|
</select>
|
||||||
<br/>
|
<color-picker id="themeColor"></color-picker>
|
||||||
<color-picker id="themeColor"></color-picker><br/>
|
|
||||||
<div id="dice-box"></div>
|
<div id="dice-box"></div>
|
||||||
|
|
||||||
<button style="margin-bottom: 20px" id="preview">Preview</button>
|
<button style="margin: 10px" id="preview">Preview 🔎</button>
|
||||||
<button style="margin-bottom: 20px" onclick="saveDice()">Save</button>
|
<button style="margin: 10px" onclick="saveDice()">Save 💾</button>
|
||||||
<button popovertarget="save-dice-hint" data-trigger="hover" class="overlayButton">?</button>
|
<button popovertarget="save-dice-hint" data-trigger="hover" class="overlayButton">🛈</button>
|
||||||
</div><br/>
|
</div>
|
||||||
<p>Example Commands: "1d6", "2d8 1d100", "1d4 and 1d6", "2d20 & 1d2, "5d6+10"</p>
|
<div style="display: flex; flex-direction: row; justify-content: space-between; align-items: center; margin: 20px 25px;">
|
||||||
<label for="command">Command </label><input type="text" id="command" onkeyup="roll(event)"/>
|
<label style="font-size: x-large; font-weight: bold;">Roll </label>
|
||||||
<button hidden id="roll" onclick="roll()">Roll</button><br/><br/>
|
<button style="border: transparent; border-radius: 100%; font-size: x-large; font-weight: bold; height: 50px; width: 50px"
|
||||||
<label for="resultSwitch">Show all results </label>
|
onclick="removeDice()">-
|
||||||
<label class="switch">
|
</button>
|
||||||
<input type="checkbox" id="resultSwitch">
|
<label style="font-size: x-large; font-weight: bold;" id="dice-amount">1</label>
|
||||||
<span class="slider"></span>
|
<button style="border: transparent; border-radius: 100%; font-size: x-large; font-weight: bold; height: 50px; width: 50px"
|
||||||
</label>
|
onclick="addDice()">+
|
||||||
|
</button>
|
||||||
|
<button style="font-size: x-large; font-weight: bold;" onclick="rollEasy('d4')">D4</button>
|
||||||
|
<button style="font-size: x-large; font-weight: bold;" onclick="rollEasy('d6')">D6</button>
|
||||||
|
<button style="font-size: x-large; font-weight: bold;" onclick="rollEasy('d8')">D8</button>
|
||||||
|
<button style="font-size: x-large; font-weight: bold;" onclick="rollEasy('d10')">D10</button>
|
||||||
|
<button style="font-size: x-large; font-weight: bold;" onclick="rollEasy('d12')">D12</button>
|
||||||
|
<button style="font-size: x-large; font-weight: bold;" onclick="rollEasy('d20')">D20</button>
|
||||||
|
<button style="font-size: x-large; font-weight: bold;" onclick="rollEasy('d100')">D100</button>
|
||||||
|
</div>
|
||||||
|
<div style="display: flex; flex-direction: row; justify-content: space-between; align-items: baseline; margin: 20px 25px;">
|
||||||
|
<label for="command">Command </label>
|
||||||
|
<input type="text" id="command" style="flex-grow: 1" onkeyup="roll(event)"/>
|
||||||
|
<button hidden id="roll" onclick="roll()">Roll 🎲</button>
|
||||||
|
<button popovertarget="command-hint" data-trigger="hover" class="overlayButton">🛈</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div style="margin: 20px 25px" id="all-results">
|
||||||
|
<label for="resultSwitch">Show all results </label>
|
||||||
|
<label class="switch">
|
||||||
|
<input type="checkbox" id="resultSwitch">
|
||||||
|
<span class="slider"></span>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div id="results" hidden class="w3-panel w3-theme-l6 w3-card w3-display-container" style="padding: 25px; flex-grow: 1; margin-bottom: auto">
|
<div id="results" hidden class="w3-panel w3-theme-l6 w3-card w3-display-container"
|
||||||
<iframe id="resultFrame" title="results" style="width: 100%; height: 85%; overflow: hidden; border: 0" onload="this.height=this.contentWindow.document.body.scrollHeight;" ></iframe>
|
style="padding: 25px; flex-grow: 1; margin-bottom: auto">
|
||||||
|
<iframe id="resultFrame" title="results" style="width: 100%; height: 85%; overflow: hidden; border: 0"
|
||||||
|
onload="this.height=this.contentWindow.document.body.scrollHeight;"></iframe>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div popover id="overlay-hint" class="tooltip">
|
<div popover id="overlay-hint" class="tooltip">
|
||||||
<p style="color: red; font-weight: bold">Only open Overlay once, unless you want multiple results</p>
|
<p style="color: red; font-weight: bold">Only the last loaded instance of that overlay rolls the dice!</p>
|
||||||
<p>Query Params you can Change:</p>
|
<p>Query Params you can Change:</p>
|
||||||
<ul>
|
<ul>
|
||||||
<li><strong>scale</strong> changes the size of the dice (any value over 1; remove param or set -1 to keep the dice)</li>
|
<li><strong>scale</strong> changes the size of the dice (any value over 1)</li>
|
||||||
<li><strong>clearAfter</strong> time until dice are cleared (in seconds)</li>
|
<li><strong>clearAfter</strong> time until dice are cleared (in seconds; remove param or set -1 to keep the
|
||||||
|
dice)
|
||||||
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
<div popover id="all-results-hint" class="tooltip">
|
<div popover id="all-results-hint" class="tooltip">
|
||||||
@@ -200,13 +377,60 @@
|
|||||||
<div popover id="save-dice-hint" class="tooltip">
|
<div popover id="save-dice-hint" class="tooltip">
|
||||||
This saves your current theme and theme color for current Name
|
This saves your current theme and theme color for current Name
|
||||||
</div>
|
</div>
|
||||||
|
<div popover id="command-hint" class="tooltip">
|
||||||
|
Example Commands: "1d6", "2d8 1d100", "1d4 and 1d6", "2d20 & 1d2, "5d6+10"
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div style="margin-top: 20px; flex-grow: 1" id="how-to">
|
||||||
|
<div class="w3-panel w3-theme-l4 w3-card w3-display-container" style="padding: 25px; margin-bottom: auto">
|
||||||
|
<h2 style="text-align: center">How-To</h2>
|
||||||
|
<ul>
|
||||||
|
<li>
|
||||||
|
Join a room by entering your character name and the name of the room.<br/>
|
||||||
|
<strong>If you are a GM, make sure to join the room first or let all other players rejoin to get all
|
||||||
|
Overlay-URLs.</strong>
|
||||||
|
</li>
|
||||||
|
|
||||||
|
<li>Open your Dice-Overlay either in a new Tab or as a browser source in OBS</li>
|
||||||
|
<ul>
|
||||||
|
<li style="color: red; font-weight: bold">Only the last loaded instance of that overlay rolls the
|
||||||
|
dice!
|
||||||
|
</li>
|
||||||
|
<li>You can configure your Overlay with query parameters (more information at the info element next
|
||||||
|
to the link)
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
<li>Configure your dice</li>
|
||||||
|
<li>Save your dice configuration</li>
|
||||||
|
<li>Start rolling</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div id="snackbar-container">
|
||||||
|
<div id="snackbar">.. they see them rolling</div>
|
||||||
</div>
|
</div>
|
||||||
<script>
|
<script>
|
||||||
|
function addDice() {
|
||||||
|
let amount = +document.getElementById('dice-amount').innerText
|
||||||
|
document.getElementById('dice-amount').innerText = amount + 1
|
||||||
|
}
|
||||||
|
|
||||||
|
function removeDice() {
|
||||||
|
let amount = +document.getElementById('dice-amount').innerText
|
||||||
|
if (amount > 1) {
|
||||||
|
document.getElementById('dice-amount').innerText = amount - 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function url() {
|
function url() {
|
||||||
return window.location.protocol + '//' + window.location.hostname + (window.location.port?.length > 0 ? ':' + window.location.port : '');
|
return window.location.protocol + '//' + window.location.hostname + (window.location.port?.length > 0 ? ':' + window.location.port : '');
|
||||||
}
|
}
|
||||||
|
|
||||||
function start(event) {
|
function start(event) {
|
||||||
if((!event || event.keyCode === 13) && document.getElementById('name').value.length > 0 && document.getElementById('room').value.length > 0) {
|
console.log(document.getElementById('gm').checked)
|
||||||
|
|
||||||
|
if ((!event || event.keyCode === 13) && document.getElementById('name').value.length > 0 && document.getElementById('room').value.length > 0) {
|
||||||
document.getElementById('overlayId').value = url() + '/overlay/' + document.getElementById('room').value + ':' + localStorage.getItem('userId') + '?scale=7&clearAfter=30';
|
document.getElementById('overlayId').value = url() + '/overlay/' + document.getElementById('room').value + ':' + localStorage.getItem('userId') + '?scale=7&clearAfter=30';
|
||||||
document.getElementById('resultsId').value = url() + '/overlay/' + document.getElementById('room').value + '/results';
|
document.getElementById('resultsId').value = url() + '/overlay/' + document.getElementById('room').value + '/results';
|
||||||
document.getElementById('myResultsId').value = document.getElementById('resultsId').value + '?name=' + encodeURIComponent(document.getElementById('name').value) + '&user=' + localStorage.getItem('userId');
|
document.getElementById('myResultsId').value = document.getElementById('resultsId').value + '?name=' + encodeURIComponent(document.getElementById('name').value) + '&user=' + localStorage.getItem('userId');
|
||||||
@@ -216,9 +440,14 @@
|
|||||||
document.getElementById('dice-tower').hidden = false;
|
document.getElementById('dice-tower').hidden = false;
|
||||||
document.getElementById('name').hidden = true;
|
document.getElementById('name').hidden = true;
|
||||||
document.getElementById('room').hidden = true;
|
document.getElementById('room').hidden = true;
|
||||||
|
document.getElementById('gm-container').hidden = true;
|
||||||
|
document.getElementById('how-to').hidden = true;
|
||||||
document.getElementById('results').hidden = false;
|
document.getElementById('results').hidden = false;
|
||||||
|
document.getElementById('all-results').hidden = !document.getElementById('gm').checked;
|
||||||
|
document.getElementById('all-results-urls').style.display = document.getElementById('gm').checked ? 'fles' : 'none';
|
||||||
document.getElementById('nameLabel').innerHTML = '<strong style="font-size:x-large;">' + document.getElementById('name').value + '</strong>';
|
document.getElementById('nameLabel').innerHTML = '<strong style="font-size:x-large;">' + document.getElementById('name').value + '</strong>';
|
||||||
document.getElementById('roomLabel').innerHTML = '<strong style="font-size:medium;">' + document.getElementById('room').value + '</strong>';
|
document.getElementById('roomLabel').innerHTML = '<strong style="font-size:medium;">' + document.getElementById('room').value + '</strong>';
|
||||||
|
document.getElementById('overlayLabel').innerHTML = 'Dice-Overlay for <strong>' + document.getElementById('name').value + '</strong>';
|
||||||
document.title = document.getElementById('name').value + ' - Dice-Tower';
|
document.title = document.getElementById('name').value + ' - Dice-Tower';
|
||||||
|
|
||||||
if (localStorage.getItem(document.getElementById('name').value + "-theme")) {
|
if (localStorage.getItem(document.getElementById('name').value + "-theme")) {
|
||||||
@@ -227,11 +456,58 @@
|
|||||||
if (localStorage.getItem(document.getElementById('name').value + "-themeColor")) {
|
if (localStorage.getItem(document.getElementById('name').value + "-themeColor")) {
|
||||||
document.getElementById('themeColor').setColor(localStorage.getItem(document.getElementById('name').value + "-themeColor"));
|
document.getElementById('themeColor').setColor(localStorage.getItem(document.getElementById('name').value + "-themeColor"));
|
||||||
}
|
}
|
||||||
|
let httpRequest = new XMLHttpRequest();
|
||||||
|
httpRequest.open('POST', url() + '/dice/' + document.getElementById('room').value + '/register')
|
||||||
|
httpRequest.setRequestHeader('Content-Type', 'application/json')
|
||||||
|
httpRequest.send(JSON.stringify({
|
||||||
|
name: document.getElementById('name').value,
|
||||||
|
overlay: document.getElementById('overlayId').value,
|
||||||
|
id: document.getElementById('room').value + ':' + localStorage.getItem('userId')
|
||||||
|
}))
|
||||||
|
if (document.getElementById('gm').checked) {
|
||||||
|
document.getElementById('resultSwitch').checked = true;
|
||||||
|
document.getElementById('resultFrame').src = document.getElementById('resultsId').value;
|
||||||
|
const evtSource = new EventSource(url() + '/dice/' + document.getElementById('room').value + '/users');
|
||||||
|
evtSource.addEventListener('message', function (event) {
|
||||||
|
let data = JSON.parse(event.data);
|
||||||
|
if (data.id !== document.getElementById('room').value + ':' + localStorage.getItem('userId')) {
|
||||||
|
let overlays = document.getElementById('overlay-urls');
|
||||||
|
let newOverlay = document.getElementById(data.id) ?? document.createElement('div');
|
||||||
|
newOverlay.replaceChildren(...[]);
|
||||||
|
newOverlay.id = data.id;
|
||||||
|
newOverlay.style.display = "flex";
|
||||||
|
newOverlay.style.flexDirection = "row";
|
||||||
|
newOverlay.style.justifyContent = "space-between";
|
||||||
|
newOverlay.style.alignItems = "baseline";
|
||||||
|
let newLabel = document.createElement('label');
|
||||||
|
newLabel.for = data.id + 'url';
|
||||||
|
newLabel.innerHTML = "Dice-Overlay for <strong>" + data.name + "</strong>";
|
||||||
|
let newInput = document.createElement('input');
|
||||||
|
newInput.type = "text";
|
||||||
|
newInput.readOnly = true;
|
||||||
|
newInput.id = data.id + 'url';
|
||||||
|
newInput.style.flexGrow = '1';
|
||||||
|
newInput.value = data.overlay;
|
||||||
|
newInput.onclick = () => copyToClipboard(newInput.id)
|
||||||
|
let hint = document.getElementById('overlay-hint-button').cloneNode(true);
|
||||||
|
newOverlay.appendChild(newLabel);
|
||||||
|
newOverlay.appendChild(newInput);
|
||||||
|
newOverlay.appendChild(hint);
|
||||||
|
overlays.appendChild(newOverlay);
|
||||||
|
}
|
||||||
|
showPopover();
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function rollEasy(dice) {
|
||||||
|
document.getElementById('command').value = document.getElementById('dice-amount').innerText + dice;
|
||||||
|
roll();
|
||||||
|
}
|
||||||
|
|
||||||
function roll(event) {
|
function roll(event) {
|
||||||
if((!event || event.keyCode === 13) && document.getElementById('command').value?.length > 0) {
|
if ((!event || event.keyCode === 13) && document.getElementById('command').value?.length > 0) {
|
||||||
let httpRequest = new XMLHttpRequest();
|
let httpRequest = new XMLHttpRequest();
|
||||||
httpRequest.open('POST', url() + '/dice/' + document.getElementById('room').value + ':' + localStorage.getItem(`userId`))
|
httpRequest.open('POST', url() + '/dice/' + document.getElementById('room').value + ':' + localStorage.getItem(`userId`))
|
||||||
httpRequest.setRequestHeader('Content-Type', 'application/json')
|
httpRequest.setRequestHeader('Content-Type', 'application/json')
|
||||||
@@ -240,7 +516,7 @@
|
|||||||
command: document.getElementById('command').value,
|
command: document.getElementById('command').value,
|
||||||
themeColor: document.getElementById('themeColor').value,
|
themeColor: document.getElementById('themeColor').value,
|
||||||
theme: document.getElementById('theme').value
|
theme: document.getElementById('theme').value
|
||||||
} ))
|
}))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -264,20 +540,24 @@
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const popover = document.querySelectorAll("[popovertarget][data-trigger='hover']");
|
function showPopover() {
|
||||||
|
const popover = document.querySelectorAll("[popovertarget][data-trigger='hover']");
|
||||||
|
|
||||||
popover.forEach((e) => {
|
popover.forEach((e) => {
|
||||||
const target = document.querySelector("#" + e.getAttribute("popovertarget"));
|
const target = document.querySelector("#" + e.getAttribute("popovertarget"));
|
||||||
e.addEventListener("mouseover",()=>{
|
e.addEventListener("mouseover", () => {
|
||||||
target.showPopover();
|
target.showPopover();
|
||||||
|
});
|
||||||
|
|
||||||
|
e.addEventListener("mouseout", () => {
|
||||||
|
target.hidePopover();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
e.addEventListener("mouseout",()=>{
|
showPopover();
|
||||||
target.hidePopover();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
document.getElementById('resultSwitch').addEventListener('change', function() {
|
document.getElementById('resultSwitch').addEventListener('change', function () {
|
||||||
if (!this.checked) {
|
if (!this.checked) {
|
||||||
document.getElementById('resultFrame').src = document.getElementById('myResultsId').value;
|
document.getElementById('resultFrame').src = document.getElementById('myResultsId').value;
|
||||||
} else {
|
} else {
|
||||||
@@ -285,15 +565,36 @@
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
document.addEventListener("DOMContentLoaded", async() => {
|
document.addEventListener("DOMContentLoaded", async () => {
|
||||||
if (!localStorage.getItem("userId")) {
|
if (!localStorage.getItem("userId")) {
|
||||||
localStorage.setItem("userId", self.crypto.randomUUID());
|
localStorage.setItem("userId", self.crypto.randomUUID());
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
function copyToClipboard(id) {
|
||||||
|
let copyText = document.getElementById(id);
|
||||||
|
copyText.select();
|
||||||
|
copyText.setSelectionRange(0, 99999);
|
||||||
|
navigator.clipboard.writeText(copyText.value);
|
||||||
|
showSnackbar("Link copied to clipboard: <br/>" + copyText.value);
|
||||||
|
}
|
||||||
|
|
||||||
|
function showSnackbar(message) {
|
||||||
|
let snackbar = document.getElementById("snackbar");
|
||||||
|
let snackbarContainer = document.getElementById("snackbar-container");
|
||||||
|
snackbar.innerHTML = message;
|
||||||
|
snackbar.className = "show";
|
||||||
|
snackbarContainer.className = "show";
|
||||||
|
setTimeout(function () {
|
||||||
|
snackbar.className = snackbar.className.replace("show", "");
|
||||||
|
snackbarContainer.className = snackbarContainer.className.replace("show", "");
|
||||||
|
}, 5000);
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
<script type="module">
|
<script type="module">
|
||||||
import DiceBox from "/vendor/dice-box/dice-box.es.js";
|
import DiceBox from "/vendor/dice-box/dice-box.es.js";
|
||||||
document.addEventListener("DOMContentLoaded", async() => {
|
|
||||||
|
document.addEventListener("DOMContentLoaded", async () => {
|
||||||
document.getElementById('preview').onclick = async () => {
|
document.getElementById('preview').onclick = async () => {
|
||||||
document.getElementById('dice-box').replaceChildren(...[])
|
document.getElementById('dice-box').replaceChildren(...[])
|
||||||
const diceBox = new DiceBox("#dice-box", {
|
const diceBox = new DiceBox("#dice-box", {
|
||||||
@@ -303,13 +604,14 @@
|
|||||||
scale: 14
|
scale: 14
|
||||||
});
|
});
|
||||||
await diceBox.init()
|
await diceBox.init()
|
||||||
diceBox.roll(['1d2','1d4','1d6','1d8','1d10','1d12','1d20','1d100']);
|
diceBox.roll(['1d2', '1d4', '1d6', '1d8', '1d10', '1d12', '1d20', '1d100']);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
<footer class="w3-theme-l1 w3-center w3-padding-16">
|
<footer class="w3-theme-l1 w3-center w3-padding-16">
|
||||||
<a href="https://git.arindy.de/arindy/dice-tower" target="_blank" class="w3-hover-text-black">Dice-Tower on my GitTea</a>
|
<a href="https://git.arindy.de/arindy/dice-tower" target="_blank" class="w3-hover-text-black">Dice-Tower on my
|
||||||
|
GitTea</a>
|
||||||
</footer>
|
</footer>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@@ -31,7 +31,7 @@
|
|||||||
resultText += '<br/>  D' + result.sides + ': [' + values.map(value => value === 1 ? '<strong style="color: red">' + value + '</strong>' : value === result.sides ? '<strong style="color: green">' + value + '</strong>' : value).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> '
|
resultText += '<br/>  D' + result.sides + ': [' + values.map(value => value === 1 ? '<strong style="color: red">' + value + '</strong>' : value === result.sides ? '<strong style="color: green">' + value + '</strong>' : value).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 style="text-shadow: 2px 2px 10px ' + data.themeColor + ';">' + data.name + ':</strong> 🎲 ' + resultText
|
node.innerHTML = '<strong style="text-shadow: 2px 2px 10px ' + data.themeColor + ';">' + data.name + ':</strong> 🎲 ' + resultText
|
||||||
name.appendChild(node)
|
name.appendChild(node)
|
||||||
document.getElementById('results').insertBefore(name, document.getElementById('results').firstChild);
|
document.getElementById('results').insertBefore(name, document.getElementById('results').firstChild);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user