From 001a35165aa80c125b6db4aa889ac63ae31fdcf0 Mon Sep 17 00:00:00 2001 From: Arindy Date: Mon, 10 Feb 2025 00:26:30 +0100 Subject: [PATCH] reformats results & fixes command parsing --- src/main/kotlin/de/arindy/dicetower/DiceResource.kt | 2 +- src/main/resources/templates/pub/index.html | 2 +- src/main/resources/templates/results.html | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/de/arindy/dicetower/DiceResource.kt b/src/main/kotlin/de/arindy/dicetower/DiceResource.kt index a78ca40..95e528d 100644 --- a/src/main/kotlin/de/arindy/dicetower/DiceResource.kt +++ b/src/main/kotlin/de/arindy/dicetower/DiceResource.kt @@ -29,7 +29,7 @@ final class DiceResource(@Context val sse: Sse) { if (!sseBroadcasters.containsKey(id)) { sseBroadcasters[id] = sse.newBroadcaster() } - data.roll = data.command.split(" ").toTypedArray() + data.roll = data.command.split(" ", "&", "and").filter { it.isNotEmpty() }.map { it.trim() }.toTypedArray() data.room = id.split(":")[0] data.user = id.split(":")[1] sseBroadcasters[id]?.broadcast( diff --git a/src/main/resources/templates/pub/index.html b/src/main/resources/templates/pub/index.html index 95c2340..32ae877 100644 --- a/src/main/resources/templates/pub/index.html +++ b/src/main/resources/templates/pub/index.html @@ -67,7 +67,7 @@


-

Example Commands: "1d6", "2d8 1d100", "5d6+10"

+

Example Commands: "1d6", "2d8 1d100", "1d4 and 1d6", "2d20 & 1d2, "5d6+10"

diff --git a/src/main/resources/templates/results.html b/src/main/resources/templates/results.html index f24a091..3b101aa 100644 --- a/src/main/resources/templates/results.html +++ b/src/main/resources/templates/results.html @@ -27,7 +27,7 @@ result.rolls.forEach(roll => { values.push(roll.value); }) - resultText += ' (' + values.join(' + ') + (result.modifier > 0 ? ' +' + result.modifier + '': result.modifier < 0 ? ' ' + result.modifier + '': '') + ' = ' + result.value + ') ' + resultText += '
  D' + result.sides + ': [' + values.map(value => value === 1 ? '' + value + '' : value === result.sides ? '' + value + '' : value).join(' + ') + (result.modifier > 0 ? ' +' + result.modifier + '': result.modifier < 0 ? ' ' + result.modifier + '': '') + '] = ' + result.value + ' ' }) } node.innerHTML = '' + data.name + ': 🎲 ' + resultText