From b41d423837b5afbcf3abb74ec1d8e76d3e9a35c2 Mon Sep 17 00:00:00 2001 From: Arindy Date: Wed, 10 Dec 2025 21:15:59 +0100 Subject: [PATCH] adds support for new "allAllowed" and "showResults" options in chat overlay --- .../arindy/dicetower/ChatOverlayResource.kt | 6 ++-- .../kotlin/de/arindy/dicetower/Templates.kt | 4 ++- .../META-INF/resources/vendor/color-picker.js | 34 +++++++++++-------- src/main/resources/templates/chatoverlay.html | 8 ++--- .../templates/chatoverlayconfig.html | 12 ++++++- 5 files changed, 42 insertions(+), 22 deletions(-) diff --git a/src/main/kotlin/de/arindy/dicetower/ChatOverlayResource.kt b/src/main/kotlin/de/arindy/dicetower/ChatOverlayResource.kt index ef40051..51b7e77 100644 --- a/src/main/kotlin/de/arindy/dicetower/ChatOverlayResource.kt +++ b/src/main/kotlin/de/arindy/dicetower/ChatOverlayResource.kt @@ -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 diff --git a/src/main/kotlin/de/arindy/dicetower/Templates.kt b/src/main/kotlin/de/arindy/dicetower/Templates.kt index 1de4962..1aa4961 100644 --- a/src/main/kotlin/de/arindy/dicetower/Templates.kt +++ b/src/main/kotlin/de/arindy/dicetower/Templates.kt @@ -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 } diff --git a/src/main/resources/META-INF/resources/vendor/color-picker.js b/src/main/resources/META-INF/resources/vendor/color-picker.js index 6cfa0d3..9ac4a12 100644 --- a/src/main/resources/META-INF/resources/vendor/color-picker.js +++ b/src/main/resources/META-INF/resources/vendor/color-picker.js @@ -123,15 +123,15 @@ class ColorPicker extends HTMLElement {
`; @@ -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 ]; } diff --git a/src/main/resources/templates/chatoverlay.html b/src/main/resources/templates/chatoverlay.html index 7fc9680..e1710dd 100644 --- a/src/main/resources/templates/chatoverlay.html +++ b/src/main/resources/templates/chatoverlay.html @@ -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 = '' + user + ' rolls ' + message + ':
[' + values.map(value => value === 1 ? '' + value + '' : value === result.sides ? '' + value + '' : value).join(' + ') + '] = ' + result.total + ' ' }) - document.getElementById('results').showPopover() + if({showResults}) { + document.getElementById('results').showPopover() + } setTimeout(() => { diceBox.clearDice(); document.getElementById('results').hidePopover() diff --git a/src/main/resources/templates/chatoverlayconfig.html b/src/main/resources/templates/chatoverlayconfig.html index be0814c..8227484 100644 --- a/src/main/resources/templates/chatoverlayconfig.html +++ b/src/main/resources/templates/chatoverlayconfig.html @@ -52,6 +52,10 @@ +
@@ -64,6 +68,10 @@ +
@@ -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 } }) -- 2.47.2