Define settings using blueprints.
This commit is contained in:
parent
cf71bab92d
commit
58d4bfb948
3 changed files with 122 additions and 63 deletions
|
@ -82,54 +82,54 @@ window.Umi = { UI: {}, Protocol: { SockChat: { Protocol: {} } } };
|
|||
const settings = new MamiSettings('umi-', ctx.events.scopeTo('settings'));
|
||||
ctx.settings = settings;
|
||||
|
||||
settings.define('style', 'string', 'dark');
|
||||
settings.define('compactView', 'boolean', false);
|
||||
settings.define('autoScroll', 'boolean', true);
|
||||
settings.define('closeTabConfirm', 'boolean', false);
|
||||
settings.define('showChannelList', 'boolean', false);
|
||||
settings.define('fancyInfo', 'boolean', true);
|
||||
settings.define('autoCloseUserContext', 'boolean', true);
|
||||
settings.define('enableParser', 'boolean', true);
|
||||
settings.define('enableEmoticons', 'boolean', true);
|
||||
settings.define('autoParseUrls', 'boolean', true);
|
||||
settings.define('preventOverflow', 'boolean', false);
|
||||
settings.define('expandTextBox', 'boolean', false);
|
||||
settings.define('eepromAutoInsert', 'boolean', true);
|
||||
settings.define('autoEmbedV1', 'boolean', false);
|
||||
settings.define('soundEnable', 'boolean', true, false, true);
|
||||
settings.define('soundPack', 'string', 'ajax-chat');
|
||||
settings.define('soundVolume', 'number', 80);
|
||||
settings.define('soundEnableJoin', 'boolean', true);
|
||||
settings.define('soundEnableLeave', 'boolean', true);
|
||||
settings.define('soundEnableError', 'boolean', true);
|
||||
settings.define('soundEnableServer', 'boolean', true);
|
||||
settings.define('soundEnableIncoming', 'boolean', true);
|
||||
settings.define('onlySoundOnMention', 'boolean', false);
|
||||
settings.define('soundEnableOutgoing', 'boolean', true);
|
||||
settings.define('soundEnablePrivate', 'boolean', true);
|
||||
settings.define('soundEnableForceLeave', 'boolean', true);
|
||||
settings.define('minecraft', ['no', 'yes', 'old'], 'no');
|
||||
settings.define('windowsLiveMessenger', 'boolean', false);
|
||||
settings.define('seinfeld', 'boolean', false);
|
||||
settings.define('flashTitle', 'boolean', true);
|
||||
settings.define('showServerMsgInTitle', 'boolean', true);
|
||||
settings.define('onlyConnectWhenVisible', 'boolean', true);
|
||||
settings.define('playJokeSounds', 'boolean', true);
|
||||
settings.define('weeaboo', 'boolean', false);
|
||||
settings.define('motivationalImages', 'boolean', false);
|
||||
settings.define('motivationalVideos', 'boolean', false);
|
||||
settings.define('osuKeys', 'boolean', false);
|
||||
settings.define('osuKeysV2', ['no', 'yes', 'rng'], 'no');
|
||||
settings.define('explosionRadius', 'number', 20);
|
||||
settings.define('dumpPackets', 'boolean', FUTAMI_DEBUG);
|
||||
settings.define('dumpEvents', 'boolean', FUTAMI_DEBUG);
|
||||
settings.define('marqueeAllNames', 'boolean', false);
|
||||
settings.define('tmpDisableOldThemeSys', 'boolean', false, false, true);
|
||||
settings.define('style').default('dark').create();
|
||||
settings.define('compactView').default(false).create();
|
||||
settings.define('autoScroll').default(true).create();
|
||||
settings.define('closeTabConfirm').default(false).create();
|
||||
settings.define('showChannelList').default(false).create();
|
||||
settings.define('fancyInfo').default(true).create();
|
||||
settings.define('autoCloseUserContext').default(true).create();
|
||||
settings.define('enableParser').default(true).create();
|
||||
settings.define('enableEmoticons').default(true).create();
|
||||
settings.define('autoParseUrls').default(true).create();
|
||||
settings.define('preventOverflow').default(false).create();
|
||||
settings.define('expandTextBox').default(false).create();
|
||||
settings.define('eepromAutoInsert').default(true).create();
|
||||
settings.define('autoEmbedV1').default(false).create();
|
||||
settings.define('soundEnable').default(true).critical().create();
|
||||
settings.define('soundPack').default('ajax-chat').create();
|
||||
settings.define('soundVolume').default(80).create();
|
||||
settings.define('soundEnableJoin').default(true).create();
|
||||
settings.define('soundEnableLeave').default(true).create();
|
||||
settings.define('soundEnableError').default(true).create();
|
||||
settings.define('soundEnableServer').default(true).create();
|
||||
settings.define('soundEnableIncoming').default(true).create();
|
||||
settings.define('onlySoundOnMention').default(false).create();
|
||||
settings.define('soundEnableOutgoing').default(true).create();
|
||||
settings.define('soundEnablePrivate').default(true).create();
|
||||
settings.define('soundEnableForceLeave').default(true).create();
|
||||
settings.define('minecraft').type(['no', 'yes', 'old']).default('no').create();
|
||||
settings.define('windowsLiveMessenger').default(false).create();
|
||||
settings.define('seinfeld').default(false).create();
|
||||
settings.define('flashTitle').default(true).create();
|
||||
settings.define('showServerMsgInTitle').default(true).create();
|
||||
settings.define('onlyConnectWhenVisible').default(true).create();
|
||||
settings.define('playJokeSounds').default(true).create();
|
||||
settings.define('weeaboo').default(false).create();
|
||||
settings.define('motivationalImages').default(false).create();
|
||||
settings.define('motivationalVideos').default(false).create();
|
||||
settings.define('osuKeys').default(false).create();
|
||||
settings.define('osuKeysV2').type(['no', 'yes', 'rng']).default('no').create();
|
||||
settings.define('explosionRadius').default(20).create();
|
||||
settings.define('dumpPackets').default(FUTAMI_DEBUG).create();
|
||||
settings.define('dumpEvents').default(FUTAMI_DEBUG).create();
|
||||
settings.define('marqueeAllNames').default(false).create();
|
||||
settings.define('tmpDisableOldThemeSys').default(false).critical().create();
|
||||
|
||||
const noNotifSupport = !('Notification' in window);
|
||||
settings.define('enableNotifications', 'boolean', false, noNotifSupport, true);
|
||||
settings.define('notificationShowMessage', 'boolean', false, noNotifSupport);
|
||||
settings.define('notificationTriggers', 'string', '', noNotifSupport);
|
||||
settings.define('enableNotifications').default(false).immutable(noNotifSupport).critical().create();
|
||||
settings.define('notificationShowMessage').default(false).immutable(noNotifSupport).create();
|
||||
settings.define('notificationTriggers').default('').immutable(noNotifSupport).create();
|
||||
|
||||
|
||||
loadingOverlay.setMessage('Loading sounds...');
|
||||
|
|
|
@ -10,7 +10,7 @@ const MamiSettingsScoped = function(settings, prefix) {
|
|||
prefix += ':';
|
||||
|
||||
return {
|
||||
define: (name, type, fallback, immutable, critical) => settings.define(prefix + name, type, fallback, immutable, critical),
|
||||
define: name => settings.define(prefix + name),
|
||||
info: name => settings.info(prefix + name),
|
||||
names: () => {
|
||||
const filtered = [];
|
||||
|
|
|
@ -108,26 +108,85 @@ const MamiSettings = function(storageOrPrefix, eventTarget) {
|
|||
}
|
||||
};
|
||||
|
||||
const pub = {
|
||||
define: (name, type, fallback, immutable, critical, virtual) => {
|
||||
const settingBlueprint = function(name) {
|
||||
if(typeof name !== 'string')
|
||||
throw 'setting name must be a string';
|
||||
if(typeof type !== 'string' && !Array.isArray(type))
|
||||
throw 'type must be a javascript type or array of valid string values.';
|
||||
|
||||
const checkDefined = () => {
|
||||
if(settings.has(name))
|
||||
throw `setting ${name} has already been defined`;
|
||||
};
|
||||
|
||||
checkDefined();
|
||||
|
||||
let created = false;
|
||||
let type = undefined;
|
||||
let fallback = null;
|
||||
let immutable = false;
|
||||
let critical = false;
|
||||
let virtual = false;
|
||||
|
||||
const checkCreated = () => {
|
||||
if(created)
|
||||
throw 'setting has already been created';
|
||||
};
|
||||
|
||||
const pub = {
|
||||
type: value => {
|
||||
if(typeof value !== 'string' && !Array.isArray(value))
|
||||
throw 'type must be a javascript type or array of valid string values.';
|
||||
|
||||
checkCreated();
|
||||
|
||||
type = value;
|
||||
return pub;
|
||||
},
|
||||
default: value => {
|
||||
checkCreated();
|
||||
fallback = value === undefined ? null : value;
|
||||
|
||||
if(type === undefined)
|
||||
type = typeof fallback;
|
||||
|
||||
return pub;
|
||||
},
|
||||
immutable: value => {
|
||||
checkCreated();
|
||||
immutable = value === undefined || value === true;
|
||||
return pub;
|
||||
},
|
||||
critical: value => {
|
||||
checkCreated();
|
||||
critical = value === undefined || value === true;
|
||||
return pub;
|
||||
},
|
||||
virtual: value => {
|
||||
checkCreated();
|
||||
virtual = value === undefined || value === true;
|
||||
return pub;
|
||||
},
|
||||
create: () => {
|
||||
checkCreated();
|
||||
checkDefined();
|
||||
|
||||
settings.set(name, Object.freeze({
|
||||
name: name,
|
||||
type: type === null ? undefined : type,
|
||||
fallback: fallback === undefined ? null : fallback,
|
||||
immutable: immutable === true,
|
||||
critical: critical === true,
|
||||
type: type,
|
||||
fallback: fallback,
|
||||
immutable: immutable,
|
||||
critical: critical,
|
||||
}));
|
||||
|
||||
if(virtual === true)
|
||||
if(virtual)
|
||||
storage.virtualise(name);
|
||||
},
|
||||
};
|
||||
|
||||
return pub;
|
||||
};
|
||||
|
||||
const pub = {
|
||||
define: name => new settingBlueprint(name),
|
||||
info: name => getSetting(name),
|
||||
names: () => Array.from(settings.keys()),
|
||||
has: name => {
|
||||
|
|
Loading…
Reference in a new issue