From 49a0439a3492e895e20c38a65f195d87e086b818 Mon Sep 17 00:00:00 2001 From: Tipx-L <138244655+Tipx-L@users.noreply.github.com> Date: Tue, 24 Oct 2023 04:47:53 -0700 Subject: [PATCH 1/3] Fix and decouple `game.updateRoundNumber`. --- game/game.js | 176 ++++++++++++++++++++++++++------------------------- 1 file changed, 91 insertions(+), 85 deletions(-) diff --git a/game/game.js b/game/game.js index a44bc4503..12cfa120e 100644 --- a/game/game.js +++ b/game/game.js @@ -11294,7 +11294,7 @@ return new Promise(resolve=>setTimeout(resolve,500)); }).then(()=>{ ui.updatex(); - ui.create.playerPositions(); + ui.updatePlayerPositions(); return new Promise(resolve=>setTimeout(resolve,500)); }).then(()=>{ ui.updatec(); @@ -42199,10 +42199,13 @@ } }); }, - updateRoundNumber:()=>game.broadcastAll((num1,num2,top)=>{ - if(ui.cardPileNumber) ui.cardPileNumber.innerHTML=`${num1}轮 剩余牌: ${num2}`; - _status.pileTop=top; - },game.roundNumber,ui.cardPile.childNodes.length,ui.cardPile.firstChild), + updateRoundNumber:()=>{ + game.broadcastAll((roundNumber,pileTop)=>{ + if(game.roundNumber!=roundNumber) game.roundNumber=roundNumber; + if(_status.pileTop!=pileTop) _status.pileTop=pileTop; + },game.roundNumber,ui.cardPile.firstChild); + ui.updateRoundNumber(); + }, asyncDraw:(players,num,drawDeck,bottom)=>players.forEach((value,index)=>{ let num2=1; if(typeof num=='number') num2=num; @@ -52094,7 +52097,7 @@ } ui.arena.setNumber=function(num){ this.dataset.number=num; - ui.create.playerPositions(); + ui.updatePlayerPositions(); // if(game.layout=='nova'&&parseInt(num)<7){ // ui.arena.classList.add('player_autolong'); // } @@ -53063,48 +53066,8 @@ } }, player:(position,noclick)=>new lib.element.Player(position,noclick), - /** - * @author curpond - * @author Tipx-L - * @param {number} [numberOfPlayers] - */ - connectPlayerPositions:numberOfPlayers=>{ - if(typeof numberOfPlayers!='number') numberOfPlayers=lib.configOL.number; - if(!numberOfPlayers) return; - const playerPositions=ui.playerPositions; - while(playerPositions.length){ - playerPositions.pop().remove(); - } - const temporaryPlayer=ui.create.div('.player.connect',ui.window).hide(); - const computedStyle=getComputedStyle(temporaryPlayer); - const halfWidth=parseFloat(computedStyle.width)/2; - const halfHeight=parseFloat(computedStyle.height)/2; - temporaryPlayer.remove(); - const halfNumberOfPlayers=Math.round(numberOfPlayers/2); - const upperPercentage=100/(halfNumberOfPlayers+1); - const scale=10/numberOfPlayers; - for(let ordinal=0;ordinal.player.connect[data-position='${ordinal}']{`, - `left:calc(${upperPercentage*(ordinal+1)}% - ${halfWidth}px);`, - `top:calc(${100/3}% - ${halfHeight}px);`, - scale<1?`transform:scale(${scale});`:'', - '}' - ].join(''))); - } - const lowerPercentage=100/(numberOfPlayers-halfNumberOfPlayers+1); - for(let ordinal=halfNumberOfPlayers;ordinal.player.connect[data-position='${ordinal}']{`, - `left:calc(${lowerPercentage*(ordinal-halfNumberOfPlayers+1)}% - ${halfWidth}px);`, - `top:calc(${100*2/3}% - ${halfHeight}px);`, - scale<1?`transform:scale(${scale});`:'', - '}' - ].join(''))); - } - }, connectPlayers:ip=>{ - ui.create.connectPlayerPositions(); + ui.updateConnectPlayerPositions(); game.connectPlayers=[]; const numberOfPlayers=lib.configOL.number; for(let position=0;position{ - if(typeof numberOfPlayers!='number') numberOfPlayers=ui.arena.dataset.number; - //当人数小于8时,还是用以前的布局。 - if(!numberOfPlayers||numberOfPlayers<9) return; - const playerPositions=ui.playerPositions; - while(playerPositions.length){ - playerPositions.pop().remove(); - } - //单个人物的宽度。这里要设置玩家的实际的宽度 - const temporaryPlayer=ui.create.div('.player',ui.arena).hide(); - const computedStyle=getComputedStyle(temporaryPlayer); - const scale=6/numberOfPlayers; - //玩家顶部距离父容器上边缘的距离偏移的单位距离 - const quarterHeight=parseFloat(computedStyle.height)/4*scale; - const halfWidth=parseFloat(computedStyle.width)/2; - temporaryPlayer.remove(); - //列数,即假如8人场,除去自己后,上面7个人占7列 - const columnCount=numberOfPlayers-1; - const percentage=90/(columnCount-1); - //仅当游戏人数大于8人,且玩家的座位号大于0时,设置玩家的位置。因为0号位是game.me在最下方,无需设置。 - for(let ordinal=1;ordinal.player[data-position='${ordinal}']{`, - `left:calc(${percentage*reversedOrdinal+5}% - ${halfWidth}px);`, - `top:${top}px;`, - `transform:scale(${scale});`, - '}' - ].join(''))); - } - }, players:numberOfPlayers=>{ if(numberOfPlayers===0){ return; @@ -57893,6 +57818,87 @@ } ui._recycle[key]=node; }, + /** + * @author curpond + * @author Tipx-L + * @param {number} [numberOfPlayers] + */ + updateConnectPlayerPositions:numberOfPlayers=>{ + if(typeof numberOfPlayers!='number') numberOfPlayers=lib.configOL.number; + if(!numberOfPlayers) return; + const playerPositions=ui.playerPositions; + while(playerPositions.length){ + playerPositions.pop().remove(); + } + const temporaryPlayer=ui.create.div('.player.connect',ui.window).hide(); + const computedStyle=getComputedStyle(temporaryPlayer); + const halfWidth=parseFloat(computedStyle.width)/2; + const halfHeight=parseFloat(computedStyle.height)/2; + temporaryPlayer.remove(); + const halfNumberOfPlayers=Math.round(numberOfPlayers/2); + const upperPercentage=100/(halfNumberOfPlayers+1); + const scale=10/numberOfPlayers; + for(let ordinal=0;ordinal.player.connect[data-position='${ordinal}']{`, + `left:calc(${upperPercentage*(ordinal+1)}% - ${halfWidth}px);`, + `top:calc(${100/3}% - ${halfHeight}px);`, + scale<1?`transform:scale(${scale});`:'', + '}' + ].join(''))); + } + const lowerPercentage=100/(numberOfPlayers-halfNumberOfPlayers+1); + for(let ordinal=halfNumberOfPlayers;ordinal.player.connect[data-position='${ordinal}']{`, + `left:calc(${lowerPercentage*(ordinal-halfNumberOfPlayers+1)}% - ${halfWidth}px);`, + `top:calc(${100*2/3}% - ${halfHeight}px);`, + scale<1?`transform:scale(${scale});`:'', + '}' + ].join(''))); + } + }, + /** + * @author curpond + * @author Tipx-L + * @param {number} [numberOfPlayers] + */ + updatePlayerPositions:numberOfPlayers=>{ + if(typeof numberOfPlayers!='number') numberOfPlayers=ui.arena.dataset.number; + //当人数小于8时,还是用以前的布局。 + if(!numberOfPlayers||numberOfPlayers<9) return; + const playerPositions=ui.playerPositions; + while(playerPositions.length){ + playerPositions.pop().remove(); + } + //单个人物的宽度。这里要设置玩家的实际的宽度 + const temporaryPlayer=ui.create.div('.player',ui.arena).hide(); + const computedStyle=getComputedStyle(temporaryPlayer); + const scale=6/numberOfPlayers; + //玩家顶部距离父容器上边缘的距离偏移的单位距离 + const quarterHeight=parseFloat(computedStyle.height)/4*scale; + const halfWidth=parseFloat(computedStyle.width)/2; + temporaryPlayer.remove(); + //列数,即假如8人场,除去自己后,上面7个人占7列 + const columnCount=numberOfPlayers-1; + const percentage=90/(columnCount-1); + //仅当游戏人数大于8人,且玩家的座位号大于0时,设置玩家的位置。因为0号位是game.me在最下方,无需设置。 + for(let ordinal=1;ordinal.player[data-position='${ordinal}']{`, + `left:calc(${percentage*reversedOrdinal+5}% - ${halfWidth}px);`, + `top:${top}px;`, + `transform:scale(${scale});`, + '}' + ].join(''))); + } + }, + updateRoundNumber:()=>game.broadcastAll((roundNumber,cardPileNumber)=>{ + if(ui.cardPileNumber) ui.cardPileNumber.innerHTML=`${roundNumber}轮 剩余牌: ${cardPileNumber}`; + },game.roundNumber,ui.cardPile.childElementCount) }; const get={ /** From 00072acb3931ab9297ea0e16372be43fdfde7716 Mon Sep 17 00:00:00 2001 From: Tipx-L <138244655+Tipx-L@users.noreply.github.com> Date: Wed, 25 Oct 2023 07:00:49 -0700 Subject: [PATCH 2/3] Fix `ui.click.ok` and eliminate all shorthand name usages of object initializing. --- game/game.js | 52 +++++++++++++++++++++++++++------------------------- 1 file changed, 27 insertions(+), 25 deletions(-) diff --git a/game/game.js b/game/game.js index 12cfa120e..32d3fed23 100644 --- a/game/game.js +++ b/game/game.js @@ -5742,7 +5742,7 @@ name:'游戏人数', init:'8', get item(){ - const minimumNumberOfPlayers=3,maximumNumberOfPlayers=Math.max(_status.maximumNumberOfPlayers||10,minimumNumberOfPlayers),item={}; + const minimumNumberOfPlayers=2,maximumNumberOfPlayers=Math.max(_status.maximumNumberOfPlayers||12,minimumNumberOfPlayers),item={}; for(let playerNumber=minimumNumberOfPlayers;playerNumber<=maximumNumberOfPlayers;playerNumber++){ item[playerNumber]=`${get.cnNumber(playerNumber)}人`; } @@ -23172,6 +23172,11 @@ } return list; } + /** + * @param {string} [arg1='h'] + * @param {string | Record | (card: Card) => boolean} [arg2] + * @returns {Card[]} + */ getCards(arg1,arg2){ if(typeof arg1!='string'){ arg1='h'; @@ -30585,7 +30590,7 @@ else Object.defineProperty(this,key,propertyDescriptor); }); if(Array.isArray(numberOrCards)){ - const noCards=!('cards' in this); + const noCards=!this.cards; /** * @type {Card[]} */ @@ -30593,8 +30598,8 @@ if(noCards){ if(!lib.suits.includes(this.suit)) this.suit=get.suit(this); if(!Object.keys(lib.color).includes(this.color)) this.color=get.color(this); - if(!('number' in this)) this.number=get.number(this); - if(!('nature' in this)) this.nature=get.nature(this); + if(typeof this.number!='number') this.number=get.number(this); + if(!this.nature) this.nature=get.nature(this); } } const info=get.info(this,false); @@ -30607,9 +30612,8 @@ if(typeof numberOrCards=='number') this.number=numberOrCards; if(typeof name=='string') this.name=name; if(typeof nature=='string') this.nature=nature; - if('suit' in this&&!('color' in this)) this.color=get.color(this); - if(!('storage' in this)) this.storage={}; - if(!('cards' in this)) this.cards=[]; + if(!this.storage) this.storage={}; + if(!this.cards) this.cards=[]; } sameSuitAs(card){ return get.suit(this)==get.suit(card); @@ -31537,7 +31541,6 @@ return this; } /** - * @throws {'Do not call this method'} * @returns {never} */ typeAnnotation(){ @@ -31613,7 +31616,7 @@ * @type {boolean} */ this.unreal; - throw 'Do not call this method'; + throw new Error('Do not call this method'); } }, Dialog:class extends HTMLDivElement{ @@ -32899,7 +32902,7 @@ }, directHit_ai:true, skillTagFilter:(player,tag,arg)=>{ - const card=arg.card; + const card=get.autoViewAs(arg.card); if(card.name!='sha'||!card.storage.stratagem_buffed) return false; const target=arg.target; if(target.countCards('h','shan')>=1&&!target.storage.stratagem_fury) return false; @@ -56121,22 +56124,21 @@ const skillInformation=get.info(gameEvent.skill),viewAs=skillInformation.viewAs; if(typeof viewAs=='function'){ const viewedAs=viewAs(result.cards,gameEvent.player); - if(viewedAs){ - viewedAs.cards=result.cards; - result.card=get.autoViewAs(viewedAs); + if(viewedAs) result.card=get.autoViewAs(viewedAs); + } + else if(viewAs) result.card=get.autoViewAs(viewAs); + const resultCard=result.card; + if(resultCard){ + const cards=result.cards; + if(cards.length==1){ + const firstCard=cards[0]; + if(!resultCard.suit) resultCard.suit=get.suit(firstCard); + if(!resultCard.number) resultCard.number=get.number(firstCard); } } - else if(viewAs){ - viewAs.cards=result.cards; - result.card=get.autoViewAs(viewAs); - } - if(gameEvent.skillDialog&&get.objtype(gameEvent.skillDialog)=='div'){ - gameEvent.skillDialog.close(); - } - var cards=gameEvent.player.getCards('hej'); - for(var i=0;icard.recheck('useSkill')); gameEvent.restore(); } else if(['chooseToUse','chooseToRespond'].includes(gameEvent.name)) result.card=get.autoViewAs(result.cards[0]); @@ -62616,7 +62618,7 @@ } } }, - get + get:get }; /** * @template T From eee7e729922e41ce653e26e34f5386c5ea5893bc Mon Sep 17 00:00:00 2001 From: Tipx-L <138244655+Tipx-L@users.noreply.github.com> Date: Wed, 25 Oct 2023 09:17:46 -0700 Subject: [PATCH 3/3] Fix the loading screen when `lib.init.layout`. --- game/game.js | 18 ++++++------------ layout/default/layout.css | 25 +++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 12 deletions(-) diff --git a/game/game.js b/game/game.js index 32d3fed23..ea859db0c 100644 --- a/game/game.js +++ b/game/game.js @@ -11184,10 +11184,10 @@ } }, layout:function(layout,nosave){ - const previousTransitionDuration=document.documentElement.style.transitionDuration; - document.documentElement.style.transitionDuration='1s'; - const previousFilter=document.documentElement.style.filter,previousWebkitFilter=document.documentElement.style.webkitFilter; - document.documentElement.style.filter=document.documentElement.style.webkitFilter='brightness(0)'; + const loadingScreen=ui.create.div('.loading-screen',document.body),loadingScreenStyle=loadingScreen.style; + loadingScreenStyle.animationDuration='1s'; + loadingScreenStyle.animationFillMode='forwards'; + loadingScreenStyle.animationName='opacity-0-1'; if(layout=='default') layout='mobile'; if(!nosave) game.saveConfig('layout',layout); game.layout=layout; @@ -11298,14 +11298,8 @@ return new Promise(resolve=>setTimeout(resolve,500)); }).then(()=>{ ui.updatec(); - if(previousFilter) document.documentElement.style.filter=previousFilter; - else document.documentElement.style.removeProperty('filter'); - if(previousWebkitFilter) document.documentElement.style.webkitFilter=previousWebkitFilter; - else document.documentElement.style.removeProperty('-webkit-filter'); - return new Promise(resolve=>setTimeout(resolve,1000)); - }).then(()=>{ - if(previousTransitionDuration) document.documentElement.style.transitionDuration=previousTransitionDuration; - else document.documentElement.style.removeProperty('transition-duration'); + loadingScreenStyle.animationName='opacity-1-0'; + loadingScreen.addEventListener('animationend',animationEvent=>animationEvent.target.remove()); }); }, background:function(){ diff --git a/layout/default/layout.css b/layout/default/layout.css index d0ddebad6..65b5ea108 100644 --- a/layout/default/layout.css +++ b/layout/default/layout.css @@ -5041,6 +5041,13 @@ div[data-decoration="bronze"]::after{ border-radius: 16px; } +.loading-screen { + background-color: black; + height: 100%; + width: 100%; + z-index: 31415926; +} + /*--------动画--------*/ @keyframes shadow_thunder { 0% { @@ -5542,6 +5549,24 @@ div[data-decoration="bronze"]::after{ background-position: left center; } } +@keyframes opacity-0-1 { + from { + opacity: 0; + } + + to { + opacity: 1; + } +} +@keyframes opacity-1-0 { + from { + opacity: 1; + } + + to { + opacity: 0; + } +} /*--------其它--------*/ ::-webkit-scrollbar { display: none;