Optimize game.save.
(cherry picked from commit ee06c2d8d595136c41045687e1679b72594962df)
This commit is contained in:
parent
61cedb172b
commit
c1367cce24
91
game/game.js
91
game/game.js
|
@ -38227,64 +38227,51 @@
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
save:function(key,value,mode){
|
save:(key,value,mode)=>{
|
||||||
if(_status.reloading) return;
|
if(_status.reloading) return;
|
||||||
mode=mode||lib.config.mode;
|
mode=mode||lib.config.mode;
|
||||||
if(!lib.db){
|
if(lib.db){
|
||||||
var config={};
|
if(!key){
|
||||||
if(key){
|
game.putDB('data',mode,get.copy(lib.storage));
|
||||||
try{
|
return;
|
||||||
config=JSON.parse(localStorage.getItem(lib.configprefix+mode));
|
}
|
||||||
if(typeof config!='object') throw 'err';
|
if(mode==lib.config.mode){
|
||||||
}
|
if(value==undefined) delete lib.storage[key];
|
||||||
catch(err){
|
else lib.storage[key]=value;
|
||||||
config={};
|
lib.storage.version=lib.version;
|
||||||
}
|
game.putDB('data',mode,lib.storage);
|
||||||
if(value==undefined){
|
}
|
||||||
delete config[key];
|
else game.getDB('data',mode,config=>{
|
||||||
if(mode==lib.config.mode) delete lib.storage[key];
|
if(!config) config={};
|
||||||
}
|
if(value==undefined) delete config[key];
|
||||||
else{
|
else config[key]=value;
|
||||||
config[key]=value;
|
|
||||||
if(mode==lib.config.mode) lib.storage[key]=value;
|
|
||||||
}
|
|
||||||
config.version=lib.version;
|
config.version=lib.version;
|
||||||
localStorage.setItem(lib.configprefix+mode,JSON.stringify(config));
|
game.putDB('data',mode,config);
|
||||||
}
|
});
|
||||||
else{
|
return;
|
||||||
localStorage.setItem(lib.configprefix+mode,JSON.stringify(lib.storage));
|
}
|
||||||
}
|
if(!key){
|
||||||
|
localStorage.setItem(`${lib.configprefix}${mode}`,JSON.stringify(lib.storage));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let config;
|
||||||
|
try{
|
||||||
|
config=JSON.parse(localStorage.getItem(`${lib.configprefix}${mode}`));
|
||||||
|
if(typeof config!='object') throw 'err';
|
||||||
|
}
|
||||||
|
catch(err){
|
||||||
|
config={};
|
||||||
|
}
|
||||||
|
if(value==undefined){
|
||||||
|
delete config[key];
|
||||||
|
if(mode==lib.config.mode) delete lib.storage[key];
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
if(key){
|
config[key]=value;
|
||||||
if(mode==lib.config.mode){
|
if(mode==lib.config.mode) lib.storage[key]=value;
|
||||||
if(value==undefined){
|
|
||||||
delete lib.storage[key];
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
lib.storage[key]=value;
|
|
||||||
}
|
|
||||||
lib.storage.version=lib.version;
|
|
||||||
game.putDB('data',mode,lib.storage);
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
game.getDB('data',mode,function(config){
|
|
||||||
if(!config) config={};
|
|
||||||
if(value==undefined){
|
|
||||||
delete config[key];
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
config[key]=value;
|
|
||||||
}
|
|
||||||
config.version=lib.version;
|
|
||||||
game.putDB('data',mode,config);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
game.putDB('data',mode,get.copy(lib.storage));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
config.version=lib.version;
|
||||||
|
localStorage.setItem(`${lib.configprefix}${mode}`,JSON.stringify(config));
|
||||||
},
|
},
|
||||||
showChangeLog:()=>{
|
showChangeLog:()=>{
|
||||||
if(lib.version==lib.config.version&&!_status.extensionChangeLog) return;
|
if(lib.version==lib.config.version&&!_status.extensionChangeLog) return;
|
||||||
|
|
Loading…
Reference in New Issue