Optimize game.logv.

(cherry picked from commit 54fa9bf940490e8edf2727d8df50c2eab3c272d8)
This commit is contained in:
Tipx-L 2023-08-24 08:24:28 -07:00
parent 41bf403216
commit a3f91d4bd2
1 changed files with 51 additions and 102 deletions

View File

@ -37950,23 +37950,18 @@
} }
} }
}, },
logv:function(player,card,targets,event,forced,logvid){ logv:(player,card,targets,event,forced,logvid)=>{
var node=ui.create.div('.hidden');
node.node={};
logvid=logvid||get.id();
if(!player){ if(!player){
player=_status.event.getParent().logvid; player=_status.event.getParent().logvid;
if(!player) return; if(!player) return;
} }
game.broadcast(function(player,card,targets,event,forced,logvid){ const node=ui.create.div('.hidden');
game.logv(player,card,targets,event,forced,logvid); node.node={};
},player,card,targets,event,forced,logvid); logvid=logvid||get.id();
game.broadcast(game.logv,player,card,targets,event,forced,logvid);
if(typeof player=='string'){ if(typeof player=='string'){
for(var i=0;i<ui.historybar.childElementCount;i++){ const childNode=Array.from(ui.historybar.childNodes).find(value=>value.logvid==player);
if(ui.historybar.childNodes[i].logvid==player){ if(childNode) childNode.added.push(card);
ui.historybar.childNodes[i].added.push(card);break;
}
}
return; return;
} }
if(typeof card=='string'){ if(typeof card=='string'){
@ -37974,23 +37969,17 @@
if(lib.skill[card]&&lib.skill[card].logv===false&&!forced) return; if(lib.skill[card]&&lib.skill[card].logv===false&&!forced) return;
if(!lib.translate[card]) return; if(!lib.translate[card]) return;
} }
var avatar; let avatar;
if(!player.isUnseen(0)){ if(!player.isUnseen(0)) avatar=player.node.avatar.cloneNode();
avatar=player.node.avatar.cloneNode(); else if(!player.isUnseen(1)) avatar=player.node.avatar2.cloneNode();
} else return;
else if(!player.isUnseen(1)){
avatar=player.node.avatar2.cloneNode();
}
else{
return;
}
node.node.avatar=avatar; node.node.avatar=avatar;
avatar.style.transform=''; avatar.style.transform='';
avatar.className='avatar'; avatar.className='avatar';
if(card=='die'){ if(card=='die'){
node.dead=true; node.dead=true;
node.player=player; node.player=player;
var avatar2=avatar.cloneNode(); const avatar2=avatar.cloneNode();
avatar2.className='avatarbg grayscale1'; avatar2.className='avatarbg grayscale1';
avatar.appendChild(avatar2); avatar.appendChild(avatar2);
avatar.style.opacity=0.6; avatar.style.opacity=0.6;
@ -38003,21 +37992,14 @@
node.appendChild(avatar); node.appendChild(avatar);
if(card=='die'&&targets&&targets!=player){ if(card=='die'&&targets&&targets!=player){
node.source=targets; node.source=targets;
var avatar;
player=targets; player=targets;
if(!player.isUnseen(0)){ if(!player.isUnseen(0)) avatar=player.node.avatar.cloneNode();
avatar=player.node.avatar.cloneNode(); else if(!player.isUnseen(1)) avatar=player.node.avatar2.cloneNode();
}
else if(!player.isUnseen(1)){
avatar=player.node.avatar2.cloneNode();
}
else if(get.mode()=='guozhan'&&player.node&&player.node.name_seat){ else if(get.mode()=='guozhan'&&player.node&&player.node.name_seat){
avatar=ui.create.div('.avatar.cardbg'); avatar=ui.create.div('.avatar.cardbg');
avatar.innerHTML=player.node.name_seat.innerHTML[0]; avatar.innerHTML=player.node.name_seat.innerHTML[0];
} }
else{ else return;
return;
}
avatar.style.transform=''; avatar.style.transform='';
node.node.avatar2=avatar; node.node.avatar2=avatar;
avatar.classList.add('avatar2'); avatar.classList.add('avatar2');
@ -38027,71 +38009,50 @@
else if(Array.isArray(card)){ else if(Array.isArray(card)){
node.cards=card[1]; node.cards=card[1];
card=card[0]; card=card[0];
var info=[card.suit||'',card.number||'',card.name||'',card.nature||'']; const info=[card.suit||'',card.number||'',card.name||'',card.nature||''];
if(!Array.isArray(node.cards)||!node.cards.length){ if(!Array.isArray(node.cards)||!node.cards.length) node.cards=[ui.create.card(node,'noclick',true).init(info)];
node.cards=[ui.create.card(node,'noclick',true).init(info)];
}
if(card.name=='wuxie'){ if(card.name=='wuxie'){
if(ui.historybar.firstChild&&ui.historybar.firstChild.type=='wuxie'){ if(ui.historybar.firstChild&&ui.historybar.firstChild.type=='wuxie'){
ui.historybar.firstChild.players.push(player); ui.historybar.firstChild.players.push(player);
ui.historybar.firstChild.cards.addArray(node.cards); ui.historybar.firstChild.cards.addArray(node.cards);
return; return;
} }
else{ node.type='wuxie';
node.type='wuxie'; node.players=[player];
node.players=[player];
}
}
if(card.copy){
card.copy(node,false);
} }
if(card.copy) card.copy(node,false);
else{ else{
card=ui.create.card(node,'noclick',true); card=ui.create.card(node,'noclick',true);
card.init(info); card.init(info);
} }
var avatar; let avatar;
if(!player.isUnseen(0)){ if(!player.isUnseen(0)) avatar=player.node.avatar.cloneNode();
avatar=player.node.avatar.cloneNode(); else if(!player.isUnseen(1)) avatar=player.node.avatar2.cloneNode();
}
else if(!player.isUnseen(1)){
avatar=player.node.avatar2.cloneNode();
}
else if(get.mode()=='guozhan'&&player.node&&player.node.name_seat){ else if(get.mode()=='guozhan'&&player.node&&player.node.name_seat){
avatar=ui.create.div('.avatar.cardbg'); avatar=ui.create.div('.avatar.cardbg');
avatar.innerHTML=player.node.name_seat.innerHTML[0]; avatar.innerHTML=player.node.name_seat.innerHTML[0];
} }
else{ else return;
return;
}
node.node.avatar=avatar; node.node.avatar=avatar;
avatar.style.transform=''; avatar.style.transform='';
avatar.classList.add('avatar2'); avatar.classList.add('avatar2');
node.appendChild(avatar); node.appendChild(avatar);
if(targets&&targets.length==1&&targets[0]!=player&&get.itemtype(targets[0])=='player') (()=>{
if(targets&&targets.length==1&&targets[0]!=player&&get.itemtype(targets[0])=='player'){ let avatar2;
(function(){ const target=targets[0];
var avatar2; if(!target.isUnseen(0)) avatar2=target.node.avatar.cloneNode();
var target=targets[0]; else if(!player.isUnseen(1)) avatar2=target.node.avatar2.cloneNode();
if(!target.isUnseen(0)){ else if(get.mode()=='guozhan'&&target.node&&target.node.name_seat){
avatar2=target.node.avatar.cloneNode(); avatar2=ui.create.div('.avatar.cardbg');
} avatar2.innerHTML=target.node.name_seat.innerHTML[0];
else if(!player.isUnseen(1)){ }
avatar2=target.node.avatar2.cloneNode(); else return;
} node.node.avatar2=avatar2;
else if(get.mode()=='guozhan'&&target.node&&target.node.name_seat){ avatar2.style.transform='';
avatar2=ui.create.div('.avatar.cardbg'); avatar2.classList.add('avatar2');
avatar2.innerHTML=target.node.name_seat.innerHTML[0]; avatar2.classList.add('avatar3');
} node.insertBefore(avatar2,avatar);
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&&targets.length){
if(targets.length==1&&targets[0]==player){ if(targets.length==1&&targets[0]==player){
@ -38101,35 +38062,23 @@
node.targets=targets; node.targets=targets;
} }
} }
var fullheight=ui.historybar.offsetHeight; const fullheight=ui.historybar.offsetHeight,num=Math.round((fullheight-8)/50),margin=(fullheight-42*num)/(num+1);
var num=Math.round((fullheight-8)/50);
var margin=(fullheight-42*num)/(num+1);
node.style.transform='scale(0.8)'; node.style.transform='scale(0.8)';
ui.historybar.insertBefore(node,ui.historybar.firstChild); ui.historybar.insertBefore(node,ui.historybar.firstChild);
ui.refresh(node); ui.refresh(node);
node.classList.remove('hidden'); node.classList.remove('hidden');
for(var i=0;i<ui.historybar.childElementCount;i++){ Array.from(ui.historybar.childNodes).forEach((value,index)=>{
var current=ui.historybar.childNodes[i]; if(index<num){
if(i<num){ value.style.transform=`scale(1) translateY(${margin+index*(42+margin)-4}px)`;
current.style.transform='scale(1) translateY('+(margin+i*(42+margin)-4)+'px)'; return;
} }
else{ if(value.removetimeout) return;
if(!current.removetimeout){ value.style.opacity=0;
current.style.opacity=0; value.style.transform=`scale(1) translateY(${fullheight}px)`;
current.style.transform='scale(1) translateY('+fullheight+'px)'; value.removetimeout=setTimeout((current=>()=>current.remove())(value),500);
current.removetimeout=setTimeout((function(current){ });
return function(){ if(lib.config.touchscreen) node.addEventListener('touchstart',ui.click.intro);
current.remove();
};
}(current)),500);
}
}
}
if(lib.config.touchscreen){
node.addEventListener('touchstart',ui.click.intro);
}
else{ else{
// node.addEventListener('mouseenter',ui.click.intro);
node.addEventListener(lib.config.pop_logv?'mousemove':'click',ui.click.logv); node.addEventListener(lib.config.pop_logv?'mousemove':'click',ui.click.logv);
node.addEventListener('mouseleave',ui.click.logvleave); node.addEventListener('mouseleave',ui.click.logvleave);
} }