12 Commits
1.2.3 ... 1.2.6

Author SHA1 Message Date
gitea
0e0406fa39 [no ci] release 1.2.6 2025-03-01 11:21:43 +00:00
37ce450f2c Merge pull request 'adds the ability to roll results externally' (#41) from allows-external-results into main
All checks were successful
CI / deploy (push) Successful in 6m3s
Reviewed-on: #41
2025-03-01 12:15:47 +01:00
152511b203 adds the ability to roll results externally
All checks were successful
CI / deploy (push) Successful in 7m26s
CI / deploy (pull_request) Successful in 5m50s
2025-03-01 11:44:09 +01:00
gitea
9e7bb02832 [no ci] prepare new Version 2025-02-22 13:56:35 +00:00
gitea
0a3beb2d74 [no ci] release 1.2.5 2025-02-22 13:56:29 +00:00
67cffae431 Merge pull request 'removes d2 from quickroll and overlay' (#40) from remove-d2 into main
All checks were successful
CI / deploy (push) Successful in 5m48s
Reviewed-on: #40
2025-02-22 14:50:48 +01:00
19ff90284a removes d2 from quickroll and overlay
All checks were successful
CI / deploy (push) Successful in 5m40s
CI / deploy (pull_request) Successful in 5m32s
2025-02-22 14:37:39 +01:00
gitea
6bf306dcc7 [no ci] prepare new Version 2025-02-22 13:15:24 +00:00
gitea
a215647947 [no ci] release 1.2.4 2025-02-22 13:15:16 +00:00
741276e477 Merge pull request 'caps the number of allowed dice' (#39) from limit-number-of-diece into main
All checks were successful
CI / deploy (push) Successful in 6m6s
Reviewed-on: #39
2025-02-22 14:09:17 +01:00
4da0d7b1f0 caps the number of allowed dice
All checks were successful
CI / deploy (push) Successful in 5m39s
CI / deploy (pull_request) Successful in 5m38s
2025-02-22 13:53:49 +01:00
gitea
2ca9ad6f5a [no ci] prepare new Version 2025-02-22 11:44:33 +00:00
9 changed files with 44 additions and 22 deletions

View File

@@ -42,6 +42,8 @@ services:
restart: always
ports:
- "8080:8080"
environment:
DICE_LIMIT: 30 # OPTIONAL: amount of dice allowed to roll (default: 30)
```
Run the container with:
```bash

View File

@@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>de.arindy</groupId>
<artifactId>dice-tower</artifactId>
<version>1.2.3</version>
<version>1.2.6</version>
<properties>
<compiler-plugin.version>3.13.0</compiler-plugin.version>

View File

@@ -14,12 +14,19 @@ import jakarta.ws.rs.sse.OutboundSseEvent
import jakarta.ws.rs.sse.Sse
import jakarta.ws.rs.sse.SseBroadcaster
import jakarta.ws.rs.sse.SseEventSink
import org.eclipse.microprofile.config.inject.ConfigProperty
import java.util.Optional
import java.util.UUID
private const val LIMIT = 30
@Path("/dice/{id}")
@ApplicationScoped
final class DiceResource(@Context val sse: Sse) {
@ConfigProperty(name = "dice.limit")
private lateinit var diceLimit: Optional<Int>
private var eventBuilder: OutboundSseEvent.Builder = sse.newEventBuilder()
private var sseBroadcasters: MutableMap<String, SseBroadcaster> = HashMap()
@@ -28,18 +35,31 @@ final class DiceResource(@Context val sse: Sse) {
fun parseCommand(@PathParam("id") id: String, data: RollPayload) {
data.room = id.split(":")[0]
data.user = id.split(":")[1]
val results = ArrayList<Results>()
if (data.results == null) {
var numberOfDice = 0
data.command.split(" ", "&", "and").filter { it.isNotEmpty() }.map { it.trim() }.toTypedArray<String>().forEach { command ->
val dice = command.split("d")
val result = IntArray(dice[0].toInt())
var amount = dice[0].toInt()
val limit = diceLimit.orElse(LIMIT)
if (limit < numberOfDice + amount) {
amount = limit - numberOfDice
}
numberOfDice += amount
if (amount > 0) {
val result = IntArray(amount)
val sides = dice[1].split("+", "-")
val modifier = if (dice[1].contains("+")) sides[1].toInt() else if (dice[1].contains("+")) -1 * sides[1].toInt() else 0
repeat(dice[0].toInt()) { index ->
repeat(amount) { index ->
result[index] = (Math.random() * sides[0].toInt() + 1).toInt()
}
results.add(Results(sides[0].toInt(), modifier, result.sum() + modifier, result.map { Roll(it) }.toTypedArray()))
}
}
} else {
results.addAll(data.results)
}
val map = results.map { r ->
"${r.rolls.size}d${r.sides}@${
if (r.sides == 100) r.rolls.map { roll -> Roll(roll.value / 10 * 10) }
@@ -48,13 +68,13 @@ final class DiceResource(@Context val sse: Sse) {
}.toTypedArray()
data.roll = map + results.filter { it.sides == 100 }.map { r -> "${r.rolls.size}d10@${r.rolls.map { roll -> Roll(roll.value % 10) }.joinToString(",")}"}.toTypedArray()
if (data.roll.all { it.trim().isNotEmpty() }) {
results(data.room!!, Result(data.name, data.user!!, data.faceColor, null))
}
sseBroadcasters[id]?.broadcast(
eventBuilder.id((UUID.randomUUID()).toString())
.mediaType(MediaType.APPLICATION_JSON_TYPE).data(data).build()
)
if (data.roll.all { it.trim().isNotEmpty() }) {
results(data.room!!, Result(data.name, data.user!!, data.faceColor, null))
}
Thread.sleep(1000)
results(data.room!!, Result(data.name, data.user!!, data.faceColor, results.toTypedArray()))
}

View File

@@ -20,7 +20,7 @@ class OverlayResource {
@GET
@Path("/results")
@Produces(MediaType.TEXT_HTML)
fun results(@PathParam("diceid") room: String, @QueryParam("name") name: String?, @QueryParam("user") user: String?): TemplateInstance {
return Templates.results(room, name ?: "all", user ?: "all")
fun results(@PathParam("diceid") room: String, @QueryParam("name") name: String?): TemplateInstance {
return Templates.results(room, name ?: "all")
}
}

View File

@@ -6,7 +6,7 @@ import io.quarkus.runtime.annotations.RegisterForReflection
data class RollPayload(
val name: String,
var command: String,
var predetermined: Boolean? = false,
val results: Array<DiceResource.Results>?,
val faceColor: String = "white",
val numberColor: String = "white",
val theme: String = "default",

View File

@@ -9,7 +9,7 @@ object Templates {
external fun overlay(diceid: String, scale: Int?, clearAfter: Long?): TemplateInstance
@JvmStatic
external fun results(room: String, name: String?, user: String?): TemplateInstance
external fun results(room: String, name: String?): TemplateInstance
@JvmStatic
external fun index(version: String): TemplateInstance

View File

@@ -89,7 +89,7 @@
<button style="border: transparent; border-radius: 100%; font-size: large; font-weight: bold; height: 50px; width: 50px"
onclick="addDice()">+
</button>
<button style="font-size: large; font-weight: bold;" onclick="rollEasy('d2')">D2</button>
<!--<button style="font-size: large; font-weight: bold;" onclick="rollEasy('d2')">D2</button><-->
<button style="font-size: large; font-weight: bold;" onclick="rollEasy('d4')">D4</button>
<button style="font-size: large; font-weight: bold;" onclick="rollEasy('d6')">D6</button>
<button style="font-size: large; font-weight: bold;" onclick="rollEasy('d8')">D8</button>

View File

@@ -40,7 +40,7 @@
foreground: data.numberColor
}
}).then(() => {
diceBox.roll(data.roll.join('&'));
diceBox.roll(data.roll.filter(it => it.split('@')[0].split('d')[1] !== "2").join('&'));
})
})
</script>

View File

@@ -17,9 +17,9 @@
const evtSource = new EventSource(url() + '/dice/{room}/results');
evtSource.addEventListener('message', function (event) {
let data = JSON.parse(event.data);
if ("{name}" === "all" && "{user}" === "all" || "{name}" === data.name && "{user}" === data.user || "{name}" === "all" && "{user}" === data.user || "{name}" === data.name && "{user}" === "all") {
let name = document.getElementById(data.user + '-' + data.name) ?? document.createElement('div');
name.id = data.user + '-' + data.name;
if ("{name}" === "all" || "{name}" === data.name) {
let name = document.getElementById(data.name) ?? document.createElement('div');
name.id = data.name;
name.replaceChildren(...[]);
let node = document.createElement('p');
let resultText = ''