Deprecate Dex.prefs for setting prefs

Dex.prefs was always intended to be used only by shared libraries
like the replay player, to access prefs that may or may not actually
be there.

The correct API for setting prefs is `Storage.prefs`.

Other uses of `Dex.prefs` have been left alone mostly because I don't
want to maintain the old client too much. But this should help make
sure people don't use the wrong API in the Preact client going forward.
This commit is contained in:
Guangcong Luo
2020-10-07 16:55:20 -07:00
parent c2fe4b72b4
commit e37f5897af
5 changed files with 48 additions and 48 deletions

View File

@@ -1445,12 +1445,12 @@
},
toggleAllIgnoreSpects: function (e) {
var ignoreSpects = !!e.currentTarget.checked;
Dex.prefs('ignorespects', ignoreSpects);
Storage.prefs('ignorespects', ignoreSpects);
if (ignoreSpects && !this.battle.ignoreSpects) this.$el.find('input[name=ignorespects]').click();
},
toggleIgnoreNicks: function (e) {
this.battle.ignoreNicks = !!e.currentTarget.checked;
Dex.prefs('ignorenicks', this.battle.ignoreNicks);
Storage.prefs('ignorenicks', this.battle.ignoreNicks);
this.battle.add('Nicknames ' + (this.battle.ignoreNicks ? '' : 'no longer ') + 'ignored.');
this.battle.resetToCurrentTurn();
},
@@ -1461,16 +1461,16 @@
},
toggleAllIgnoreOpponent: function (e) {
var ignoreOpponent = !!e.currentTarget.checked;
Dex.prefs('ignoreopp', ignoreOpponent);
Storage.prefs('ignoreopp', ignoreOpponent);
if (ignoreOpponent && !this.battle.ignoreOpponent) this.$el.find('input[name=ignoreopp]').click();
},
toggleAutoTimer: function (e) {
var autoTimer = !!e.currentTarget.checked;
Dex.prefs('autotimer', autoTimer);
Storage.prefs('autotimer', autoTimer);
if (autoTimer) this.room.setTimer('on');
},
toggleRightPanelBattles: function (e) {
Dex.prefs('rightpanelbattles', !!e.currentTarget.checked);
Storage.prefs('rightpanelbattles', !!e.currentTarget.checked);
}
});

View File

@@ -242,7 +242,7 @@
if (Array.isArray(highlights)) {
highlights = {global: highlights};
// Migrate from the old highlight system
Dex.prefs('highlights', highlights);
Storage.prefs('highlights', highlights);
}
if (!Dex.prefs('noselfhighlight') && app.user.nameRegExp) {
if (app.user.nameRegExp.test(message)) return true;
@@ -650,7 +650,7 @@
return false;
case 'showdebug':
this.add('Debug battle messages: ON');
Dex.prefs('showdebug', true);
Storage.prefs('showdebug', true);
var debugStyle = $('#debugstyle').get(0);
var onCSS = '.debug {display: block;}';
if (!debugStyle) {
@@ -661,7 +661,7 @@
return false;
case 'hidedebug':
this.add('Debug battle messages: HIDDEN');
Dex.prefs('showdebug', false);
Storage.prefs('showdebug', false);
var debugStyle = $('#debugstyle').get(0);
var offCSS = '.debug {display: none;}';
if (!debugStyle) {
@@ -687,7 +687,7 @@
this.add('Join/leave messages: ALWAYS ON');
}
showjoins[Config.server.id] = serverShowjoins;
Dex.prefs('showjoins', showjoins);
Storage.prefs('showjoins', showjoins);
return false;
case 'hidejoins':
var showjoins = Dex.prefs('showjoins') || {};
@@ -705,25 +705,25 @@
this.add('Join/leave messages: AUTOMATIC');
}
showjoins[Config.server.id] = serverShowjoins;
Dex.prefs('showjoins', showjoins);
Storage.prefs('showjoins', showjoins);
return false;
case 'showbattles':
this.add('Battle messages: ON');
Dex.prefs('showbattles', true);
Storage.prefs('showbattles', true);
return false;
case 'hidebattles':
this.add('Battle messages: HIDDEN');
Dex.prefs('showbattles', false);
Storage.prefs('showbattles', false);
return false;
case 'unpackhidden':
this.add('Locked/banned users\' chat messages: ON');
Dex.prefs('nounlink', true);
Storage.prefs('nounlink', true);
return false;
case 'packhidden':
this.add('Locked/banned users\' chat messages: HIDDEN');
Dex.prefs('nounlink', false);
Storage.prefs('nounlink', false);
return false;
case 'timestamps':
@@ -754,7 +754,7 @@
break;
}
this.add("Timestamps preference set to: '" + targets[1] + "' for '" + targets[0] + "'.");
Dex.prefs('timestamps', timestamps);
Storage.prefs('timestamps', timestamps);
return false;
case 'hl':
@@ -809,10 +809,10 @@
this.parseCommand('/help highlight'); // show help
return false;
}
Dex.prefs('highlights', highlights);
Storage.prefs('highlights', highlights);
} else {
if (target === 'delete') {
Dex.prefs('highlights', false);
Storage.prefs('highlights', false);
this.updateHighlightRegExp({});
this.add("All highlights cleared");
} else if (['show', 'list', 'roomshow', 'roomlist'].includes(target)) {
@@ -972,7 +972,7 @@
if (window.BattleAvatarNumbers && Object.prototype.hasOwnProperty.call(window.BattleAvatarNumbers, avatar)) {
avatar = window.BattleAvatarNumbers[avatar];
}
Dex.prefs('avatar', avatar);
Storage.prefs('avatar', avatar);
return '/avatar ' + avatar; // Send the command through to the server.
case 'afd':
@@ -1643,7 +1643,7 @@
return; // PMs independently notify in the main menu; no need to make them notify again with `inchatpm`.
}
var lastMessageDates = Dex.prefs('logtimes') || (Dex.prefs('logtimes', {}), Dex.prefs('logtimes'));
var lastMessageDates = Dex.prefs('logtimes') || (Storage.prefs('logtimes', {}), Dex.prefs('logtimes'));
if (!lastMessageDates[Config.server.id]) lastMessageDates[Config.server.id] = {};
var lastMessageDate = lastMessageDates[Config.server.id][this.id] || 0;
// because the time offset to the server can vary slightly, subtract it to not have it affect comparisons between dates

View File

@@ -60,7 +60,7 @@
},
toggleMute: function () {
var muted = !Dex.prefs('mute');
Dex.prefs('mute', muted);
Storage.prefs('mute', muted);
BattleSound.setMute(muted);
app.topbar.$('button[name=openSounds]').html('<i class="' + (muted ? 'fa fa-volume-off' : 'fa fa-volume-up') + '"></i>');
},
@@ -402,7 +402,7 @@
},
setMute: function (e) {
var muted = !!e.currentTarget.checked;
Dex.prefs('mute', muted);
Storage.prefs('mute', muted);
BattleSound.setMute(muted);
if (!muted) {
@@ -419,14 +419,14 @@
},
setEffectVolume: function (volume) {
BattleSound.setEffectVolume(volume);
Dex.prefs('effectvolume', volume);
Storage.prefs('effectvolume', volume);
},
setMusicVolume: function (volume) {
BattleSound.setBgmVolume(volume);
Dex.prefs('musicvolume', volume);
Storage.prefs('musicvolume', volume);
},
setNotifVolume: function (volume) {
Dex.prefs('notifvolume', volume);
Storage.prefs('notifvolume', volume);
}
});
@@ -556,35 +556,35 @@
} else {
Storage.stopLoggingChat();
}
Dex.prefs('logchat', logchat);
Storage.prefs('logchat', logchat);
},
setNoanim: function (e) {
var noanim = !!e.currentTarget.checked;
Dex.prefs('noanim', noanim);
Storage.prefs('noanim', noanim);
Dex.loadSpriteData(noanim || Dex.prefs('bwgfx') ? 'bw' : 'xy');
},
setNogif: function (e) {
var nogif = !!e.currentTarget.checked;
Dex.prefs('nogif', nogif);
Storage.prefs('nogif', nogif);
Dex.loadSpriteData(nogif || Dex.prefs('bwgfx') ? 'bw' : 'xy');
},
setDark: function (e) {
var dark = !!e.currentTarget.checked;
Dex.prefs('dark', dark);
Storage.prefs('dark', dark);
$('html').toggleClass('dark', dark);
},
setBwgfx: function (e) {
var bwgfx = !!e.currentTarget.checked;
Dex.prefs('bwgfx', bwgfx);
Storage.prefs('bwgfx', bwgfx);
Dex.loadSpriteData(bwgfx || Dex.prefs('noanim') ? 'bw' : 'xy');
},
setNopastgens: function (e) {
var nopastgens = !!e.currentTarget.checked;
Dex.prefs('nopastgens', nopastgens);
Storage.prefs('nopastgens', nopastgens);
},
setTournaments: function (e) {
var tournaments = e.currentTarget.value;
Dex.prefs('tournaments', tournaments);
Storage.prefs('tournaments', tournaments);
},
setLanguage: function (e) {
app.user.updateSetting('language', e.currentTarget.value);
@@ -597,35 +597,35 @@
},
setSelfHighlight: function (e) {
var noselfhighlight = !e.currentTarget.checked;
Dex.prefs('noselfhighlight', noselfhighlight);
Storage.prefs('noselfhighlight', noselfhighlight);
},
setInchatpm: function (e) {
var inchatpm = !!e.currentTarget.checked;
Dex.prefs('inchatpm', inchatpm);
Storage.prefs('inchatpm', inchatpm);
},
setTemporaryNotifications: function (e) {
var temporarynotifications = !!e.currentTarget.checked;
Dex.prefs('temporarynotifications', temporarynotifications);
Storage.prefs('temporarynotifications', temporarynotifications);
},
setRefreshprompt: function (e) {
var refreshprompt = !!e.currentTarget.checked;
Dex.prefs('refreshprompt', refreshprompt);
Storage.prefs('refreshprompt', refreshprompt);
},
background: function (e) {
app.addPopup(CustomBackgroundPopup);
},
setOnePanel: function (e) {
app.singlePanelMode = !!e.currentTarget.value;
Dex.prefs('onepanel', !!e.currentTarget.value);
Storage.prefs('onepanel', !!e.currentTarget.value);
app.updateLayout();
},
setTimestampsLobby: function (e) {
this.timestamps.lobby = e.currentTarget.value;
Dex.prefs('timestamps', this.timestamps);
Storage.prefs('timestamps', this.timestamps);
},
setTimestampsPMs: function (e) {
this.timestamps.pms = e.currentTarget.value;
Dex.prefs('timestamps', this.timestamps);
Storage.prefs('timestamps', this.timestamps);
},
avatars: function () {
app.addPopup(AvatarsPopup);
@@ -673,7 +673,7 @@
setOption: function (e) {
var name = $(e.currentTarget).prop('name');
this.chatformatting['hide' + name] = !!e.currentTarget.checked;
Dex.prefs('chatformatting', this.chatformatting);
Storage.prefs('chatformatting', this.chatformatting);
}
});
@@ -701,7 +701,7 @@
}
app.send('/avatar ' + avatar);
app.send('/cmd userdetails ' + app.user.get('userid'));
Dex.prefs('avatar', avatar);
Storage.prefs('avatar', avatar);
this.close();
}
});

View File

@@ -175,7 +175,7 @@ function toId() {
}
});
this.on('change:settings', function () {
Dex.prefs('serversettings', self.get('settings'));
Storage.prefs('serversettings', self.get('settings'));
});
var replaceList = {'A': 'AⱯȺ', 'B': 'BƂƁɃ', 'C': 'CꜾȻ', 'D': 'DĐƋƊƉꝹ', 'E': 'EƐƎ', 'F': 'FƑꝻ', 'G': 'GꞠꝽꝾ', 'H': 'HĦⱧⱵꞍ', 'I': 'IƗ', 'J': 'JɈ', 'K': 'KꞢ', 'L': 'LꝆꞀ', 'M': 'MⱮƜ', 'N': 'NȠƝꞐꞤ', 'O': 'OǪǬØǾƆƟꝊꝌ', 'P': 'PƤⱣꝐꝒꝔ', 'Q': 'QꝖꝘɊ', 'R': 'RɌⱤꝚꞦꞂ', 'S': 'SẞꞨꞄ', 'T': 'TŦƬƮȾꞆ', 'U': 'UɄ', 'V': 'VƲꝞɅ', 'W': 'WⱲ', 'X': '', 'Y': 'YɎỾ', 'Z': 'ZƵȤⱿⱫꝢ', 'a': 'aąⱥɐ', 'b': 'bƀƃɓ', 'c': 'cȼꜿↄ', 'd': 'dđƌɖɗꝺ', 'e': 'eɇɛǝ', 'f': 'fḟƒꝼ', 'g': 'gɠꞡᵹꝿ', 'h': 'hħⱨⱶɥ', 'i': 'iɨı', 'j': 'jɉ', 'k': 'kƙⱪꝁꝃꝅꞣ', 'l': 'lſłƚɫⱡꝉꞁꝇ', 'm': 'mɱɯ', 'n': 'nƞɲʼnꞑꞥ', 'o': 'oǫǭøǿɔꝋꝍɵ', 'p': 'pƥᵽꝑꝓꝕ', 'q': 'qɋꝗꝙ', 'r': 'rɍɽꝛꞧꞃ', 's': 'sꞩꞅẛ', 't': 'tŧƭʈⱦꞇ', 'u': 'uưừứữửựųṷṵʉ', 'v': 'vʋꝟʌ', 'w': 'wⱳ', 'x': '', 'y': 'yɏỿ', 'z': 'zƶȥɀⱬꝣ', 'AA': 'Ꜳ', 'AE': 'ÆǼǢ', 'AO': 'Ꜵ', 'AU': 'Ꜷ', 'AV': 'ꜸꜺ', 'AY': 'Ꜽ', 'DZ': 'DZDŽ', 'Dz': 'DzDž', 'LJ': 'LJ', 'Lj': 'Lj', 'NJ': 'NJ', 'Nj': 'Nj', 'OI': 'Ƣ', 'OO': 'Ꝏ', 'OU': 'Ȣ', 'TZ': 'Ꜩ', 'VY': 'Ꝡ', 'aa': 'ꜳ', 'ae': 'æǽǣ', 'ao': 'ꜵ', 'au': 'ꜷ', 'av': 'ꜹꜻ', 'ay': 'ꜽ', 'dz': 'dzdž', 'hv': 'ƕ', 'lj': 'lj', 'nj': 'nj', 'oi': 'ƣ', 'ou': 'ȣ', 'oo': 'ꝏ', 'ss': 'ß', 'tz': 'ꜩ', 'vy': 'ꝡ'};
@@ -425,8 +425,8 @@ function toId() {
}
// Support legacy tournament setting and migrate to new pref
if (Dex.prefs('notournaments') !== undefined) {
Dex.prefs('tournaments', Dex.prefs('notournaments') ? 'hide' : 'notify');
Dex.prefs('notournaments', null, true);
Storage.prefs('tournaments', Dex.prefs('notournaments') ? 'hide' : 'notify');
Storage.prefs('notournaments', null, true);
}
var autojoin = (Dex.prefs('autojoin') || '');
var autojoinIds = [];
@@ -1885,7 +1885,7 @@ function toId() {
curAutojoin = autojoins.join(',');
}
}
Dex.prefs('autojoin', curAutojoin);
Storage.prefs('autojoin', curAutojoin);
},
playNotificationSound: function () {
@@ -2210,7 +2210,7 @@ function toId() {
if (this.lastMessageDate) {
// Mark chat messages as read to avoid double-notifying on reload
var lastMessageDates = Dex.prefs('logtimes') || (Dex.prefs('logtimes', {}), Dex.prefs('logtimes'));
var lastMessageDates = Dex.prefs('logtimes') || (Storage.prefs('logtimes', {}), Dex.prefs('logtimes'));
if (!lastMessageDates[Config.server.id]) lastMessageDates[Config.server.id] = {};
lastMessageDates[Config.server.id][this.id] = this.lastMessageDate;
Storage.prefs.save();
@@ -2242,7 +2242,7 @@ function toId() {
if (this.lastMessageDate) {
// Mark chat messages as read to avoid double-notifying on reload
var lastMessageDates = Dex.prefs('logtimes') || (Dex.prefs('logtimes', {}), Dex.prefs('logtimes'));
var lastMessageDates = Dex.prefs('logtimes') || (Storage.prefs('logtimes', {}), Dex.prefs('logtimes'));
if (!lastMessageDates[Config.server.id]) lastMessageDates[Config.server.id] = {};
lastMessageDates[Config.server.id][this.id] = this.lastMessageDate;
Storage.prefs.save();

View File

@@ -244,9 +244,9 @@ const Dex = new class implements ModdedDex {
.slice(0, 50);
}
prefs(prop: string, value?: any, save?: boolean) {
prefs(prop: string) {
// @ts-ignore
return window.Storage?.prefs?.(prop, value, save);
return window.Storage?.prefs?.(prop);
}
getShortName(name: string) {