From 542018cecb74963d73dc8e87c57a2e312619c31c Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Mon, 6 May 2024 22:55:31 +0300 Subject: [PATCH] Fix group weight clamping --- public/index.html | 2 +- public/scripts/world-info.js | 17 ++++++++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/public/index.html b/public/index.html index 1c5d7049e..562b2cd9a 100644 --- a/public/index.html +++ b/public/index.html @@ -5256,7 +5256,7 @@
- +
diff --git a/public/scripts/world-info.js b/public/scripts/world-info.js index 1cce57313..18702235d 100644 --- a/public/scripts/world-info.js +++ b/public/scripts/world-info.js @@ -1478,13 +1478,24 @@ function getWorldEntry(name, data, entry) { groupWeightInput.data('uid', entry.uid); groupWeightInput.on('input', function () { const uid = $(this).data('uid'); - const value = Number($(this).val()); + let value = Number($(this).val()); + const min = Number($(this).attr('min')); + const max = Number($(this).attr('max')); - data.entries[uid].groupWeight = !isNaN(value) ? Math.abs(value) : 0; + // Clamp the value + if (value < min) { + value = min; + $(this).val(min); + } else if (value > max) { + value = max; + $(this).val(max); + } + + data.entries[uid].groupWeight = !isNaN(value) ? Math.abs(value) : 1; setOriginalDataValue(data, uid, 'extensions.group_weight', data.entries[uid].groupWeight); saveWorldInfo(name, data); }); - groupWeightInput.val(entry.groupWeight).trigger('input'); + groupWeightInput.val(entry.groupWeight ?? DEFAULT_WEIGHT).trigger('input'); // probability if (entry.probability === undefined) {