Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6fbedd92c7 | ||
| f4ec070f8f | |||
| b41d423837 | |||
|
|
18bb994a0f | ||
|
|
0e0406fa39 | ||
| 37ce450f2c | |||
| 152511b203 | |||
|
|
9e7bb02832 |
2
pom.xml
2
pom.xml
@@ -4,7 +4,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>de.arindy</groupId>
|
||||
<artifactId>dice-tower</artifactId>
|
||||
<version>1.2.5</version>
|
||||
<version>1.2.7</version>
|
||||
|
||||
<properties>
|
||||
<compiler-plugin.version>3.13.0</compiler-plugin.version>
|
||||
|
||||
@@ -21,14 +21,16 @@ class ChatOverlayResource {
|
||||
@QueryParam("modsAllowed") modsAllowed: Boolean = false,
|
||||
@QueryParam("vipAllowed") vipAllowed: Boolean = false,
|
||||
@QueryParam("subsAllowed") subsAllowed: Boolean = false,
|
||||
@QueryParam("allAllowed") allAllowed: Boolean = false,
|
||||
@QueryParam("cmd") cmd: String? = "roll",
|
||||
@QueryParam("theme") theme: String? = "default",
|
||||
@QueryParam("faceColor") faceColor: String? = "#ff0202",
|
||||
@QueryParam("numberColor") numberColor: String? = "#ffffff",
|
||||
@QueryParam("clearAfter") clearAfter: Long? = -1,
|
||||
@QueryParam("timeout") timeout: Long? = -1
|
||||
@QueryParam("timeout") timeout: Long? = -1,
|
||||
@QueryParam("showResults") showResults: Boolean = true
|
||||
): TemplateInstance {
|
||||
return Templates.chatoverlay(channel, scale ?: 7, maxDice ?: 20, modsAllowed, vipAllowed, subsAllowed, cmd ?: "roll", theme ?: "default", faceColor ?: "#ff0202", numberColor ?: "#ffffff", clearAfter ?: 10, timeout ?: 60)
|
||||
return Templates.chatoverlay(channel, scale ?: 7, maxDice ?: 20, modsAllowed, vipAllowed, subsAllowed, allAllowed, cmd ?: "roll", theme ?: "default", faceColor ?: "#ff0202", numberColor ?: "#ffffff", clearAfter ?: 10, timeout ?: 60, showResults)
|
||||
}
|
||||
|
||||
@GET
|
||||
|
||||
@@ -35,27 +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>()
|
||||
var numberOfDice = 0
|
||||
data.command.split(" ", "&", "and").filter { it.isNotEmpty() }.map { it.trim() }.toTypedArray<String>().forEach { command ->
|
||||
val dice = command.split("d")
|
||||
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(amount) { index ->
|
||||
result[index] = (Math.random() * sides[0].toInt() + 1).toInt()
|
||||
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")
|
||||
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(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()))
|
||||
}
|
||||
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) }
|
||||
@@ -64,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()))
|
||||
}
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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
|
||||
@@ -25,11 +25,13 @@ object Templates {
|
||||
modsAllowed: Boolean,
|
||||
vipAllowed: Boolean,
|
||||
subsAllowed: Boolean,
|
||||
allAllowed: Boolean,
|
||||
cmd: String?,
|
||||
theme: String?,
|
||||
faceColor: String?,
|
||||
numberColor: String?,
|
||||
clearAfter: Long?,
|
||||
timeout: Long?
|
||||
timeout: Long?,
|
||||
showResults: Boolean?
|
||||
): TemplateInstance
|
||||
}
|
||||
|
||||
@@ -123,15 +123,15 @@ class ColorPicker extends HTMLElement {
|
||||
<div class="bg-cover" id="controls">
|
||||
<label for="hue">
|
||||
<abbr title="Hue: The color tint.">H</abbr>
|
||||
<input type="range" id="hue" min="0" max="360" value="0">
|
||||
<input type="range" id="hue" min="0" max="360" value="0" step="0.01">
|
||||
</label>
|
||||
<label for="saturation">
|
||||
<abbr title="Saturation: The amount of gray in the color.">S</abbr>
|
||||
<input type="range" id="saturation" min="0" max="100" value="0">
|
||||
<input type="range" id="saturation" min="0" max="100" value="0" step="0.01">
|
||||
</label>
|
||||
<label for="lightness">
|
||||
<abbr title="Lightness: How light or dark the color is.">L</abbr>
|
||||
<input type="range" id="lightness" min="0" max="100" value="0">
|
||||
<input type="range" id="lightness" min="0" max="100" value="0" step="0.01">
|
||||
</label>
|
||||
</div>
|
||||
</div>`;
|
||||
@@ -251,9 +251,9 @@ class ColorPicker extends HTMLElement {
|
||||
*/
|
||||
updateColor() {
|
||||
|
||||
const hue = Math.round( this.hueInput.value );
|
||||
const saturation = Math.round( this.saturationInput.value );
|
||||
const lightness = Math.round( this.lightnessInput.value );
|
||||
const hue = parseFloat( this.hueInput.value );
|
||||
const saturation = parseFloat( this.saturationInput.value );
|
||||
const lightness = parseFloat( this.lightnessInput.value );
|
||||
const hsla = [ hue, saturation, lightness ];
|
||||
|
||||
const rgba = this.HSLAToRGBA( hsla );
|
||||
@@ -324,6 +324,10 @@ class ColorPicker extends HTMLElement {
|
||||
*/
|
||||
setColor( color = 'hsla(60, 100%, 50%, 0.5)' ) {
|
||||
|
||||
if ( /^[0-9A-F]{3,6}$/i.test( color ) ) {
|
||||
color = '#' + color;
|
||||
}
|
||||
|
||||
const rgba = this.colorToRGBA( color );
|
||||
const hsla = this.rgbToHSLA( rgba );
|
||||
|
||||
@@ -484,13 +488,15 @@ class ColorPicker extends HTMLElement {
|
||||
}
|
||||
|
||||
// Calculate hue
|
||||
let hue;
|
||||
if ( max === normalizedR ) {
|
||||
hue = ( ( normalizedG - normalizedB ) / ( max - min ) ) % 6;
|
||||
} else if ( max === normalizedG ) {
|
||||
hue = ( ( normalizedB - normalizedR ) / ( max - min ) + 2 );
|
||||
} else {
|
||||
hue = ( ( normalizedR - normalizedG ) / ( max - min ) + 4 );
|
||||
let hue = 0;
|
||||
if ( max !== min ) {
|
||||
if ( max === normalizedR ) {
|
||||
hue = ( ( normalizedG - normalizedB ) / ( max - min ) ) % 6;
|
||||
} else if ( max === normalizedG ) {
|
||||
hue = ( ( normalizedB - normalizedR ) / ( max - min ) + 2 );
|
||||
} else {
|
||||
hue = ( ( normalizedR - normalizedG ) / ( max - min ) + 4 );
|
||||
}
|
||||
}
|
||||
|
||||
// Convert hue to degrees
|
||||
@@ -500,7 +506,7 @@ class ColorPicker extends HTMLElement {
|
||||
hue += 360;
|
||||
}
|
||||
|
||||
return [ Math.round( hue ), Math.round( saturation * 100 ), Math.round( lightness * 100 ), a ];
|
||||
return [ parseFloat(hue.toFixed(2)), parseFloat((saturation * 100).toFixed(2)), parseFloat((lightness * 100).toFixed(2)), a ];
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -31,9 +31,7 @@
|
||||
//maxDice
|
||||
|
||||
ComfyJS.onCommand = async (user, command, message, flags) => {
|
||||
if ((
|
||||
flags.broadcaster || ({modsAllowed} && flags.mod) || ({vipAllowed} && flags.vip) || ({subsAllowed} && flags.subscriber
|
||||
)) && '{cmd}' === command && !shouldWait() && message.match(/^\d+d(4|6|8|10|12|20|100)$/) && (+message.split('d')[0] <= {maxDice})
|
||||
if ((flags.broadcaster || {allAllowed} || ({modsAllowed} && flags.mod) || ({vipAllowed} && flags.vip) || ({subsAllowed} && flags.subscriber)) && '{cmd}' === command && !shouldWait() && message.match(/^\d+d(4|6|8|10|12|20|100)$/) && (+message.split('d')[0] <= {maxDice})
|
||||
) {
|
||||
toggleWait(true);
|
||||
|
||||
@@ -45,7 +43,9 @@
|
||||
})
|
||||
document.getElementById('results').innerHTML = '<strong>' + user + '</strong> rolls <strong>' + message + '</strong>:<br/> [' + values.map(value => value === 1 ? '<strong style="text-shadow: 2px 2px 10px red">' + value + '</strong>' : value === result.sides ? '<strong style="text-shadow: 2px 2px 10px green">' + value + '</strong>' : value).join(' + ') + '] = <strong>' + result.total + '</strong> '
|
||||
})
|
||||
document.getElementById('results').showPopover()
|
||||
if({showResults}) {
|
||||
document.getElementById('results').showPopover()
|
||||
}
|
||||
setTimeout(() => {
|
||||
diceBox.clearDice();
|
||||
document.getElementById('results').hidePopover()
|
||||
|
||||
@@ -52,6 +52,10 @@
|
||||
<input type="checkbox" id="subsAllowed">
|
||||
<span class="checkmark"></span>
|
||||
</label>
|
||||
<label class="checkbox" id="allAllowed-container">Allow everyone to roll (yes, everyone!!)
|
||||
<input type="checkbox" id="allAllowed">
|
||||
<span class="checkmark"></span>
|
||||
</label>
|
||||
</div>
|
||||
<div>
|
||||
<label for="scale">Dice-Scale </label>
|
||||
@@ -64,6 +68,10 @@
|
||||
<input type="number" id="clearAfter" style="width: 50px; margin-top: 20px" value="10"/>
|
||||
<label for="timeout">Command-timeout (in seconds)</label>
|
||||
<input type="number" id="timeout" style="width: 50px; margin-top: 20px" value="60"/>
|
||||
<label class="checkbox" id="showResults-container">Show Results Overlay
|
||||
<input type="checkbox" id="showResults" checked>
|
||||
<span class="checkmark"></span>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div id="dice-box" style="width: 850px; height: 400px">
|
||||
@@ -244,7 +252,9 @@
|
||||
"&timeout=" + document.getElementById('timeout').value +
|
||||
"&modsAllowed=" + document.getElementById('modsAllowed').checked +
|
||||
"&vipAllowed=" + document.getElementById('vipAllowed').checked +
|
||||
"&subsAllowed=" + document.getElementById('subsAllowed').checked
|
||||
"&subsAllowed=" + document.getElementById('subsAllowed').checked +
|
||||
"&allAllowed=" + document.getElementById('allAllowed').checked +
|
||||
"&showResults=" + document.getElementById('showResults').checked
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
@@ -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 = ''
|
||||
|
||||
Reference in New Issue
Block a user