From 85021b21cb566574478d28c26abda600e6e1a247 Mon Sep 17 00:00:00 2001 From: kuangthree Date: Sun, 21 Jan 2024 19:28:30 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E2=80=9C=E8=A3=85=E5=A4=87?= =?UTF-8?q?=E7=89=8C=E5=8D=A0=E4=BD=8D=E2=80=9D=E5=BC=80=E5=85=B3=EF=BC=8C?= =?UTF-8?q?=E5=BC=80=E5=90=AF=E5=90=8E=E7=A9=BA=E7=9A=84=E8=A3=85=E5=A4=87?= =?UTF-8?q?=E6=A0=8F=E5=B0=86=E5=8D=A0=E6=8D=AE=E4=BD=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- noname/library/element/player.js | 90 +++++++++++++++++++++++++++++--- noname/library/index.js | 30 +++++++++++ 2 files changed, 113 insertions(+), 7 deletions(-) diff --git a/noname/library/element/player.js b/noname/library/element/player.js index 139e8d356..f4e6a20ef 100644 --- a/noname/library/element/player.js +++ b/noname/library/element/player.js @@ -203,6 +203,22 @@ export class Player extends HTMLDivElement { handcards2: ui.create.div('.handcards'), expansions: ui.create.div('.expansions') }; + if(lib.config.equip_span){ + let observer = new MutationObserver(mutationsList=>{ + for (let mutation of mutationsList) { + if (mutation.type === 'childList') { + const addedNodes = Array.from(mutation.addedNodes); + const removedNodes = Array.from(mutation.removedNodes); + if(addedNodes.some(card=>!card.classList.contains('emptyequip')) || + removedNodes.some(card=>!card.classList.contains('emptyequip'))){ + player.$handleEquipChange(); + } + } + } + }); + const config = { childList: true }; + observer.observe(node.equips, config); + } node.expansions.style.display = 'none'; const chainLength = game.layout == 'default' ? 64 : 40; for (let repetition = 0; repetition < chainLength; repetition++) { @@ -2896,14 +2912,14 @@ export class Player extends HTMLDivElement { } else if (arg1[i] == 'e') { for (j = 0; j < this.node.equips.childElementCount; j++) { - if (!this.node.equips.childNodes[j].classList.contains('removing') && !this.node.equips.childNodes[j].classList.contains('feichu')) { + if (!this.node.equips.childNodes[j].classList.contains('removing') && !this.node.equips.childNodes[j].classList.contains('feichu') && !this.node.equips.childNodes[j].classList.contains('emptyequip')) { cards.push(this.node.equips.childNodes[j]); } } } else if (arg1[i] == 'j') { for (j = 0; j < this.node.judges.childElementCount; j++) { - if (!this.node.judges.childNodes[j].classList.contains('removing') && !this.node.judges.childNodes[j].classList.contains('feichu')) { + if (!this.node.judges.childNodes[j].classList.contains('removing') && !this.node.judges.childNodes[j].classList.contains('feichu') && !this.node.judges.childNodes[j].classList.contains('emptyequip')) { cards.push(this.node.judges.childNodes[j]); if (this.node.judges.childNodes[j].viewAs && arguments.length > 1) { this.node.judges.childNodes[j].tempJudge = this.node.judges.childNodes[j].name; @@ -3074,7 +3090,7 @@ export class Player extends HTMLDivElement { var es = []; if (arg3 !== false) { for (i = 0; i < this.node.equips.childElementCount; i++) { - if (!this.node.equips.childNodes[i].classList.contains('removing') && !this.node.equips.childNodes[i].classList.contains('feichu')) { + if (!this.node.equips.childNodes[i].classList.contains('removing') && !this.node.equips.childNodes[i].classList.contains('feichu') && !this.node.equips.childNodes[i].classList.contains('emptyequip')) { var equipskills = get.info(this.node.equips.childNodes[i]).skills; if (equipskills) { es.addArray(equipskills); @@ -3115,19 +3131,19 @@ export class Player extends HTMLDivElement { for (i = 0; i < arg1.length; i++) { if (arg1[i] == 'h') { for (j = 0; j < this.node.handcards1.childElementCount; j++) { - if (!this.node.handcards1.childNodes[j].classList.contains('removing') && !this.node.handcards1.childNodes[j].classList.contains('feichu') && !this.node.handcards1.childNodes[j].classList.contains('glows')) { + if (!this.node.handcards1.childNodes[j].classList.contains('removing') && !this.node.handcards1.childNodes[j].classList.contains('feichu') && !this.node.handcards1.childNodes[j].classList.contains('emptyequip') && !this.node.handcards1.childNodes[j].classList.contains('glows')) { cards.push(this.node.handcards1.childNodes[j]); } } for (j = 0; j < this.node.handcards2.childElementCount; j++) { - if (!this.node.handcards2.childNodes[j].classList.contains('removing') && !this.node.handcards2.childNodes[j].classList.contains('feichu') && !this.node.handcards2.childNodes[j].classList.contains('glows')) { + if (!this.node.handcards2.childNodes[j].classList.contains('removing') && !this.node.handcards2.childNodes[j].classList.contains('feichu') && !this.node.handcards2.childNodes[j].classList.contains('emptyequip') && !this.node.handcards2.childNodes[j].classList.contains('glows')) { cards.push(this.node.handcards2.childNodes[j]); } } } else if (arg1[i] == 'e') { for (j = 0; j < this.node.equips.childElementCount; j++) { - if (!this.node.equips.childNodes[j].classList.contains('removing') && !this.node.equips.childNodes[j].classList.contains('feichu')) { + if (!this.node.equips.childNodes[j].classList.contains('removing') && !this.node.equips.childNodes[j].classList.contains('feichu') && !this.node.equips.childNodes[j].classList.contains('emptyequip')) { cards.push(this.node.equips.childNodes[j]); } } @@ -3140,7 +3156,7 @@ export class Player extends HTMLDivElement { } else if (arg1[i] == 'j') { for (j = 0; j < this.node.judges.childElementCount; j++) { - if (!this.node.judges.childNodes[j].classList.contains('removing') && !this.node.judges.childNodes[j].classList.contains('feichu')) { + if (!this.node.judges.childNodes[j].classList.contains('removing') && !this.node.judges.childNodes[j].classList.contains('feichu') && !this.node.judges.childNodes[j].classList.contains('emptyequip')) { cards.push(this.node.judges.childNodes[j]); if (this.node.judges.childNodes[j].viewAs && arguments.length > 1) { this.node.judges.childNodes[j].tempJudge = this.node.judges.childNodes[j].name; @@ -9090,6 +9106,66 @@ export class Player extends HTMLDivElement { } } } + $handleEquipChange(){ + let player = this; + const cards = Array.from(this.node.equips.childNodes); + const cardsResume = cards.slice(0); + cards.forEach(card=>{ + if(card.name.indexOf('empty_equip') == 0){ + let num = get.equipNum(card); + let remove = false; + if((num == 4 || num == 3) && get.is.mountCombined()){ + remove = !this.hasEmptySlot('equip3_4') || this.getEquips('equip3_4').length; + }else if(!this.hasEmptySlot(num) || this.getEquips(num).length){ + remove = true; + } + if(remove){ + this.node.equips.removeChild(card); + cardsResume.remove(card); + } + } + }); + for(let i=1;i<=4;i++){ + let add = false; + if((i == 4 || i == 3) && get.is.mountCombined()){ + add = this.hasEmptySlot('equip3_4') && !this.getEquips('equip3_4').length; + }else{ + add = this.hasEmptySlot(i) && !this.getEquips(i).length; + } + if(add && !cardsResume.some(card=>{ + let num = get.equipNum(card); + if((i==4|| i==3) && get.is.mountCombined()){ + return num == 4 || num == 3; + }else{ + return num == i; + } + })){ + const card = game.createCard('empty_equip' + i,'', ''); + card.fix(); + console.log('add '+card.name); + card.style.transform = ''; + card.classList.remove('drawinghidden'); + card.classList.add('emptyequip'); + card.classList.add('hidden'); + delete card._transform; + const equipNum = get.equipNum(card); + let equipped = false; + for (let j = 0; j < player.node.equips.childNodes.length; j++) { + if (get.equipNum(player.node.equips.childNodes[j]) >= equipNum) { + player.node.equips.insertBefore(card, player.node.equips.childNodes[j]); + equipped = true; + break; + } + } + if (!equipped) { + player.node.equips.appendChild(card); + if (_status.discarded) { + _status.discarded.remove(card); + } + } + } + } + } $equip(card) { game.broadcast(function (player, card) { player.$equip(card); diff --git a/noname/library/index.js b/noname/library/index.js index 8aa8a74ed..de78ae4b6 100644 --- a/noname/library/index.js +++ b/noname/library/index.js @@ -3056,6 +3056,12 @@ export class Library extends Uninstantable { lib.init.cssstyles(); } }, + equip_span:{ + name: '装备牌占位', + intro:'打开后,没有装备的装备区将在装备栏占据空白位置。', + init: false, + unfrequent:false, + }, fold_card: { name: '折叠手牌', init: true, @@ -9577,6 +9583,30 @@ export class Library extends Uninstantable { type: "equip", subtype: "equip6", }, + empty_equip1: { + type: "equip", + subtype: "equip1", + }, + empty_equip2: { + type: "equip", + subtype: "equip2", + }, + empty_equip3: { + type: "equip", + subtype: "equip3", + }, + empty_equip4: { + type: "equip", + subtype: "equip4", + }, + empty_equip5: { + type: "equip", + subtype: "equip5", + }, + empty_equip6: { + type: "equip", + subtype: "equip6", + }, zhengsu_leijin: {}, zhengsu_mingzhi: {}, zhengsu_bianzhen: {},