Fix group weight clamping

This commit is contained in:
Cohee 2024-05-06 22:55:31 +03:00
parent 5e7c214c89
commit 542018cecb
2 changed files with 15 additions and 4 deletions

View File

@ -5256,7 +5256,7 @@
</small>
</div>
<div class="range-block-range">
<input type="number" class="text_pole margin0" name="groupWeight" rows="1" placeholder="100" min="0" max="999999">
<input type="number" class="text_pole margin0" name="groupWeight" rows="1" placeholder="100" min="1" max="999999">
</div>
</div>
</div>

View File

@ -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) {