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){
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;i<ui.historybar.childElementCount;i++){
if(ui.historybar.childNodes[i].logvid==player){
ui.historybar.childNodes[i].added.push(card);break;
}
}
const childNode=Array.from(ui.historybar.childNodes).find(value=>value.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);
}
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();
}
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;
}
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<ui.historybar.childElementCount;i++){
var current=ui.historybar.childNodes[i];
if(i<num){
current.style.transform='scale(1) translateY('+(margin+i*(42+margin)-4)+'px)';
Array.from(ui.historybar.childNodes).forEach((value,index)=>{
if(index<num){
value.style.transform=`scale(1) translateY(${margin+index*(42+margin)-4}px)`;
return;
}
if(value.removetimeout) return;
value.style.opacity=0;
value.style.transform=`scale(1) translateY(${fullheight}px)`;
value.removetimeout=setTimeout((current=>()=>current.remove())(value),500);
});
if(lib.config.touchscreen) node.addEventListener('touchstart',ui.click.intro);
else{
if(!current.removetimeout){
current.style.opacity=0;
current.style.transform='scale(1) translateY('+fullheight+'px)';
current.removetimeout=setTimeout((function(current){
return function(){
current.remove();
};
}(current)),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);
}