From a3f91d4bd2423024afc69956f9f99ace5dc6a657 Mon Sep 17 00:00:00 2001 From: Tipx-L <138244655+Tipx-L@users.noreply.github.com> Date: Thu, 24 Aug 2023 08:24:28 -0700 Subject: [PATCH] Optimize game.logv. (cherry picked from commit 54fa9bf940490e8edf2727d8df50c2eab3c272d8) --- game/game.js | 153 +++++++++++++++++---------------------------------- 1 file changed, 51 insertions(+), 102 deletions(-) diff --git a/game/game.js b/game/game.js index 2def5f502..28fd286ca 100644 --- a/game/game.js +++ b/game/game.js @@ -37950,23 +37950,18 @@ } } }, - 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 +37969,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 +37992,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 +38009,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 +38062,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); }