fixed a storage problem

This commit is contained in:
libccy 2015-04-29 16:41:00 +08:00
parent 0b9697e821
commit 3a61ee0774
11 changed files with 57 additions and 122 deletions

View File

@ -275,7 +275,7 @@ window.config={
guozhan:{ guozhan:{
double_hp:'pingjun', double_hp:'pingjun',
difficulty:'normal', difficulty:'normal',
initshow_draw:0, initshow_draw:2,
dierestart:true dierestart:true
} }
}, },

View File

@ -151,82 +151,15 @@ window.play={};
lib.config.defaultcards=lib.config.cards.slice(0); lib.config.defaultcards=lib.config.cards.slice(0);
} }
for(var i in config2){ for(var i in config2){
switch(i){
case 'cheat':lib.config.cheat=config2[i];break;
case 'confirmtouch':lib.config.confirmtouch=config2[i];break;
case 'auto_skill':lib.config.auto_skill=config2[i];break;
case 'auto_confirm':lib.config.auto_confirm=config2[i];break;
case 'enable_drag':lib.config.enable_drag=config2[i];break;
case 'hover_all':lib.config.hover_all=config2[i];break;
case 'hover_handcard':lib.config.hover_handcard=config2[i];break;
case 'duration':lib.config.duration=config2[i];break;
case 'hoveration':lib.config.hoveration=config2[i];break;
case 'image_background':lib.config.image_background=config2[i];break;
case 'image_background_filter':lib.config.image_background_filter=config2[i];break;
case 'ui_zoom':lib.config.ui_zoom=config2[i];break;
case 'show_name':lib.config.show_name=config2[i];break;
case 'show_replay':lib.config.show_replay=config2[i];break;
case 'show_playerids':lib.config.show_playerids=config2[i];break;
case 'show_pause':lib.config.show_pause=config2[i];break;
case 'show_auto':lib.config.show_auto=config2[i];break;
case 'right_info':lib.config.right_info=config2[i];break;
case 'long_info':lib.config.long_info=config2[i];break;
case 'only_fullskin':lib.config.only_fullskin=config2[i];break;
case 'hide_card_image':lib.config.hide_card_image=config2[i];break;
case 'show_wuxie':lib.config.show_wuxie=config2[i];break;
case 'show_scrollbar':lib.config.show_scrollbar=config2[i];break;
case 'mousewheel':lib.config.mousewheel=config2[i];break;
case 'fold_card':lib.config.fold_card=config2[i];break;
case 'touchscreen':lib.config.touchscreen=config2[i];break;
case 'threed_card':lib.config.threed_card=config2[i];break;
case 'blur_ui':lib.config.blur_ui=config2[i];break;
case 'hide_history':lib.config.hide_history=config2[i];break;
case 'right_sidebar':lib.config.right_sidebar=config2[i];break;
case 'right_click':lib.config.right_click=config2[i];break;
case 'sort':lib.config.sort=config2[i];break;
case 'reverse_sort':lib.config.reverse_sort=config2[i];break;
case 'title':lib.config.title=config2[i];break;
case 'intro':lib.config.intro=config2[i];break;
case 'theme':lib.config.theme=config2[i];break;
case 'layout':lib.config.layout=config2[i];break;
case 'gameconfig':lib.config.gameconfig=config2[i];break; if(i.indexOf('_mode_config')!=-1&&i.substr(i.indexOf('_mode_config')+13)==lib.config.mode){
case 'modeconfig':lib.config.modeconfig=config2[i];break;
case 'appearence':lib.config.appearence=config2[i];break;
case 'forbidlist':lib.config.forbidlist=config2[i];break;
case 'autoskilllist':lib.config.autoskilllist=config2[i];break;
default:
if(i.indexOf('_character')==i.length-10&&i.length>10){
if(config2[i]){
lib.config.characters.add(i.slice(0,i.indexOf('_character')));
}
else{
lib.config.characters.remove(i.slice(0,i.indexOf('_character')));
}
}
else if(i.indexOf('_card')==i.length-5&&i.length>5){
if(config2[i]){
lib.config.cards.add(i.slice(0,i.indexOf('_card')));
}
else{
lib.config.cards.remove(i.slice(0,i.indexOf('_card')));
}
}
if(i.indexOf('_play')==i.length-5&&i.length>5){
if(config2[i]){
lib.config.plays.add(i.slice(0,i.indexOf('_play')));
}
else{
lib.config.plays.remove(i.slice(0,i.indexOf('_play')));
}
}
else if(i.indexOf('_mode_config')!=-1&&i.substr(i.indexOf('_mode_config')+13)==lib.config.mode){
lib.config.mode_config[lib.config.mode][i.substr(0,i.indexOf('_mode_config'))]=config2[i]; lib.config.mode_config[lib.config.mode][i.substr(0,i.indexOf('_mode_config'))]=config2[i];
} }
else{ else{
lib.config[i]=config2[i];
}
}
}
} }
for(var i in lib.config.translate){ for(var i in lib.config.translate){
lib.translate[i]=lib.config.translate[i]; lib.translate[i]=lib.config.translate[i];
@ -1818,7 +1751,7 @@ window.play={};
ui.revive=ui.create.control('revive',ui.click.dierevive); ui.revive=ui.create.control('revive',ui.click.dierevive);
} }
if(get.config('dierestart')&&lib.config.mode!='versus'){ if(get.config('dierestart')&&lib.config.mode!='versus'){
ui.restart=ui.create.control('restart',function(){window.location.reload()}); ui.restart=ui.create.control('restart',game.reload);
} }
} }
if(player==game.me&&ui.auto){ if(player==game.me&&ui.auto){
@ -4848,6 +4781,12 @@ window.play={};
}; };
var game={ var game={
version:0.912, version:0.912,
reload:function(){
if(_status){
_status.reloading=true;
}
window.location.reload();
},
update:function(func){ update:function(func){
lib.updates.push(func); lib.updates.push(func);
if(lib.updates.length===1){ if(lib.updates.length===1){
@ -5103,12 +5042,10 @@ window.play={};
dialog.add(ui.create.div('.placeholder')); dialog.add(ui.create.div('.placeholder'));
dialog.add(ui.create.div('.placeholder')); dialog.add(ui.create.div('.placeholder'));
if(!ui.restart){ if(!ui.restart){
ui.restart=ui.create.control('restart',function(){window.location.reload()}); ui.restart=ui.create.control('restart',game.reload);
} }
if(lib.storage.test){ if(lib.storage.test){
setTimeout(function(){ setTimeout(game.reload,500);
window.location.reload();
},500);
} }
if(ui.auto) ui.auto.hide(); if(ui.auto) ui.auto.hide();
@ -5803,6 +5740,7 @@ window.play={};
if(lib.config.title) document.title=str; if(lib.config.title) document.title=str;
}, },
save:function(key,value){ save:function(key,value){
if(_status.reloading) return;
var config={}; var config={};
if(arguments.length>0){ if(arguments.length>0){
try{ try{
@ -5825,6 +5763,7 @@ window.play={};
localStorage.setItem(lib.configprefix+lib.config.mode,JSON.stringify(config)); localStorage.setItem(lib.configprefix+lib.config.mode,JSON.stringify(config));
}, },
updateSave:function(){ updateSave:function(){
if(_status.reloading) return;
localStorage.setItem(lib.configprefix+lib.config.mode,JSON.stringify(lib.storage)); localStorage.setItem(lib.configprefix+lib.config.mode,JSON.stringify(lib.storage));
}, },
import:function(name,replace){ import:function(name,replace){
@ -5896,6 +5835,7 @@ window.play={};
} }
}, },
saveConfig:function(key,value,local){ saveConfig:function(key,value,local){
if(_status.reloading) return;
var config; var config;
try{ try{
config=JSON.parse(localStorage.getItem(lib.configprefix+'config')); config=JSON.parse(localStorage.getItem(lib.configprefix+'config'));
@ -6481,15 +6421,15 @@ window.play={};
var span2='<div style="width:20px;text-align:center;padding-right:0">·</div>'; var span2='<div style="width:20px;text-align:center;padding-right:0">·</div>';
newgame.push(ui.create.line((lib.config.mode=='identity'?span1:span2)+'身份模式',function(){ newgame.push(ui.create.line((lib.config.mode=='identity'?span1:span2)+'身份模式',function(){
game.saveConfig('mode','identity'); game.saveConfig('mode','identity');
window.location.reload(); game.reload();
})); }));
newgame.push(ui.create.line((lib.config.mode=='guozhan'?span1:span2)+'国战模式',function(){ newgame.push(ui.create.line((lib.config.mode=='guozhan'?span1:span2)+'国战模式',function(){
game.saveConfig('mode','guozhan'); game.saveConfig('mode','guozhan');
window.location.reload(); game.reload();
})); }));
newgame.push(ui.create.line((lib.config.mode=='versus'?span1:span2)+'对决模式',function(){ newgame.push(ui.create.line((lib.config.mode=='versus'?span1:span2)+'对决模式',function(){
game.saveConfig('mode','versus'); game.saveConfig('mode','versus');
window.location.reload(); game.reload();
})); }));
if(!lib.config.modeconfig&&!lib.config.gameconfig&&!lib.config.appearence){ if(!lib.config.modeconfig&&!lib.config.gameconfig&&!lib.config.appearence){
@ -6574,13 +6514,15 @@ window.play={};
modeconfig.push(ui.create.switcher('strict_sort',get.config('strict_sort'),ui.click.sidebar.local)); modeconfig.push(ui.create.switcher('strict_sort',get.config('strict_sort'),ui.click.sidebar.local));
modeconfig.push(ui.create.switcher('reverse_sort',get.config('reverse_sort'),ui.click.sidebar.reverse_sort)); modeconfig.push(ui.create.switcher('reverse_sort',get.config('reverse_sort'),ui.click.sidebar.reverse_sort));
} }
else if(Array.isArray(lib.config.current_mode[i])){
modeconfig.push(ui.create.switcher.apply(this,lib.config.current_mode[i]));
}
} }
if(lib.config.modeconfig){ if(lib.config.modeconfig){
for(i=0;i<modeconfig.length;i++){ for(i=0;i<modeconfig.length;i++){
ui.config.appendChild(modeconfig[i]); ui.config.appendChild(modeconfig[i]);
} }
} }
// ui.config.appendChild(ui.create.div('.placeholder'));
var gameconfig=[]; var gameconfig=[];
gameconfig._configstr='gameconfig'; gameconfig._configstr='gameconfig';
folditems.push(gameconfig); folditems.push(gameconfig);
@ -6700,23 +6642,20 @@ window.play={};
reset_characterpack.innerHTML='恢复默认'; reset_characterpack.innerHTML='恢复默认';
reset_characterpack.addEventListener(lib.config.touchscreen?'touchend':'click',function(){ reset_characterpack.addEventListener(lib.config.touchscreen?'touchend':'click',function(){
if(_status.dragged) return; if(_status.dragged) return;
game.saveConfig('characters',lib.config.defaultcharacters);
for(var i=0;i<characterpack.length;i++){ for(var i=0;i<characterpack.length;i++){
if(characterpack[i].link){ if(characterpack[i].link){
var pnme=characterpack[i].link.slice(0,characterpack[i].link.indexOf('_character')); var pnme=characterpack[i].link.slice(0,characterpack[i].link.indexOf('_character'));
if(lib.config.defaultcharacters.contains(pnme)){ if(lib.config.defaultcharacters.contains(pnme)){
if(!characterpack[i].lastChild.classList.contains('on')){ if(!characterpack[i].lastChild.classList.contains('on')){
characterpack[i].querySelector('.toggle').link=true; characterpack[i].querySelector('.toggle').link=true;
game.saveConfig(characterpack[i].link,true);
characterpack[i].lastChild.classList.add('on'); characterpack[i].lastChild.classList.add('on');
// characterpack[i].lastChild.innerHTML='开';
} }
} }
else{ else{
if(characterpack[i].lastChild.classList.contains('on')){ if(characterpack[i].lastChild.classList.contains('on')){
characterpack[i].querySelector('.toggle').link=false; characterpack[i].querySelector('.toggle').link=false;
game.saveConfig(characterpack[i].link,false);
characterpack[i].lastChild.classList.remove('on'); characterpack[i].lastChild.classList.remove('on');
// characterpack[i].lastChild.innerHTML='关';
} }
} }
} }
@ -6727,13 +6666,12 @@ window.play={};
all_characterpack.innerHTML='全部开启'; all_characterpack.innerHTML='全部开启';
all_characterpack.addEventListener(lib.config.touchscreen?'touchend':'click',function(){ all_characterpack.addEventListener(lib.config.touchscreen?'touchend':'click',function(){
if(_status.dragged) return; if(_status.dragged) return;
game.saveConfig('characters',lib.config.all.characters);
for(var i=0;i<characterpack.length;i++){ for(var i=0;i<characterpack.length;i++){
if(characterpack[i].link){ if(characterpack[i].link){
if(!characterpack[i].lastChild.classList.contains('on')){ if(!characterpack[i].lastChild.classList.contains('on')){
characterpack[i].querySelector('.toggle').link=true; characterpack[i].querySelector('.toggle').link=true;
game.saveConfig(characterpack[i].link,true);
characterpack[i].lastChild.classList.add('on'); characterpack[i].lastChild.classList.add('on');
// characterpack[i].lastChild.innerHTML='开';
} }
} }
} }
@ -6741,12 +6679,6 @@ window.play={};
}); });
characterpack.push(reset_characterpack); characterpack.push(reset_characterpack);
characterpack.push(all_characterpack); characterpack.push(all_characterpack);
// if(lib.config.characterpack){
// for(i=0;i<characterpack.length;i++){
// ui.config.appendChild(characterpack[i]);
// }
// }
// ui.config.appendChild(ui.create.div('.placeholder'));
var cardpack=[]; var cardpack=[];
folditems.push(cardpack); folditems.push(cardpack);
@ -6773,23 +6705,20 @@ window.play={};
reset_cardpack.innerHTML='恢复默认'; reset_cardpack.innerHTML='恢复默认';
reset_cardpack.addEventListener(lib.config.touchscreen?'touchend':'click',function(){ reset_cardpack.addEventListener(lib.config.touchscreen?'touchend':'click',function(){
if(_status.dragged) return; if(_status.dragged) return;
game.saveConfig('cards',lib.config.defaultcards);
for(var i=0;i<cardpack.length;i++){ for(var i=0;i<cardpack.length;i++){
if(cardpack[i].link){ if(cardpack[i].link){
var pnme=cardpack[i].link.slice(0,cardpack[i].link.indexOf('_card')); var pnme=cardpack[i].link.slice(0,cardpack[i].link.indexOf('_card'));
if(lib.config.defaultcards.contains(pnme)){ if(lib.config.defaultcards.contains(pnme)){
if(!cardpack[i].lastChild.classList.contains('on')){ if(!cardpack[i].lastChild.classList.contains('on')){
cardpack[i].querySelector('.toggle').link=true; cardpack[i].querySelector('.toggle').link=true;
game.saveConfig(cardpack[i].link,true);
cardpack[i].lastChild.classList.add('on'); cardpack[i].lastChild.classList.add('on');
// cardpack[i].lastChild.innerHTML='开';
} }
} }
else{ else{
if(cardpack[i].lastChild.classList.contains('on')){ if(cardpack[i].lastChild.classList.contains('on')){
cardpack[i].querySelector('.toggle').link=false; cardpack[i].querySelector('.toggle').link=false;
game.saveConfig(cardpack[i].link,false);
cardpack[i].lastChild.classList.remove('on'); cardpack[i].lastChild.classList.remove('on');
// cardpack[i].lastChild.innerHTML='关';
} }
} }
} }
@ -6800,13 +6729,12 @@ window.play={};
all_cardpack.innerHTML='全部开启'; all_cardpack.innerHTML='全部开启';
all_cardpack.addEventListener(lib.config.touchscreen?'touchend':'click',function(){ all_cardpack.addEventListener(lib.config.touchscreen?'touchend':'click',function(){
if(_status.dragged) return; if(_status.dragged) return;
game.saveConfig('cards',lib.config.all.cards);
for(var i=0;i<cardpack.length;i++){ for(var i=0;i<cardpack.length;i++){
if(cardpack[i].link){ if(cardpack[i].link){
if(!cardpack[i].lastChild.classList.contains('on')){ if(!cardpack[i].lastChild.classList.contains('on')){
cardpack[i].querySelector('.toggle').link=true; cardpack[i].querySelector('.toggle').link=true;
game.saveConfig(cardpack[i].link,true);
cardpack[i].lastChild.classList.add('on'); cardpack[i].lastChild.classList.add('on');
// cardpack[i].lastChild.innerHTML='开';
} }
} }
} }
@ -6814,12 +6742,6 @@ window.play={};
}); });
cardpack.push(reset_cardpack); cardpack.push(reset_cardpack);
cardpack.push(all_cardpack); cardpack.push(all_cardpack);
// if(lib.config.cardpack){
// for(i=0;i<cardpack.length;i++){
// ui.config.appendChild(cardpack[i]);
// }
// }
// ui.config.appendChild(ui.create.div('.placeholder'));
var playpack=[]; var playpack=[];
folditems.push(playpack); folditems.push(playpack);
@ -6842,11 +6764,6 @@ window.play={};
node.link=plays[i]+'_play'; node.link=plays[i]+'_play';
playpack[i]=node; playpack[i]=node;
} }
// if(lib.config.playpack){
// for(i=0;i<playpack.length;i++){
// ui.config.appendChild(playpack[i]);
// }
// }
ui.config.appendChild(ui.create.div('.placeholder')); ui.config.appendChild(ui.create.div('.placeholder'));
var cardlist=[]; var cardlist=[];
@ -7111,9 +7028,7 @@ window.play={};
if(_status.reset) localStorage.clear(); if(_status.reset) localStorage.clear();
ui.arena.hide(); ui.arena.hide();
ui.config.hide(); ui.config.hide();
setTimeout(function(){ setTimeout(game.reload,500);
window.location.reload();
},500);
}); });
if(lib.config.right_sidebar){ if(lib.config.right_sidebar){
@ -7124,7 +7039,7 @@ window.play={};
ui.system1=ui.create.div('#system1',ui.system); ui.system1=ui.create.div('#system1',ui.system);
ui.system2=ui.create.div('#system2',ui.system); ui.system2=ui.create.div('#system2',ui.system);
} }
ui.replay=ui.create.system('重来',function(){window.location.reload()},true); ui.replay=ui.create.system('重来',game.reload,true);
ui.pause=ui.create.system('暂停',ui.click.pause); ui.pause=ui.create.system('暂停',ui.click.pause);
if(!lib.config.show_pause){ if(!lib.config.show_pause){
ui.pause.style.display='none'; ui.pause.style.display='none';
@ -7143,7 +7058,7 @@ window.play={};
var backtomouse=ui.create.system('返回鼠标模式'); var backtomouse=ui.create.system('返回鼠标模式');
backtomouse.addEventListener('click',function(){ backtomouse.addEventListener('click',function(){
game.saveConfig('touchscreen',false); game.saveConfig('touchscreen',false);
window.location.reload(); game.reload();
}); });
var keeptouch=ui.create.system('确认触屏'); var keeptouch=ui.create.system('确认触屏');
keeptouch.addEventListener('touchend',function(){ keeptouch.addEventListener('touchend',function(){
@ -8376,7 +8291,7 @@ window.play={};
}, },
player_number:function(num){ player_number:function(num){
game.saveConfig('player_number',num,true); game.saveConfig('player_number',num,true);
window.location.reload(); game.reload();
}, },
auto_identity:function(bool){ auto_identity:function(bool){
game.saveConfig('auto_identity',bool,true); game.saveConfig('auto_identity',bool,true);
@ -8630,15 +8545,36 @@ window.play={};
if(!lib.config.title) document.title='无名杀'; if(!lib.config.title) document.title='无名杀';
}, },
characters:function(bool,node){ characters:function(bool,node){
game.saveConfig(node.link,bool); var name=node.link.slice(0,node.link.length-10);
if(bool){
lib.config.characters.add(name);
}
else{
lib.config.characters.remove(name);
}
game.saveConfig('characters',lib.config.characters);
ui.sidebarrestart.classList.add('thundertext'); ui.sidebarrestart.classList.add('thundertext');
}, },
cards:function(bool,node){ cards:function(bool,node){
game.saveConfig(node.link,bool); var name=node.link.slice(0,node.link.length-5);
if(bool){
lib.config.cards.add(name);
}
else{
lib.config.cards.remove(name);
}
game.saveConfig('cards',lib.config.cards);
ui.sidebarrestart.classList.add('thundertext'); ui.sidebarrestart.classList.add('thundertext');
}, },
plays:function(bool,node){ plays:function(bool,node){
game.saveConfig(node.link,bool); var name=node.link.slice(0,node.link.length-5);
if(bool){
lib.config.plays.add(name);
}
else{
lib.config.plays.remove(name);
}
game.saveConfig('plays',lib.config.plays);
ui.sidebarrestart.classList.add('thundertext'); ui.sidebarrestart.classList.add('thundertext');
}, },
forbid:function(bool,node){ forbid:function(bool,node){
@ -10512,7 +10448,8 @@ window.play={};
} }
} }
else if(e.keyCode==116||((e.ctrlKey||e.metaKey)&&e.keyCode==82)){ else if(e.keyCode==116||((e.ctrlKey||e.metaKey)&&e.keyCode==82)){
window.location.reload(); _status.reloading=true;
game.reload();
} }
}; };
window.onload=function(){ window.onload=function(){

View File

@ -730,8 +730,6 @@ mode.guozhan={
ai_identity:true, ai_identity:true,
revive:true, revive:true,
double_hp:true, double_hp:true,
// ban_weak:true,
// keep_max_hp:true,
difficulty:true, difficulty:true,
}, },
} }