Optimize game.saveConfig.
(cherry picked from commit 3b86a39de119067bd5c2342d2050e78fc45782a5)
This commit is contained in:
parent
76422bd9eb
commit
4043bf1271
73
game/game.js
73
game/game.js
|
@ -38387,63 +38387,34 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
saveConfig:function(key,value,local,callback){
|
saveConfig:(key,value,local,callback)=>{
|
||||||
if(_status.reloading) return;
|
if(_status.reloading) return;
|
||||||
if(local){
|
if(local){
|
||||||
var localmode;
|
const localmode=typeof local=='string'?local:lib.config.mode;
|
||||||
if(typeof local=='string'){
|
if(!lib.config.mode_config[localmode]) lib.config.mode_config[localmode]={};
|
||||||
localmode=local;
|
if(value==undefined) delete lib.config.mode_config[localmode][key];
|
||||||
}
|
else lib.config.mode_config[localmode][key]=value;
|
||||||
else{
|
key+=`_mode_config_${localmode}`;
|
||||||
localmode=lib.config.mode;
|
|
||||||
}
|
|
||||||
if(!lib.config.mode_config[localmode]){
|
|
||||||
lib.config.mode_config[localmode]={};
|
|
||||||
}
|
|
||||||
if(value==undefined){
|
|
||||||
delete lib.config.mode_config[localmode][key];
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
lib.config.mode_config[localmode][key]=value;
|
|
||||||
}
|
|
||||||
key+='_mode_config_'+localmode;
|
|
||||||
}
|
}
|
||||||
else{
|
else if(value==undefined) delete lib.config[key];
|
||||||
if(value==undefined){
|
else lib.config[key]=value;
|
||||||
delete lib.config[key];
|
if(lib.db){
|
||||||
}
|
if(value==undefined) game.deleteDB('config',key,callback);
|
||||||
else{
|
else game.putDB('config',key,value,callback);
|
||||||
lib.config[key]=value;
|
return;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if(!lib.db){
|
let config;
|
||||||
var config;
|
try{
|
||||||
try{
|
config=JSON.parse(localStorage.getItem(`${lib.configprefix}config`));
|
||||||
config=JSON.parse(localStorage.getItem(lib.configprefix+'config'));
|
if(!config||typeof config!='object') throw 'err';
|
||||||
if(!config||typeof config!='object') throw 'err'
|
|
||||||
}
|
|
||||||
catch(err){
|
|
||||||
config={};
|
|
||||||
}
|
|
||||||
if(value===undefined){
|
|
||||||
delete config[key];
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
config[key]=value;
|
|
||||||
}
|
|
||||||
localStorage.setItem(lib.configprefix+'config',JSON.stringify(config));
|
|
||||||
if(callback){
|
|
||||||
callback();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else{
|
catch(err){
|
||||||
if(value==undefined){
|
config={};
|
||||||
game.deleteDB('config',key,callback);
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
game.putDB('config',key,value,callback);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
if(value===undefined) delete config[key];
|
||||||
|
else config[key]=value;
|
||||||
|
localStorage.setItem(`${lib.configprefix}config`,JSON.stringify(config));
|
||||||
|
if(callback) callback();
|
||||||
},
|
},
|
||||||
saveConfigValue:key=>game.saveConfig(key,lib.config[key]),
|
saveConfigValue:key=>game.saveConfig(key,lib.config[key]),
|
||||||
saveExtensionConfig:(extension,key,value)=>game.saveConfig(`extension_${extension}_${key}`,value),
|
saveExtensionConfig:(extension,key,value)=>game.saveConfig(`extension_${extension}_${key}`,value),
|
||||||
|
|
Loading…
Reference in New Issue