diff --git a/game/game.js b/game/game.js index 4e0db2c5a..b16a09d6d 100644 --- a/game/game.js +++ b/game/game.js @@ -6827,10 +6827,11 @@ }, placePoppedDialog:function(dialog,e){ if(dialog._place_text){ - if(dialog._place_text.firstChild.offsetWidth>=190|| - dialog._place_text.firstChild.offsetHeight>=30){ - dialog._place_text.style.textAlign='left'; + if(dialog._place_text.firstChild.offsetWidth>=190||dialog._place_text.firstChild.offsetHeight>=30){ dialog._place_text.style.marginLeft='14px'; + dialog._place_text.style.marginRight='14px'; + dialog._place_text.style.textAlign='left'; + dialog._place_text.style.width='calc(100% - 28px)'; } } if(e.touches&&e.touches[0]){ @@ -7805,17 +7806,19 @@ if(pack.font){ ui.css.fontsheet=lib.init.sheet(); - for(i in pack.font){ - lib.configMenu.appearence.config.name_font.item[i]=pack.font[i]; - lib.configMenu.appearence.config.identity_font.item[i]=pack.font[i]; - lib.configMenu.appearence.config.cardtext_font.item[i]=pack.font[i]; - lib.configMenu.appearence.config.global_font.item[i]=pack.font[i]; - ui.css.fontsheet.sheet.insertRule("@font-face {font-family: '"+i+"'; src: url('"+lib.assetURL+"font/"+i+".ttf');}",0); - if(lib.config.suits_font) ui.css.fontsheet.sheet.insertRule("@font-face {font-family: '"+i+"'; src: url('"+lib.assetURL+"font/suits.ttf');}",0); - } - if(lib.config.suits_font) ui.css.fontsheet.sheet.insertRule("@font-face {font-family: 'Suits'; src: url('"+lib.assetURL+"font/suits.ttf');}",0); - lib.configMenu.appearence.config.cardtext_font.item.default='默认'; - lib.configMenu.appearence.config.global_font.item.default='默认'; + const appearenceConfig=lib.configMenu.appearence.config,fontSheet=ui.css.fontsheet.sheet,suitsFont=lib.config.suits_font; + Object.keys(pack.font).forEach(value=>{ + const font=pack.font[value]; + appearenceConfig.name_font.item[value]=font; + appearenceConfig.identity_font.item[value]=font; + appearenceConfig.cardtext_font.item[value]=font; + appearenceConfig.global_font.item[value]=font; + fontSheet.insertRule(`@font-face {font-family: '${value}'; src: local('${font}'), url('${lib.assetURL}font/${value}.ttf');}`,0); + if(suitsFont) fontSheet.insertRule(`@font-face {font-family: '${value}'; src: local('${font}'), url('${lib.assetURL}font/suits.ttf');}`,0); + }); + if(suitsFont) fontSheet.insertRule(`@font-face {font-family: 'Suits'; src: local('Noname Suit'), url('${lib.assetURL}font/suits.ttf');}`,0); + appearenceConfig.cardtext_font.item.default='默认'; + appearenceConfig.global_font.item.default='默认'; } var ua=navigator.userAgent.toLowerCase(); @@ -8109,10 +8112,8 @@ ui.backgroundMusic.pause(); } }); - document.addEventListener("resume", function(){ - if(ui.backgroundMusic){ - ui.backgroundMusic.play(); - } + document.addEventListener("resume", ()=>{ + if(ui.backgroundMusic) Promise.resolve(ui.backgroundMusic.play()).catch(()=>void 0); }); document.addEventListener("backbutton", function(){ if(ui.arena&&ui.arena.classList.contains('menupaused')){ @@ -11203,10 +11204,7 @@ game.resume(); _status.imchoosing=false; if(roundmenu) ui.roundmenu.style.display=''; - if(ui.backgroundMusic){ - var promise=ui.backgroundMusic.play(); - if(promise) promise.catch(()=>void 0); - } + if(ui.backgroundMusic) Promise.resolve(ui.backgroundMusic.play()).catch(()=>void 0); hitsound_audio.remove(); },1000); }; @@ -11321,7 +11319,7 @@ combo++; max_combo=Math.max(combo,max_combo); hitsound_audio.currentTime=0; - if(hitsound_audio.paused) hitsound_audio.play(); + if(hitsound_audio.paused) Promise.resolve(hitsound_audio.play()).catch(()=>void 0); break; } }; @@ -11395,10 +11393,7 @@ if(dialog){ dialog.close(); } - if(ui.backgroundMusic){ - var promise=ui.backgroundMusic.play(); - if(promise) promise.catch(()=>void 0); - } + if(ui.backgroundMusic) Promise.resolve(ui.backgroundMusic.play()).catch(()=>void 0); },event.videoId,event.time); var result=event.result||result; event.result=result; @@ -31995,7 +31990,7 @@ }; //Some browsers do not support "autoplay", so "oncanplay" listening has been added audio.oncanplay=function(){ - this.play(); + Promise.resolve(this.play()).catch(()=>void 0); }; ui.window.appendChild(audio); return audio; @@ -32106,7 +32101,7 @@ }; //Some browsers do not support "autoplay", so "oncanplay" listening has been added audio.oncanplay=function(){ - this.play(); + Promise.resolve(this.play()).catch(()=>void 0); }; ui.window.appendChild(audio); }, @@ -37425,284 +37420,189 @@ } }); }, - updateRoundNumber:function(){ - game.broadcastAll(function(num1,num2,top){ - if(ui.cardPileNumber) ui.cardPileNumber.innerHTML=num1+'轮 剩余牌: '+num2; - _status.pileTop=top; - },game.roundNumber,ui.cardPile.childNodes.length,ui.cardPile.firstChild); - }, - asyncDraw:function(players,num,drawDeck,bottom){ - for(var i=0;igame.broadcastAll((num1,num2,top)=>{ + if(ui.cardPileNumber) ui.cardPileNumber.innerHTML=`${num1}轮 剩余牌: ${num2}`; + _status.pileTop=top; + },game.roundNumber,ui.cardPile.childNodes.length,ui.cardPile.firstChild), + asyncDraw:(players,num,drawDeck,bottom)=>players.forEach((value,index)=>{ + let num2=1; + if(typeof num=='number') num2=num; + else if(Array.isArray(num)) num2=num[index]; + else if(typeof num=='function') num2=num(value); + if(drawDeck&&drawDeck.drawDeck) value.draw(num2,false,drawDeck); + else if(bottom) value.draw(num2,'nodelay','bottom'); + else value.draw(num2,'nodelay'); + }), asyncDrawAuto:function(players,num,drawDeck){ - if(players.length==1){ - var num2=1; - if(typeof num=='number'){ - num2=num; - } - else if(Array.isArray(num)){ - num2=num[0]; - } - else if(typeof num=='function'){ - num2=num(players[0]); - } - if(drawDeck&&drawDeck.drawDeck){ - players[0].draw(num2,drawDeck); - } - else{ - players[0].draw(num2); - } - } - else{ + if(players.length>1){ game.asyncDraw.apply(this,arguments); + return; } + let num2=1; + if(typeof num=='number') num2=num; + else if(Array.isArray(num)) num2=num[0]; + else if(typeof num=='function') num2=num(players[0]); + if(drawDeck&&drawDeck.drawDeck) players[0].draw(num2,drawDeck); + else players[0].draw(num2); }, - finishSkill:function(i,sub){ - var j; - var mode=get.mode(); - var info=lib.skill[i]; + finishSkill:(i,sub)=>{ + const mode=get.mode(),info=lib.skill[i],iInfo=`${i}_info`; if(info.alter){ - lib.translate[i+'_info_origin']=lib.translate[i+'_info']; - if(!lib.config.vintageSkills.contains(i)){ - lib.translate[i+'_info']=lib.translate[i+'_info_alter']; - } - } - else if(lib.translate[i+'_info_'+mode]){ - lib.translate[i+'_info']=lib.translate[i+'_info_'+mode]; - } - else if(lib.translate[i+'_info_zhu']&&(mode=='identity'||(mode=='guozhan'&&_status.mode=='four'))){ - lib.translate[i+'_info']=lib.translate[i+'_info_zhu']; - } - else if(lib.translate[i+'_info_combat']&&get.is.versus()){ - lib.translate[i+'_info']=lib.translate[i+'_info_combat']; + lib.translate[`${iInfo}_origin`]=lib.translate[iInfo]; + if(!lib.config.vintageSkills.contains(i)) lib.translate[iInfo]=lib.translate[`${iInfo}_alter`]; } + else if(lib.translate[`${iInfo}_${mode}`]) lib.translate[iInfo]=lib.translate[`${iInfo}_${mode}`]; + else if(lib.translate[`${iInfo}_zhu`]&&(mode=='identity'||mode=='guozhan'&&_status.mode=='four')) lib.translate[iInfo]=lib.translate[`${iInfo}_zhu`]; + else if(lib.translate[`${iInfo}_combat`]&&get.is.versus()) lib.translate[iInfo]=lib.translate[`${iInfo}_combat`]; if(info.forbid&&info.forbid.contains(mode)){ lib.skill[i]={}; - if(lib.translate[i+'_info']){ - lib.translate[i+'_info']='此模式下不可用'; - } + if(lib.translate[iInfo]) lib.translate[iInfo]='此模式下不可用'; return; } if(info.mode&&info.mode.contains(mode)==false){ lib.skill[i]={}; - if(lib.translate[i+'_info']){ - lib.translate[i+'_info']='此模式下不可用'; - } + if(lib.translate[iInfo]) lib.translate[iInfo]='此模式下不可用'; return; } if(info.available&&info.available(mode)==false){ lib.skill[i]={}; - if(lib.translate[i+'_info']){ - lib.translate[i+'_info']='此模式下不可用'; - } + if(lib.translate[iInfo]) lib.translate[iInfo]='此模式下不可用'; return; } if(info.viewAs&&typeof info.viewAs!='function'){ - if(typeof info.viewAs=='string'){ - info.viewAs={name:info.viewAs}; - } + if(typeof info.viewAs=='string') info.viewAs={ + name:info.viewAs + }; if(!lib.card[info.viewAs.name]){ lib.skill[i]={}; - lib.translate[i+'_info']='技能不可用'; + lib.translate[iInfo]='技能不可用'; return; } if(info.ai==undefined) info.ai={}; - var skill=info.ai; - var card=lib.card[info.viewAs.name].ai; - for(j in card){ - if(skill[j]==undefined) skill[j]=card[j]; - else if(typeof skill[j]=='object'){ - for(var k in card[j]){ - if(skill[j][k]==undefined) skill[j][k]=card[j][k]; - } - } - } + const skill=info.ai,card=lib.card[info.viewAs.name].ai; + Object.keys(card).forEach(value=>{ + if(skill[value]==undefined) skill[value]=card[value]; + else if(typeof skill[value]=='object') Object.keys(card[value]).forEach(element=>{ + if(skill[value][element]==undefined) skill[value][element]=card[value][element]; + }); + }); } if(info.inherit){ - var skill=lib.skill[info.inherit]; - for(j in skill){ - if(info[j]==undefined){ - if(j=='audio'&&(typeof info[j]=='number'||typeof info[j]=='boolean')){ - info[j]=info.inherit; - } - else{ - info[j]=skill[j]; - } - } - } - if(lib.translate[i]==undefined){ - lib.translate[i]=lib.translate[info.inherit]; - } - if(lib.translate[i+'_info']==undefined){ - lib.translate[i+'_info']=lib.translate[info.inherit+'_info']; - } + const skill=lib.skill[info.inherit]; + Object.keys(skill).forEach(value=>{ + if(info[value]!=undefined) return; + if(value=='audio'&&(typeof info[value]=='number'||typeof info[value]=='boolean')) info[value]=info.inherit; + else info[value]=skill[value]; + }); + if(lib.translate[i]==undefined) lib.translate[i]=lib.translate[info.inherit]; + if(lib.translate[iInfo]==undefined) lib.translate[iInfo]=lib.translate[`${info.inherit}_info`]; } if(info.limited){ if(info.mark===undefined) info.mark=true; if(!info.intro) info.intro={}; if(info.intro.content===undefined) info.intro.content='limited'; if(info.skillAnimation===undefined) info.skillAnimation=true; - if(info.init===undefined) info.init=function(player,skill){ - player.storage[skill]=false; - } - } - if(info.subSkill&&!sub){ - for(var j in info.subSkill){ - lib.skill[i+'_'+j]=info.subSkill[j]; - lib.skill[i+'_'+j].sub=true; - if(info.subSkill[j].name){ - lib.translate[i+'_'+j]=info.subSkill[j].name; - } - else{ - lib.translate[i+'_'+j]=lib.translate[i+'_'+j]||lib.translate[i]; - } - if(info.subSkill[j].description){ - lib.translate[i+'_'+j+'_info']=info.subSkill[j].description; - } - if(info.subSkill[j].marktext){ - lib.translate[i+'_'+j+'_bg']=info.subSkill[j].marktext; - } - game.finishSkill(i+'_'+j,true); - } + if(info.init===undefined) info.init=(player,skill)=>player.storage[skill]=false; } + if(info.subSkill&&!sub) Object.keys(info.subSkill).forEach(value=>{ + const iValue=`${i}_${value}`; + lib.skill[iValue]=info.subSkill[value]; + lib.skill[iValue].sub=true; + if(info.subSkill[value].name) lib.translate[iValue]=info.subSkill[value].name; + else lib.translate[iValue]=lib.translate[iValue]||lib.translate[i]; + if(info.subSkill[value].description) lib.translate[`${iValue}_info`]=info.subSkill[value].description; + if(info.subSkill[value].marktext) lib.translate[`${iValue}_bg`]=info.subSkill[value].marktext; + game.finishSkill(iValue,true); + }); if(info.round){ - var k=i+'_roundcount'; - if(typeof info.group=='string'){ - info.group=[info.group,k]; - } - else if(Array.isArray(info.group)){ - info.group.add(k); - } - else{ - info.group=[k]; - } - lib.skill[k]=(function(round,name){ - return { - init:function(player){ - if(typeof player.storage[name]!=='number') player.storage[name]=1-round; + const k=`${i}_roundcount`; + if(typeof info.group=='string') info.group=[info.group,k]; + else if(Array.isArray(info.group)) info.group.add(k); + else info.group=[k]; + lib.skill[k]=((round,name)=>({ + init:player=>{ + if(typeof player.storage[name]!=='number') player.storage[name]=1-round; + }, + intro:{ + content:(storage,player)=>{ + let str=''; + const info=get.info(name.slice(0,name.indexOf('_roundcount'))); + if(info&&info.addintro) str+=info.addintro(storage,player); + const num=round-(game.roundNumber-storage); + if(num>0) str+=`${get.cnNumber(num)}轮后${info.roundtext||'技能重置'}`; + else str+='技能可发动'; + return str; }, - intro:{ - content:function(storage,player){ - var str=''; - var info=get.info(name.slice(0,name.indexOf('_roundcount'))); - if(info&&info.addintro){ - str+=info.addintro(storage,player); - } - var num=round-(game.roundNumber-storage); - if(num>0){ - str+=get.cnNumber(num)+'轮后'+(info.roundtext||'技能重置'); - } - else{ - str+='技能可发动'; - } - return str; - }, - markcount:function(storage,player){ - var num=round-(game.roundNumber-storage); - if(num>0){ - return num; - } - return 0; - } - }, - trigger:{global:'roundStart'}, - forced:true, - popup:false, - silent:true, - content:function(){ - var skill=event.name.slice(0,event.name.indexOf('_roundcount')); - if(lib.skill[skill].round-(game.roundNumber-player.storage[event.name])>0){ - player.updateMarks(); - } - else{ - player.unmarkSkill(event.name); - } - } - }; - }(info.round,k)); + markcount:(storage,player)=>Math.max(round-(game.roundNumber-storage),0) + }, + trigger:{global:'roundStart'}, + forced:true, + popup:false, + silent:true, + content:()=>{ + if(lib.skill[event.name.slice(0,event.name.indexOf('_roundcount'))].round-(game.roundNumber-player.storage[event.name])>0) player.updateMarks(); + else player.unmarkSkill(event.name); + } + }))(info.round,k); lib.translate[k]=lib.translate[i]||''; - lib.translate[k+'_bg']=lib.translate[i+'_bg']||lib.translate[k][0]; - } - if(info.marktext){ - lib.translate[i+'_bg']=info.marktext; + lib.translate[`${k}_bg`]=lib.translate[`${i}_bg`]||lib.translate[k][0]; } + if(info.marktext) lib.translate[`${i}_bg`]=info.marktext; if(info.silent){ if(!info.hasOwnProperty('forced')) info.forced=true; if(!info.hasOwnProperty('popup')) info.popup=false; } - if(i[0]=='_'){ - game.addGlobalSkill(i); - } + if(i[0]=='_') game.addGlobalSkill(i); }, - finishCards:function(){ + finishCards:()=>{ _status.cardsFinished=true; - var i,j,k; - var mode=get.mode(); - for(i in lib.card){ - if(lib.translate[i+'_info_'+mode]){ - lib.translate[i+'_info']=lib.translate[i+'_info_'+mode]; - } - else if(lib.translate[i+'_info_zhu']&&(mode=='identity'||(mode=='guozhan'&&_status.mode=='four'))){ - lib.translate[i+'_info']=lib.translate[i+'_info_zhu']; - } - else if(lib.translate[i+'_info_combat']&&get.is.versus()){ - lib.translate[i+'_info']=lib.translate[i+'_info_combat']; - } - var card=lib.card[i]; - if(card.filterTarget&&card.selectTarget==undefined){ - card.selectTarget=1; + const mode=get.mode(),filterTarget=(card,player,target)=>player==target&&target.canEquip(card,true),aiBasicOrder=(card,player)=>{ + const equipValue=get.equipValue(card,player)/20; + return player&&player.hasSkillTag('reverseEquip')?8.5-equipValue:8+equipValue; + },aiBasicValue=(card,player,index,method)=>{ + if(!player.getCards('e').contains(card)&&!player.canEquip(card,true)) return 0.01; + const info=get.info(card),current=player.getEquip(info.subtype),value=current&&card!=current&&get.value(current,player); + let equipValue=info.ai.equipValue||info.ai.basic.equipValue; + if(typeof equipValue=='function'){ + if(method=='raw')return equipValue(card,player); + if(method=='raw2')return equipValue(card,player)-value; + return Math.max(0.1,equipValue(card,player)-value); } + if(typeof equipValue!='number') equipValue=0; + if(method=='raw') return equipValue; + if(method=='raw2') return equipValue-value; + return Math.max(0.1,equipValue-value); + },aiResultTarget=(player,target,card)=>get.equipResult(player,target,card.name); + Object.keys(lib.card).forEach(libCardKey=>{ + const info = `${libCardKey}_info`; + if(lib.translate[`${info}_${mode}`]) lib.translate[info]=lib.translate[`${info}_${mode}`]; + else if(lib.translate[`${info}_zhu`]&&(mode=='identity'||mode=='guozhan'&&_status.mode=='four')) lib.translate[info]=lib.translate[`${info}_zhu`]; + else if(lib.translate[`${info}_combat`]&&get.is.versus()) lib.translate[info]=lib.translate[`${info}_combat`]; + const card=lib.card[libCardKey]; + if(card.filterTarget&&card.selectTarget==undefined) card.selectTarget=1; if(card.autoViewAs){ - if(!card.ai){ - card.ai={}; - } + if(!card.ai) card.ai={}; if(!card.ai.order){ card.ai.order=lib.card[card.autoViewAs].ai.order; - if(!card.ai.order&&lib.card[card.autoViewAs].ai.basic){ - card.ai.order=lib.card[card.autoViewAs].ai.basic.order; - } + if(!card.ai.order&&lib.card[card.autoViewAs].ai.basic) card.ai.order=lib.card[card.autoViewAs].ai.basic.order; } } if(card.type=='equip'){ if(card.enable==undefined) card.enable=true; if(card.selectTarget==undefined) card.selectTarget=-1; - if(card.filterTarget==undefined) card.filterTarget=function(card,player,target){ - if(player!=target) return false; - return target.canEquip(card,true); - }; + if(card.filterTarget==undefined) card.filterTarget=filterTarget; if(card.modTarget==undefined) card.modTarget=true; if(card.allowMultiple==undefined) card.allowMultiple=false; if(card.content==undefined) card.content=lib.element.content.equipCard; if(card.toself==undefined) card.toself=true; - if(card.ai==undefined) card.ai={basic:{}}; - if(card.ai.basic==undefined) card.ai.basic={}; - if(card.ai.result==undefined) card.ai.result={target:1.5}; - if(card.ai.basic.order==undefined) card.ai.basic.order=function(card,player){ - if(player&&player.hasSkillTag('reverseEquip')){ - return 8.5-get.equipValue(card,player)/20; - } - else{ - return 8+get.equipValue(card,player)/20; - } + if(card.ai==undefined) card.ai={ + basic:{} }; + if(card.ai.basic==undefined) card.ai.basic={}; + if(card.ai.result==undefined) card.ai.result={ + target:1.5 + }; + if(card.ai.basic.order==undefined) card.ai.basic.order=aiBasicOrder; if(card.ai.basic.useful==undefined) card.ai.basic.useful=2; if(card.subtype=='equip3'){ if(card.ai.basic.equipValue==undefined) card.ai.basic.equipValue=7; @@ -37710,34 +37610,9 @@ else if(card.subtype=='equip4'){ if(card.ai.basic.equipValue==undefined) card.ai.basic.equipValue=4; } - else{ - if(card.ai.basic.equipValue==undefined) card.ai.basic.equipValue=1; - } - if(card.ai.basic.value==undefined) card.ai.basic.value=function(card,player,index,method){ - if(!player.getCards('e').contains(card)&&!player.canEquip(card,true)) return 0.01; - var value=0; - var info=get.info(card); - var current=player.getEquip(info.subtype); - if(current&&card!=current){ - value=get.value(current,player); - } - var equipValue=info.ai.equipValue; - if(equipValue==undefined){ - equipValue=info.ai.basic.equipValue; - } - if(typeof equipValue=='function'){ - if(method=='raw') return equipValue(card,player); - if(method=='raw2') return equipValue(card,player)-value; - return Math.max(0.1,equipValue(card,player)-value); - } - if(typeof equipValue!='number') equipValue=0; - if(method=='raw') return equipValue; - if(method=='raw2') return equipValue-value; - return Math.max(0.1,equipValue-value); - } - if(!card.ai.result.keepAI) card.ai.result.target=function(player,target,card){ - return get.equipResult(player,target,card.name); - }; + else if(card.ai.basic.equipValue==undefined) card.ai.basic.equipValue=1; + if(card.ai.basic.value==undefined) card.ai.basic.value=aiBasicValue; + if(!card.ai.result.keepAI) card.ai.result.target=aiResultTarget; } else if(card.type=='delay'){ if(card.enable==undefined) card.enable=true; @@ -37745,38 +37620,26 @@ if(card.content==undefined) card.content=lib.element.content.addJudgeCard; if(card.allowMultiple==undefined) card.allowMultiple=false; } - } - for(i in lib.skill){ - game.finishSkill(i); - } + }); + Object.keys(lib.skill).forEach(value=>game.finishSkill(value)); }, checkMod:function(){ - var name=arguments[arguments.length-2]; - var skills=arguments[arguments.length-1]; - if(skills.getSkills){ - //if(name!='cardname') skills=skills.getSkills(); - //else skills=skills.getSkills(null,false); - skills=skills.getSkills(); - } + const argumentArray=Array.from(arguments),name=argumentArray[argumentArray.length-2]; + let skills=argumentArray[argumentArray.length-1]; + if(skills.getSkills) skills=skills.getSkills(); skills=skills.concat(lib.skill.global); game.expandSkills(skills); - skills.sort(function(a,b){ - return get.priority(a)-get.priority(b); + skills.sort((a,b)=>get.priority(a)-get.priority(b)); + const arg=argumentArray.slice(0,-2); + skills.forEach(value=>{ + const info=get.info(value); + if(!info||!info.mod||!info.mod[name]) return; + const result=info.mod[name].apply(this,arg); + if(typeof arg[arg.length-1]!='object'&&result!=undefined) arg[arg.length-1]=result; }); - var arg=[],i,info; - for(i=0;i{ _status.prepareArena=true; game.showHistory(false); ui.create.players(num); @@ -37784,22 +37647,18 @@ ui.create.cardsAsync(); game.finishCards(); }, - clearArena:function(){ + clearArena:()=>{ ui.control.innerHTML=''; ui.arenalog.innerHTML=''; - var nodes=[]; - for(var i=0;i{ + if(value==ui.canvas) return; + if(value==ui.control) return; + if(value==ui.arenalog) return; + if(value==ui.roundmenu) return; + if(value==ui.timer) return; + if(value==ui.autonode) return; + value.remove(); + }); ui.sidebar.innerHTML=''; ui.cardPile.innerHTML=''; ui.discardPile.innerHTML=''; @@ -37810,7 +37669,7 @@ game.dead.length=0; game.me=null; }, - clearConnect:function(){ + clearConnect:()=>{ if(ui.ipnode){ ui.ipnode.remove(); delete ui.ipnode; @@ -37836,137 +37695,108 @@ delete ui.startServer; } if(ui.rooms){ - for(var i=0;ivalue.remove()); delete ui.rooms; } if(ui.roombase){ ui.roombase.remove(); delete ui.roombase; } - if(ui.connectEvents){ - ui.connectEvents.remove(); - ui.connectEventsCount.remove(); - ui.connectClients.remove(); - ui.connectClientsCount.remove(); - ui.createRoomButton.remove(); - delete ui.connectEvents; - delete ui.connectEventsCount; - delete ui.connectClients; - delete ui.connectClientsCount; - delete ui.createRoomButton; - } + if(!ui.connectEvents) return; + ui.connectEvents.remove(); + ui.connectEventsCount.remove(); + ui.connectClients.remove(); + ui.connectClientsCount.remove(); + ui.createRoomButton.remove(); + delete ui.connectEvents; + delete ui.connectEventsCount; + delete ui.connectClients; + delete ui.connectClientsCount; + delete ui.createRoomButton; }, log:function(){ - var str='',str2='',logvid=null; - for(var i=0;i{ + const itemtype=get.itemtype(value); if(itemtype=='player'||itemtype=='players'){ - str+=''+get.translation(arguments[i])+''; - str2+=get.translation(arguments[i]); + str+=`${get.translation(value)}`; + str2+=get.translation(value); } - else if(itemtype=='cards'||itemtype=='card'||(typeof arguments[i]=='object'&&arguments[i]&&arguments[i].name)){ - str+=''+get.translation(arguments[i])+''; - str2+=get.translation(arguments[i]); + else if(itemtype=='cards'||itemtype=='card'||(typeof value=='object'&&value&&value.name)){ + str+=`${get.translation(value)}`; + str2+=get.translation(value); } - else if(typeof arguments[i]=='object'){ - if(arguments[i]){ - if(arguments[i].parentNode==ui.historybar){ - logvid=arguments[i].logvid; - } - else{ - str+=get.translation(arguments[i]); - str2+=get.translation(arguments[i]); - } + else if(typeof value=='object'){ + if(value.parentNode==ui.historybar) logvid=value.logvid; + else{ + str+=get.translation(value); + str2+=get.translation(value); } } - else if(typeof arguments[i]=='string'){ - if(arguments[i][0]=='【'&&arguments[i][arguments[i].length-1]=='】'){ - str+=''+get.translation(arguments[i])+''; - str2+=get.translation(arguments[i]); + else if(typeof value=='string'){ + if(value[0]=='【'&&value[value.length-1]=='】'){ + str+=`${get.translation(value)}`; + str2+=get.translation(value); } - else if(arguments[i][0]=='#'){ - var color=''; - switch(arguments[i][1]){ - case 'b':color='blue';break; - case 'y':color='yellow';break; - case 'g':color='green';break; - } - str+=''+get.translation(arguments[i].slice(2))+''; - str2+=get.translation(arguments[i].slice(2)); + else if(value[0]=='#'){ + str+=`${get.translation(value.slice(2))}`; + str2+=get.translation(value.slice(2)); } else{ - str+=get.translation(arguments[i]); - str2+=get.translation(arguments[i]); + str+=get.translation(value); + str2+=get.translation(value); } } else{ - str+=arguments[i]; - str2+=arguments[i]; + str+=value; + str2+=value; } - - } - var node=ui.create.div(); + }); + const node=ui.create.div(); node.innerHTML=lib.config.log_highlight?str:str2; ui.sidebar.insertBefore(node,ui.sidebar.firstChild); game.addVideo('log',null,lib.config.log_highlight?str:str2); - game.broadcast(function(str,str2){ - game.log(lib.config.log_highlight?str:str2); - },str,str2); + game.broadcast((str,str2)=>game.log(lib.config.log_highlight?str:str2),str,str2); if(!_status.video&&!game.online){ - if(!logvid){ - logvid=_status.event.getLogv(); - } - if(logvid){ - game.logv(logvid,'
'+lib.config.log_highlight?str:str2+'
'); - } + if(logvid) game.logv(logvid,`
${lib.config.log_highlight?str:str2}
`); + else logvid=_status.event.getLogv(); } - // if(lib.config.title) document.title=lib.config.log_highlight?str:str2; - if(lib.config.show_log!='off'&&!game.chess){ - var nodeentry=node.cloneNode(true); - ui.arenalog.insertBefore(nodeentry,ui.arenalog.firstChild); - if(!lib.config.clear_log){ - while(ui.arenalog.childNodes.length&&ui.arenalog.scrollHeight>ui.arenalog.offsetHeight){ - ui.arenalog.lastChild.remove(); - } - } - if(!lib.config.low_performance){ - nodeentry.style.transition='all 0s'; - nodeentry.style.marginBottom=(-nodeentry.offsetHeight)+'px'; - ui.refresh(nodeentry); - nodeentry.style.transition=''; - nodeentry.style.marginBottom=''; - } - if(lib.config.clear_log){ - nodeentry.timeout=setTimeout(function(){ - nodeentry.delete(); - },1000); - for(var i=0;iui.arenalog.offsetHeight){ + ui.arenalog.lastChild.remove(); } + if(!lib.config.low_performance){ + nodeentry.style.transition='all 0s'; + nodeentry.style.marginBottom=`-${nodeentry.offsetHeight}px`; + ui.refresh(nodeentry); + nodeentry.style.transition=''; + nodeentry.style.marginBottom=''; + } + if(!lib.config.clear_log) return; + nodeentry.timeout=setTimeout(()=>nodeentry.delete(),1000); + Array.from(ui.arenalog.childNodes).forEach(value=>{ + if(!value.timeout) value.remove(); + }); }, - logv:function(player,card,targets,event,forced,logvid){ - var node=ui.create.div('.hidden'); - node.node={}; - logvid=logvid||get.id(); + logv:(player,card,targets,event,forced,logvid)=>{ if(!player){ player=_status.event.getParent().logvid; if(!player) return; } - game.broadcast(function(player,card,targets,event,forced,logvid){ - game.logv(player,card,targets,event,forced,logvid); - },player,card,targets,event,forced,logvid); + const node=ui.create.div('.hidden'); + node.node={}; + logvid=logvid||get.id(); + game.broadcast(game.logv,player,card,targets,event,forced,logvid); if(typeof player=='string'){ - for(var i=0;ivalue.logvid==player); + if(childNode) childNode.added.push(card); return; } if(typeof card=='string'){ @@ -37974,23 +37804,17 @@ if(lib.skill[card]&&lib.skill[card].logv===false&&!forced) return; if(!lib.translate[card]) return; } - var avatar; - if(!player.isUnseen(0)){ - avatar=player.node.avatar.cloneNode(); - } - else if(!player.isUnseen(1)){ - avatar=player.node.avatar2.cloneNode(); - } - else{ - return; - } + let avatar; + if(!player.isUnseen(0)) avatar=player.node.avatar.cloneNode(); + else if(!player.isUnseen(1)) avatar=player.node.avatar2.cloneNode(); + else return; node.node.avatar=avatar; avatar.style.transform=''; avatar.className='avatar'; if(card=='die'){ node.dead=true; node.player=player; - var avatar2=avatar.cloneNode(); + const avatar2=avatar.cloneNode(); avatar2.className='avatarbg grayscale1'; avatar.appendChild(avatar2); avatar.style.opacity=0.6; @@ -38003,21 +37827,14 @@ node.appendChild(avatar); if(card=='die'&&targets&&targets!=player){ node.source=targets; - var avatar; player=targets; - if(!player.isUnseen(0)){ - avatar=player.node.avatar.cloneNode(); - } - else if(!player.isUnseen(1)){ - avatar=player.node.avatar2.cloneNode(); - } + if(!player.isUnseen(0)) avatar=player.node.avatar.cloneNode(); + else if(!player.isUnseen(1)) avatar=player.node.avatar2.cloneNode(); else if(get.mode()=='guozhan'&&player.node&&player.node.name_seat){ avatar=ui.create.div('.avatar.cardbg'); avatar.innerHTML=player.node.name_seat.innerHTML[0]; } - else{ - return; - } + else return; avatar.style.transform=''; node.node.avatar2=avatar; avatar.classList.add('avatar2'); @@ -38027,71 +37844,50 @@ else if(Array.isArray(card)){ node.cards=card[1]; card=card[0]; - var info=[card.suit||'',card.number||'',card.name||'',card.nature||'']; - if(!Array.isArray(node.cards)||!node.cards.length){ - node.cards=[ui.create.card(node,'noclick',true).init(info)]; - } + const info=[card.suit||'',card.number||'',card.name||'',card.nature||'']; + if(!Array.isArray(node.cards)||!node.cards.length) node.cards=[ui.create.card(node,'noclick',true).init(info)]; if(card.name=='wuxie'){ if(ui.historybar.firstChild&&ui.historybar.firstChild.type=='wuxie'){ ui.historybar.firstChild.players.push(player); ui.historybar.firstChild.cards.addArray(node.cards); return; } - else{ - node.type='wuxie'; - node.players=[player]; - } - } - if(card.copy){ - card.copy(node,false); + node.type='wuxie'; + node.players=[player]; } + if(card.copy) card.copy(node,false); else{ card=ui.create.card(node,'noclick',true); card.init(info); } - var avatar; - if(!player.isUnseen(0)){ - avatar=player.node.avatar.cloneNode(); - } - else if(!player.isUnseen(1)){ - avatar=player.node.avatar2.cloneNode(); - } + let avatar; + if(!player.isUnseen(0)) avatar=player.node.avatar.cloneNode(); + else if(!player.isUnseen(1)) avatar=player.node.avatar2.cloneNode(); else if(get.mode()=='guozhan'&&player.node&&player.node.name_seat){ avatar=ui.create.div('.avatar.cardbg'); avatar.innerHTML=player.node.name_seat.innerHTML[0]; } - else{ - return; - } + else return; node.node.avatar=avatar; avatar.style.transform=''; avatar.classList.add('avatar2'); node.appendChild(avatar); - - if(targets&&targets.length==1&&targets[0]!=player&&get.itemtype(targets[0])=='player'){ - (function(){ - var avatar2; - var target=targets[0]; - if(!target.isUnseen(0)){ - avatar2=target.node.avatar.cloneNode(); - } - else if(!player.isUnseen(1)){ - avatar2=target.node.avatar2.cloneNode(); - } - else if(get.mode()=='guozhan'&&target.node&&target.node.name_seat){ - avatar2=ui.create.div('.avatar.cardbg'); - avatar2.innerHTML=target.node.name_seat.innerHTML[0]; - } - else{ - return; - } - node.node.avatar2=avatar2; - avatar2.style.transform=''; - avatar2.classList.add('avatar2'); - avatar2.classList.add('avatar3'); - node.insertBefore(avatar2,avatar); - }()); - } + if(targets&&targets.length==1&&targets[0]!=player&&get.itemtype(targets[0])=='player') (()=>{ + let avatar2; + const target=targets[0]; + if(!target.isUnseen(0)) avatar2=target.node.avatar.cloneNode(); + else if(!player.isUnseen(1)) avatar2=target.node.avatar2.cloneNode(); + else if(get.mode()=='guozhan'&&target.node&&target.node.name_seat){ + avatar2=ui.create.div('.avatar.cardbg'); + avatar2.innerHTML=target.node.name_seat.innerHTML[0]; + } + else return; + node.node.avatar2=avatar2; + avatar2.style.transform=''; + avatar2.classList.add('avatar2'); + avatar2.classList.add('avatar3'); + node.insertBefore(avatar2,avatar); + })(); } if(targets&&targets.length){ if(targets.length==1&&targets[0]==player){ @@ -38101,35 +37897,23 @@ node.targets=targets; } } - var fullheight=ui.historybar.offsetHeight; - var num=Math.round((fullheight-8)/50); - var margin=(fullheight-42*num)/(num+1); + const fullheight=ui.historybar.offsetHeight,num=Math.round((fullheight-8)/50),margin=(fullheight-42*num)/(num+1); node.style.transform='scale(0.8)'; ui.historybar.insertBefore(node,ui.historybar.firstChild); ui.refresh(node); node.classList.remove('hidden'); - for(var i=0;i{ + if(index()=>current.remove())(value),500); + }); + if(lib.config.touchscreen) node.addEventListener('touchstart',ui.click.intro); else{ - // node.addEventListener('mouseenter',ui.click.intro); node.addEventListener(lib.config.pop_logv?'mousemove':'click',ui.click.logv); node.addEventListener('mouseleave',ui.click.logvleave); } @@ -38148,8 +37932,7 @@ return; } lib.status.reload++; - var put=lib.db.transaction([type],'readwrite').objectStore(type).put(item,id); - put.onsuccess=function(){ + lib.db.transaction([type],'readwrite').objectStore(type).put(item,id).onsuccess=function(){ if(callback){ _status.dburgent=true; callback.apply(this,arguments); @@ -38169,30 +37952,28 @@ return; } lib.status.reload++; - var store=lib.db.transaction([type],'readwrite').objectStore(type); + const store=lib.db.transaction([type],'readwrite').objectStore(type); if(id){ - store.get(id).onsuccess=function(e){ + store.get(id).onsuccess=e=>{ _status.dburgent=true; callback(e.target.result); delete _status.dburgent; game.reload2(); }; + return; } - else{ - var obj={}; - store.openCursor().onsuccess=function(e){ - var cursor=e.target.result; - if(cursor){ - obj[cursor.key]=cursor.value; - cursor.continue(); - } - else{ - _status.dburgent=true; - callback(obj); - delete _status.dburgent; - game.reload2(); - } + const obj={}; + store.openCursor().onsuccess=e=>{ + const cursor=e.target.result; + if(cursor){ + obj[cursor.key]=cursor.value; + cursor.continue(); + return; } + _status.dburgent=true; + callback(obj); + delete _status.dburgent; + game.reload2(); } }, deleteDB:function(type,id,callback){ @@ -38204,332 +37985,234 @@ lib[_status.dburgent?'ondb2':'ondb'].push(['deleteDB',Array.from(arguments)]); return; } - if(arguments.length==1){ - game.getDB(type,null,function(obj){ - var store=lib.db.transaction([type],'readwrite').objectStore(type); - for(var id in obj){ - lib.status.reload++; - } - for(var id in obj){ - store.delete(id).onsuccess=game.reload2; - } - game.reload2(); - }); - } - else{ + const store=lib.db.transaction([type],'readwrite').objectStore(type); + if(arguments.length!=1){ lib.status.reload++; - var store=lib.db.transaction([type],'readwrite').objectStore(type); store.delete(id).onsuccess=function(){ - if(callback){ - callback.apply(this,arguments); - } + if(callback) callback.apply(this,arguments); game.reload2(); }; + return; } + game.getDB(type,null,obj=>{ + const objKeys=Object.keys(obj); + lib.status.reload+=objKeys.length; + objKeys.forEach(value=>store.delete(value).onsuccess=game.reload2); + game.reload2(); + }); }, - save:function(key,value,mode){ + save:(key,value,mode)=>{ if(_status.reloading) return; mode=mode||lib.config.mode; - if(!lib.db){ - var config={}; - if(key){ - 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{ - config[key]=value; - if(mode==lib.config.mode) lib.storage[key]=value; - } + if(lib.db){ + if(!key){ + game.putDB('data',mode,get.copy(lib.storage)); + return; + } + if(mode==lib.config.mode){ + 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,config=>{ + if(!config) config={}; + if(value==undefined) delete config[key]; + else config[key]=value; config.version=lib.version; - localStorage.setItem(lib.configprefix+mode,JSON.stringify(config)); - } - else{ - localStorage.setItem(lib.configprefix+mode,JSON.stringify(lib.storage)); - } + game.putDB('data',mode,config); + }); + return; + } + 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{ - if(key){ - if(mode==lib.config.mode){ - 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[key]=value; + if(mode==lib.config.mode) lib.storage[key]=value; } + config.version=lib.version; + localStorage.setItem(`${lib.configprefix}${mode}`,JSON.stringify(config)); }, - showChangeLog:function(){ - if(lib.version!=lib.config.version||_status.extensionChangeLog){ - var ul=document.createElement('ul'); - ul.style.textAlign='left'; - var caption; - var players=null,cards=null; - if(lib.version!=lib.config.version){ - for(var i=0;i{ + if(lib.version==lib.config.version&&!_status.extensionChangeLog) return; + const ul=document.createElement('ul'); + ul.style.textAlign='left'; + const caption=lib.version==lib.config.version?'扩展更新':`${lib.version}更新内容`; + let players=null,cards=null; + if(lib.version!=lib.config.version) lib.changeLog.forEach(value=>{ + if(value.indexOf('players://')==0) try{ + players=JSON.parse(value.slice(10)).filter(value=>lib.character[value]); + } + catch(e){ + players=null; + } + else if(value.indexOf('cards://')==0) try{ + cards=JSON.parse(value.slice(8)).filter(value=>lib.card[value]); + } + catch(e){ + cards=null; } else{ - caption='扩展更新'; - } - game.saveConfig('version',lib.version); - for(var i in _status.extensionChangeLog){ - var li=document.createElement('li'); - li.innerHTML=i+':'+_status.extensionChangeLog[i]; + const li=document.createElement('li'); + li.innerHTML=value; ul.appendChild(li); } - var dialog=ui.create.dialog(caption,'hidden'); - var lic=ui.create.div(dialog.content); - lic.style.display='block'; - ul.style.display='inline-block'; - ul.style.marginLeft='-40px'; - lic.appendChild(ul); - if(players){ - for(var i=0;i