Added min/max to numeric config values.

This commit is contained in:
flash 2024-04-21 18:58:18 +00:00
parent 36e14399d8
commit a3421af127
2 changed files with 39 additions and 19 deletions

View file

@ -99,7 +99,7 @@ window.Umi = { UI: {} };
settings.define('autoEmbedV1').default(false).create(); settings.define('autoEmbedV1').default(false).create();
settings.define('soundEnable').default(true).critical().create(); settings.define('soundEnable').default(true).critical().create();
settings.define('soundPack').default('').create(); settings.define('soundPack').default('').create();
settings.define('soundVolume').default(80).create(); settings.define('soundVolume').default(80).min(0).max(100).create();
settings.define('soundEnableJoin').default(true).create(); settings.define('soundEnableJoin').default(true).create();
settings.define('soundEnableLeave').default(true).create(); settings.define('soundEnableLeave').default(true).create();
settings.define('soundEnableError').default(true).create(); settings.define('soundEnableError').default(true).create();
@ -121,7 +121,7 @@ window.Umi = { UI: {} };
settings.define('motivationalVideos').default(false).create(); settings.define('motivationalVideos').default(false).create();
settings.define('osuKeys').default(false).create(); settings.define('osuKeys').default(false).create();
settings.define('osuKeysV2').type(['no', 'yes', 'rng']).default('no').create(); settings.define('osuKeysV2').type(['no', 'yes', 'rng']).default('no').create();
settings.define('explosionRadius').default(20).create(); settings.define('explosionRadius').default(20).min(0).create();
settings.define('dumpPackets').default(FUTAMI_DEBUG).create(); settings.define('dumpPackets').default(FUTAMI_DEBUG).create();
settings.define('dumpEvents').default(FUTAMI_DEBUG).create(); settings.define('dumpEvents').default(FUTAMI_DEBUG).create();
settings.define('marqueeAllNames').default(false).create(); settings.define('marqueeAllNames').default(false).create();

View file

@ -71,6 +71,11 @@ const MamiSettings = function(storageOrPrefix, eventTarget) {
if(setting.type === 'number') { if(setting.type === 'number') {
value = parseFloat(value); value = parseFloat(value);
resolved = true; resolved = true;
if(setting.min !== undefined && value < setting.min)
value = setting.min;
else if(setting.max !== undefined && value > setting.max)
value = setting.max;
} else if(setting.type === 'boolean') { } else if(setting.type === 'boolean') {
value = !!value; value = !!value;
resolved = true; resolved = true;
@ -122,11 +127,16 @@ const MamiSettings = function(storageOrPrefix, eventTarget) {
checkDefined(); checkDefined();
let created = false; let created = false;
let type = undefined;
let fallback = null;
let immutable = false;
let critical = false;
let virtual = false; let virtual = false;
const setting = {
name: name,
type: undefined,
fallback: null,
immutable: false,
critical: false,
min: undefined,
max: undefined,
};
const checkCreated = () => { const checkCreated = () => {
if(created) if(created)
@ -140,26 +150,42 @@ const MamiSettings = function(storageOrPrefix, eventTarget) {
checkCreated(); checkCreated();
type = value; setting.type = value;
return pub; return pub;
}, },
default: value => { default: value => {
checkCreated(); checkCreated();
fallback = value === undefined ? null : value; setting.fallback = value === undefined ? null : value;
if(type === undefined) if(setting.type === undefined)
type = typeof fallback; setting.type = typeof setting.fallback;
return pub; return pub;
}, },
immutable: value => { immutable: value => {
checkCreated(); checkCreated();
immutable = value === undefined || value === true; setting.immutable = value === undefined || value === true;
return pub; return pub;
}, },
critical: value => { critical: value => {
checkCreated(); checkCreated();
critical = value === undefined || value === true; setting.critical = value === undefined || value === true;
return pub;
},
min: value => {
checkCreated();
if(typeof value !== 'number')
throw 'value must be a number';
setting.min = value;
return pub;
},
max: value => {
checkCreated();
if(typeof value !== 'number')
throw 'value must be a number';
setting.max = value;
return pub; return pub;
}, },
virtual: value => { virtual: value => {
@ -171,13 +197,7 @@ const MamiSettings = function(storageOrPrefix, eventTarget) {
checkCreated(); checkCreated();
checkDefined(); checkDefined();
settings.set(name, Object.freeze({ settings.set(name, Object.freeze(setting));
name: name,
type: type,
fallback: fallback,
immutable: immutable,
critical: critical,
}));
if(virtual) if(virtual)
storage.virtualise(name); storage.virtualise(name);