From 57398a4ea4a112cc2c152c3224d0c2bc39102ed4 Mon Sep 17 00:00:00 2001 From: Tipx-L <138244655+Tipx-L@users.noreply.github.com> Date: Thu, 24 Aug 2023 06:33:56 -0700 Subject: [PATCH 01/43] Optimize game.countGroup. (cherry picked from commit 0eac481969bcd104bf818e35889ed4fc1a0742f3) --- game/game.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/game/game.js b/game/game.js index 4e0db2c5a..dcb7e96c9 100644 --- a/game/game.js +++ b/game/game.js @@ -38815,13 +38815,12 @@ } return cards; }, - countGroup:function(){ - var list=lib.group.slice(0); - return game.countPlayer(function(current){ - if(list.contains(current.group)){ - list.remove(current.group); - return true; - } + countGroup:()=>{ + const list=lib.group.slice(0); + return game.countPlayer(current=>{ + if(!list.includes(current.group)) return false; + list.remove(current.group); + return true; }); }, players:[], From 60a1d59aa4f29bae56a3fc5dd571fa714fd2cf29 Mon Sep 17 00:00:00 2001 From: Tipx-L <138244655+Tipx-L@users.noreply.github.com> Date: Thu, 24 Aug 2023 06:34:39 -0700 Subject: [PATCH 02/43] Optimize game.findCards. (cherry picked from commit 7a80e7ed521bf8f54df35e715f026e91682e3164) --- game/game.js | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/game/game.js b/game/game.js index dcb7e96c9..bb6c35aad 100644 --- a/game/game.js +++ b/game/game.js @@ -38803,18 +38803,12 @@ } return null; }, - findCards:function(func,all){ - var cards=[]; - for(var i in lib.card){ - if(!lib.translate[i+'_info']) continue; - if(lib.card[i].mode&&lib.card[i].mode.contains(lib.config.mode)==false) continue; - if(!all&&!lib.inpile.contains(i)) continue; - if(func(i,lib.card[i])){ - cards.push(i); - } - } - return cards; - }, + findCards:(func,all)=>Object.keys(lib.card).filter(value=>{ + if(!lib.translate[`${value}_info`]) return false; + if(lib.card[value].mode&&lib.card[value].mode.includes(lib.config.mode)==false) return false; + if(!all&&!lib.inpile.includes(value)) return false; + return func(value,lib.card[value]); + }), countGroup:()=>{ const list=lib.group.slice(0); return game.countPlayer(current=>{ From 762ea0dc6c84d00a1289020a95cf88b7a9eaf99d Mon Sep 17 00:00:00 2001 From: Tipx-L <138244655+Tipx-L@users.noreply.github.com> Date: Thu, 24 Aug 2023 06:37:33 -0700 Subject: [PATCH 03/43] Optimize game.findPlayer2. (cherry picked from commit e4f85f6b5c5f95269babf777034a3b145f3d5736) --- game/game.js | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/game/game.js b/game/game.js index bb6c35aad..8d416413b 100644 --- a/game/game.js +++ b/game/game.js @@ -38793,16 +38793,7 @@ } return null; }, - findPlayer2:function(func,includeOut){ - var players=game.players.slice(0).concat(game.dead); - for(var i=0;igame.players.concat(game.dead).find(value=>(includeOut||!value.isOut())&&func(value))||null, findCards:(func,all)=>Object.keys(lib.card).filter(value=>{ if(!lib.translate[`${value}_info`]) return false; if(lib.card[value].mode&&lib.card[value].mode.includes(lib.config.mode)==false) return false; From d0e1063a9b5e97522c42772ae2af1e69e8b0df44 Mon Sep 17 00:00:00 2001 From: Tipx-L <138244655+Tipx-L@users.noreply.github.com> Date: Thu, 24 Aug 2023 06:38:17 -0700 Subject: [PATCH 04/43] Optimize game.findPlayer. (cherry picked from commit 9819bceb12a930c4be2f4a189def95ba0f0568ce) --- game/game.js | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/game/game.js b/game/game.js index 8d416413b..cb3d03c1d 100644 --- a/game/game.js +++ b/game/game.js @@ -38784,15 +38784,7 @@ if(typeof func!='function') func=lib.filter.all; return list.addArray(game.players.concat(game.dead).filter(value=>(includeOut||!value.isOut())&&func(value))); }, - findPlayer:function(func,includeOut){ - for(var i=0;igame.players.find(value=>(includeOut||!value.isOut())&&func(value))||null, findPlayer2:(func,includeOut)=>game.players.concat(game.dead).find(value=>(includeOut||!value.isOut())&&func(value))||null, findCards:(func,all)=>Object.keys(lib.card).filter(value=>{ if(!lib.translate[`${value}_info`]) return false; From ed19d18f75260b5a79d3d38e33eace83b6c6d271 Mon Sep 17 00:00:00 2001 From: Tipx-L <138244655+Tipx-L@users.noreply.github.com> Date: Thu, 24 Aug 2023 06:39:26 -0700 Subject: [PATCH 05/43] Optimize game.countPlayer2. (cherry picked from commit e6af8abe7b7826bb6c7dc005f8f6c8106cc59c06) --- game/game.js | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/game/game.js b/game/game.js index cb3d03c1d..20d3dca8c 100644 --- a/game/game.js +++ b/game/game.js @@ -38756,23 +38756,15 @@ } return num; }, - countPlayer2:function(func,includeOut){ - var num=0; - if(typeof func!='function'){ - func=lib.filter.all; - } - var players=game.players.slice(0).concat(game.dead); - for(var i=0;i{ + if(typeof func!='function') func=lib.filter.all; + return game.players.concat(game.dead).reduce((previousValue,currentValue)=>{ + if(!includeOut&¤tValue.isOut()) return previousValue; + const result=func(currentValue); + if(typeof result=='number') previousValue+=result; + else if(result) previousValue++; + return previousValue; + },0); }, filterPlayer:(func,list,includeOut)=>{ if(!Array.isArray(list)) list=[]; From 674f45e8b83a0553e0ecb3d4da9afe70255e75cd Mon Sep 17 00:00:00 2001 From: Tipx-L <138244655+Tipx-L@users.noreply.github.com> Date: Thu, 24 Aug 2023 06:45:37 -0700 Subject: [PATCH 06/43] Optimize game.countPlayer. (cherry picked from commit df9c74b86040e6e576b643e8f094cec99372b397) --- game/game.js | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/game/game.js b/game/game.js index 20d3dca8c..ece9f4052 100644 --- a/game/game.js +++ b/game/game.js @@ -38739,22 +38739,15 @@ } return false; }, - countPlayer:function(func,includeOut){ - var num=0; - if(typeof func!='function'){ - func=lib.filter.all; - } - for(var i=0;i{ + if(typeof func!='function') func=lib.filter.all; + return game.players.reduce((previousValue,currentValue)=>{ + if(!includeOut&¤tValue.isOut()) return previousValue; + const result=func(currentValue); + if(typeof result=='number') previousValue+=result; + else if(result) previousValue++; + return previousValue; + },0); }, countPlayer2:(func,includeOut)=>{ if(typeof func!='function') func=lib.filter.all; From 0a544d01b3ee8f899f3e9fdf7029f25becf476fb Mon Sep 17 00:00:00 2001 From: Tipx-L <138244655+Tipx-L@users.noreply.github.com> Date: Thu, 24 Aug 2023 06:49:51 -0700 Subject: [PATCH 07/43] Optimize game.hasPlayer2. (cherry picked from commit ba85e81ecf38f41039295bcf440b1c6a89d4067e) --- game/game.js | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/game/game.js b/game/game.js index ece9f4052..c1dba89d9 100644 --- a/game/game.js +++ b/game/game.js @@ -38731,14 +38731,7 @@ } return false; }, - hasPlayer2:function(func,includeOut){ - var players=game.players.slice(0).concat(game.dead); - for(var i=0;igame.players.concat(game.dead).some(value=>(includeOut||!value.isOut())&&func(value)), countPlayer:(func,includeOut)=>{ if(typeof func!='function') func=lib.filter.all; return game.players.reduce((previousValue,currentValue)=>{ From 4e66afb155f844fb0a362c188b90b1a6fa4ed67c Mon Sep 17 00:00:00 2001 From: Tipx-L <138244655+Tipx-L@users.noreply.github.com> Date: Thu, 24 Aug 2023 06:53:37 -0700 Subject: [PATCH 08/43] Optimize game.hasPlayer. (cherry picked from commit 82333a3751f150f6108122a34279952d2b21d43d) --- game/game.js | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/game/game.js b/game/game.js index c1dba89d9..a69fb1153 100644 --- a/game/game.js +++ b/game/game.js @@ -38724,13 +38724,7 @@ } } }, - hasPlayer:function(func,includeOut){ - for(var i=0;igame.players.some(value=>(includeOut||!value.isOut())&&func(value)), hasPlayer2:(func,includeOut)=>game.players.concat(game.dead).some(value=>(includeOut||!value.isOut())&&func(value)), countPlayer:(func,includeOut)=>{ if(typeof func!='function') func=lib.filter.all; From 71a801e279be89e515fd21a31628ce02bb5a5981 Mon Sep 17 00:00:00 2001 From: Tipx-L <138244655+Tipx-L@users.noreply.github.com> Date: Thu, 24 Aug 2023 07:01:33 -0700 Subject: [PATCH 09/43] Optimize game.css. (cherry picked from commit dcf133dfaf344e56503890904293b88511896be9) --- game/game.js | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/game/game.js b/game/game.js index a69fb1153..2c2e70396 100644 --- a/game/game.js +++ b/game/game.js @@ -38714,16 +38714,14 @@ } return skills; }, - css:function(style){ - for(var i in style){ - if(ui.style[i]) ui.style[i].innerHTML=i+JSON.stringify(style[i]).replace(/"/g,""); - else{ - ui.style[i]=document.createElement('style'); - ui.style[i].innerHTML=i+JSON.stringify(style[i]).replace(/"/g,""); - document.head.appendChild(ui.style[i]); - } + css:style=>Object.keys(style).forEach(value=>{ + let uiStyle=ui.style[value]; + if(!uiStyle){ + uiStyle=ui.style[value]=document.createElement('style'); + document.head.appendChild(uiStyle); } - }, + uiStyle.innerHTML=`${value}${JSON.stringify(style[value]).replace(/"/g,"")}`; + }), hasPlayer:(func,includeOut)=>game.players.some(value=>(includeOut||!value.isOut())&&func(value)), hasPlayer2:(func,includeOut)=>game.players.concat(game.dead).some(value=>(includeOut||!value.isOut())&&func(value)), countPlayer:(func,includeOut)=>{ From b6ca7b534ee753a6dad79fac7661cdcd45a2c783 Mon Sep 17 00:00:00 2001 From: Tipx-L <138244655+Tipx-L@users.noreply.github.com> Date: Thu, 24 Aug 2023 07:21:19 -0700 Subject: [PATCH 10/43] Optimize game.expandSkills. (cherry picked from commit fcc1d48119587ec9bb7a1e5f2470ee7c3dd3c1cb) --- game/game.js | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/game/game.js b/game/game.js index 2c2e70396..c491e1cd8 100644 --- a/game/game.js +++ b/game/game.js @@ -38698,22 +38698,15 @@ } return out; }, - expandSkills:function(skills){ - var skills2=[]; - for(var i=0;iskills.addArray(skills.reduce((previousValue,currentValue)=>{ + const info=get.info(currentValue); + if(info){ + if(Array.isArray(info.group)) previousValue.push(...info.group); + else if(info.group) previousValue.push(info.group); } - for(var i=0;iObject.keys(style).forEach(value=>{ let uiStyle=ui.style[value]; if(!uiStyle){ From 940b0086d5d87c715ac6531b4fda6c33654a3304 Mon Sep 17 00:00:00 2001 From: Tipx-L <138244655+Tipx-L@users.noreply.github.com> Date: Thu, 24 Aug 2023 07:26:23 -0700 Subject: [PATCH 11/43] Optimize game.filterSkills. (cherry picked from commit 570a9935d734c82ef986841f4ad43095053e8ddb) --- game/game.js | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/game/game.js b/game/game.js index c491e1cd8..35d767167 100644 --- a/game/game.js +++ b/game/game.js @@ -38686,17 +38686,10 @@ } } }, - filterSkills:function(skills,player,exclude){ - var out=skills.slice(0); - for(var i in player.disabledSkills){ - out.remove(i); - } - if(player.storage.skill_blocker&&player.storage.skill_blocker.length){ - for(var i=0;i{ + const out=skills.slice().removeArray(Object.keys(player.disabledSkills)); + if(!player.storage.skill_blocker||!player.storage.skill_blocker.length) return out; + return out.filter(value=>exclude&&exclude.includes(value)||!get.is.blocked(value,player)); }, expandSkills:skills=>skills.addArray(skills.reduce((previousValue,currentValue)=>{ const info=get.info(currentValue); From 65cb9d6172adf755e2f12c23a5cfb0193e5f908d Mon Sep 17 00:00:00 2001 From: Tipx-L <138244655+Tipx-L@users.noreply.github.com> Date: Thu, 24 Aug 2023 07:29:40 -0700 Subject: [PATCH 12/43] Optimize game.arrangePlayers. (cherry picked from commit e8dffce889b2bd9bf06e48df70fd5eb375e22802) --- game/game.js | 109 ++++++++++++++------------------------------------- 1 file changed, 29 insertions(+), 80 deletions(-) diff --git a/game/game.js b/game/game.js index 35d767167..fb8c57352 100644 --- a/game/game.js +++ b/game/game.js @@ -38600,91 +38600,40 @@ } return player2; }, - arrangePlayers:function(){ + arrangePlayers:()=>{ if(game.chess&&game.me){ - var friendCount=0; - var enemyCount=0; - var rand=Math.random()<0.5; - for(var i=0;i{ + if(value.side==game.me.side){ + if(rand) if(value==game.friendZhu) sortCount.set(value,-2); + else sortCount.set(value,2*friendCount); + else if(value==game.friendZhu) sortCount.set(value,-1); + else sortCount.set(value,2*friendCount+1); friendCount++; + return; } - else{ - if(rand){ - if(game.players[i]==game.enemyZhu){ - game.players[i]._sortCount=-1; - } - else{ - game.players[i]._sortCount=2*enemyCount+1; - } - } - else{ - if(game.players[i]==game.enemyZhu){ - game.players[i]._sortCount=-2; - } - else{ - game.players[i]._sortCount=2*enemyCount; - } - } - enemyCount++; - } - } - game.players.sort(function(a,b){ - return a._sortCount-b._sortCount; + if(rand) if(value==game.enemyZhu) sortCount.set(value,-1); + else sortCount.set(value,2*enemyCount+1); + else if(value==game.enemyZhu) sortCount.set(value,-2); + else sortCount.set(value,2*enemyCount); + enemyCount++; }); - for(var i=0;isortCount.get(a)-sortCount.get(b)); } + else game.players.sort(lib.sort.position); + game.players.concat(game.dead).sort(lib.sort.position).forEach((value,index,array)=>{ + if(index==0) value.previousSeat=array[array.length-1]; + else value.previousSeat=array[index-1]; + if(index==array.length-1) value.nextSeat=array[0]; + else value.nextSeat=array[index+1]; + }); + game.players.forEach((value,index,array)=>{ + if(index==0) value.previous=array[array.length-1]; + else value.previous=array[index-1]; + if(index==array.length-1) value.next=array[0]; + else value.next=array[index+1]; + }); }, filterSkills:(skills,player,exclude)=>{ const out=skills.slice().removeArray(Object.keys(player.disabledSkills)); From 9d760011de1f28d366bffa4e1958a9608a218128 Mon Sep 17 00:00:00 2001 From: Tipx-L <138244655+Tipx-L@users.noreply.github.com> Date: Thu, 24 Aug 2023 07:53:40 -0700 Subject: [PATCH 13/43] Optimize game.replacePlayer. (cherry picked from commit bb0f329ac931b154be0aa490d9192b92e8b68a93) --- game/game.js | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/game/game.js b/game/game.js index fb8c57352..dfb3d8a18 100644 --- a/game/game.js +++ b/game/game.js @@ -38573,13 +38573,13 @@ },500); return player; }, - replacePlayer:function(player,character,character2){ + replacePlayer:(player,character,character2)=>{ player.removed=true; - var position=parseInt(player.dataset.position); + const position=parseInt(player.dataset.position); game.players.remove(player); game.dead.remove(player); player.delete(); - var player2=ui.create.player(ui.arena).animate('start'); + const player2=ui.create.player(ui.arena).animate('start'); if(character) player2.init(character,character2); game.players.push(player2); player2.dataset.position=position; @@ -38587,17 +38587,19 @@ player2.previousSeat=player.previousSeat; player2.nextSeat.previousSeat=player2; player2.previousSeat.nextSeat=player2; - var player3=player2.nextSeat; - while(player3.isDead()) player3=player3.nextSeat; + const player3=player2.nextSeat; + while(player3.isDead()){ + player3=player3.nextSeat; + } player3.previous=player2; player2.next=player3; - var player4=player2.previousSeat; - while(player4.isDead()) player4=player4.previousSeat; + const player4=player2.previousSeat; + while(player4.isDead()){ + player4=player4.previousSeat; + } player4.next=player2; player2.previous=player4; - if(_status.roundStart==player){ - _status.roundStart=player2; - } + if(_status.roundStart==player) _status.roundStart=player2; return player2; }, arrangePlayers:()=>{ From b7ebba8f53910fd0efa48b982940486a5fe78317 Mon Sep 17 00:00:00 2001 From: Tipx-L <138244655+Tipx-L@users.noreply.github.com> Date: Thu, 24 Aug 2023 07:58:13 -0700 Subject: [PATCH 14/43] Optimize game.removePlayer. (cherry picked from commit 662380e02d1e72d0867d07b0318b08b1e8066661) --- game/game.js | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/game/game.js b/game/game.js index dfb3d8a18..5b398fb23 100644 --- a/game/game.js +++ b/game/game.js @@ -38538,20 +38538,16 @@ game.arrangePlayers(); return player; }, - removePlayer:function(player){ - if(_status.roundStart==player){ - _status.roundStart=player.next||player.getNext()||game.players[0]; - } - var players=game.players.concat(game.dead); - player.style.left=player.getLeft()+'px'; - player.style.top=player.getTop()+'px'; + removePlayer:player=>{ + if(_status.roundStart==player) _status.roundStart=player.next||player.getNext()||game.players[0]; + const players=game.players.concat(game.dead); + player.style.left=`${player.getLeft()}px`; + player.style.top=`${player.getTop()}px`; if(player==undefined) player=game.dead[0]||game.me.next; - var position=parseInt(player.dataset.position); - for(var i=0;iposition){ - players[i].dataset.position=parseInt(players[i].dataset.position)-1; - } - } + const position=parseInt(player.dataset.position); + players.forEach(value=>{ + if(parseInt(value.dataset.position)>position) value.dataset.position=parseInt(value.dataset.position)-1; + }); if(player.isAlive()){ player.next.previous=player.previous; player.previous.next=player.next; @@ -38568,9 +38564,7 @@ ui.auto.hide(); ui.wuxie.hide(); } - setTimeout(function(){ - player.removeAttribute('style'); - },500); + setTimeout(()=>player.removeAttribute('style'),500); return player; }, replacePlayer:(player,character,character2)=>{ From bbde8b2cb9cac54439bec284996e40be07095271 Mon Sep 17 00:00:00 2001 From: Tipx-L <138244655+Tipx-L@users.noreply.github.com> Date: Thu, 24 Aug 2023 08:00:19 -0700 Subject: [PATCH 15/43] Optimize game.restorePlayer. (cherry picked from commit 906e5d6b2c78d2837ec68eef63d093cef2da65fe) --- game/game.js | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/game/game.js b/game/game.js index 5b398fb23..84b085546 100644 --- a/game/game.js +++ b/game/game.js @@ -38517,19 +38517,15 @@ event.trigger('enterGame'); }); }, - restorePlayer:function(player){ + restorePlayer:player=>{ if(game.players.contains(player)||game.dead.contains(player)) return; - var position=parseInt(player.dataset.position); - if(position<0||position>game.players.length+game.dead.length||position==undefined){ - position=Math.ceil(Math.random()*(game.players.length+game.dead.length)); - } - var players=game.players.concat(game.dead); + let position=parseInt(player.dataset.position); + if(position<0||position>game.players.length+game.dead.length||position==undefined) position=Math.ceil(Math.random()*(game.players.length+game.dead.length)); + const players=game.players.concat(game.dead); ui.arena.setNumber(players.length+1); - for(var i=0;i=position){ - players[i].dataset.position=parseInt(players[i].dataset.position)+1; - } - } + players.forEach(value=>{ + if(parseInt(value.dataset.position)>=position) value.dataset.position=parseInt(value.dataset.position)+1; + }); game.players.push(player); delete player.removed; player.removeAttribute('style'); From 944cb075e3c060c982f7538ece7051051bb0a718 Mon Sep 17 00:00:00 2001 From: Tipx-L <138244655+Tipx-L@users.noreply.github.com> Date: Thu, 24 Aug 2023 08:01:53 -0700 Subject: [PATCH 16/43] Optimize game.triggerEnter. (cherry picked from commit fb12fecfda619fc880ccbc0ba7b03024f1f0f990) --- game/game.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/game/game.js b/game/game.js index 84b085546..474eba68c 100644 --- a/game/game.js +++ b/game/game.js @@ -38510,12 +38510,13 @@ game.players.push(player);game.arrangePlayers(); return player; }, - triggerEnter:function(player){ - var next=game.createEvent('enterGame',false); + triggerEnter:player=>{ + const next=game.createEvent('enterGame',false); next.player=player; - next.setContent(function(){ + next.setContent(()=>{ event.trigger('enterGame'); }); + return next; }, restorePlayer:player=>{ if(game.players.contains(player)||game.dead.contains(player)) return; From 5536c0bbd9094a8bfe31cf1a1ee702db4a030ca1 Mon Sep 17 00:00:00 2001 From: Tipx-L <138244655+Tipx-L@users.noreply.github.com> Date: Thu, 24 Aug 2023 08:02:17 -0700 Subject: [PATCH 17/43] Optimize game.addFellow. (cherry picked from commit 5ec4bcd30c920726d2a7411de5bd8349a53ede2f) --- game/game.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/game/game.js b/game/game.js index 474eba68c..f86c02497 100644 --- a/game/game.js +++ b/game/game.js @@ -38501,13 +38501,14 @@ game.arrangePlayers(); return player; }, - addFellow:function(position,character,animation){ + addFellow:(position,character,animation)=>{ game.addVideo('addFellow',null,[position,character,animation]); - var player=ui.create.player(ui.arena).animate(animation||'start'); + const player=ui.create.player(ui.arena).animate(animation||'start'); player.dataset.position=position||game.players.length+game.dead.length; player.getId(); if(character) player.init(character); - game.players.push(player);game.arrangePlayers(); + game.players.push(player); + game.arrangePlayers(); return player; }, triggerEnter:player=>{ From 5948ab207ab1442bb97570d1cdbd2e2b24435ae8 Mon Sep 17 00:00:00 2001 From: Tipx-L <138244655+Tipx-L@users.noreply.github.com> Date: Thu, 24 Aug 2023 08:07:25 -0700 Subject: [PATCH 18/43] Optimize game.addPlayer. (cherry picked from commit e376bcdc6122914a2cc6f8c0880322dcea85b3b6) --- game/game.js | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/game/game.js b/game/game.js index f86c02497..532f00bde 100644 --- a/game/game.js +++ b/game/game.js @@ -38483,18 +38483,14 @@ }); } }, - addPlayer:function(position,character,character2){ - if(position<0||position>game.players.length+game.dead.length||position==undefined){ - position=Math.ceil(Math.random()*(game.players.length+game.dead.length)); - } - var players=game.players.concat(game.dead); + addPlayer:(position,character,character2)=>{ + if(position<0||position>game.players.length+game.dead.length||position==undefined) position=Math.ceil(Math.random()*(game.players.length+game.dead.length)); + const players=game.players.concat(game.dead); ui.arena.setNumber(players.length+1); - for(var i=0;i=position){ - players[i].dataset.position=parseInt(players[i].dataset.position)+1; - } - } - var player=ui.create.player(ui.arena).animate('start'); + players.forEach(value=>{ + if(parseInt(value.dataset.position)>=position) value.dataset.position=parseInt(value.dataset.position)+1; + }); + const player=ui.create.player(ui.arena).animate('start'); if(character) player.init(character,character2); game.players.push(player); player.dataset.position=position; From 38a8a11a02e5860710e855660fa2425d7cae07b0 Mon Sep 17 00:00:00 2001 From: Tipx-L <138244655+Tipx-L@users.noreply.github.com> Date: Thu, 24 Aug 2023 08:11:29 -0700 Subject: [PATCH 19/43] Optimize game.clearModeConfig. (cherry picked from commit 5e9d8d068b81e172da88032e6195bb5aad2d8a5f) --- game/game.js | 43 ++++++++++++++++++------------------------- 1 file changed, 18 insertions(+), 25 deletions(-) diff --git a/game/game.js b/game/game.js index 532f00bde..3ed5122e0 100644 --- a/game/game.js +++ b/game/game.js @@ -38454,34 +38454,27 @@ getExtensionConfig:function(extension,key){ return lib.config['extension_'+extension+'_'+key]; }, - clearModeConfig:function(mode){ + clearModeConfig:mode=>{ if(_status.reloading) return; - if(!lib.db){ - var config; - try{ - config=JSON.parse(localStorage.getItem(lib.configprefix+'config')); - if(!config||typeof config!='object') throw 'err' - } - catch(err){ - config={}; - } - for(var i in config){ - if(i.substr(i.indexOf('_mode_config')+13)==mode){ - delete config[i]; - } - } - localStorage.setItem(lib.configprefix+'config',JSON.stringify(config)); - localStorage.removeItem(lib.configprefix+mode); + if(lib.db){ + game.getDB('config',null,config=>Object.keys(config).forEach(value=>{ + if(value.substr(value.indexOf('_mode_config')+13)==mode) game.saveConfig(value); + })); + return; } - else{ - game.getDB('config',null,function(config){ - for(var i in config){ - if(i.substr(i.indexOf('_mode_config')+13)==mode){ - game.saveConfig(i); - } - } - }); + let config; + try{ + config=JSON.parse(localStorage.getItem(`${lib.configprefix}config`)); + if(!config||typeof config!='object') throw 'err'; } + catch(err){ + config={}; + } + Object.keys(config).forEach(value=>{ + if(value.substr(value.indexOf('_mode_config')+13)==mode) delete config[value]; + }); + localStorage.setItem(`${lib.configprefix}config`,JSON.stringify(config)); + localStorage.removeItem(`${lib.configprefix}${mode}`); }, addPlayer:(position,character,character2)=>{ if(position<0||position>game.players.length+game.dead.length||position==undefined) position=Math.ceil(Math.random()*(game.players.length+game.dead.length)); From 5cf7788ccba10b84f728ee8dbc5660b5bc922de4 Mon Sep 17 00:00:00 2001 From: Tipx-L <138244655+Tipx-L@users.noreply.github.com> Date: Thu, 24 Aug 2023 08:12:04 -0700 Subject: [PATCH 20/43] Optimize game.getExtensionConfig. (cherry picked from commit ea243be12f87d4be0c1fcc87d6d5d53b44637cc9) --- game/game.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/game/game.js b/game/game.js index 3ed5122e0..023b039a2 100644 --- a/game/game.js +++ b/game/game.js @@ -38451,9 +38451,7 @@ saveExtensionConfig:function(extension,key,value){ return game.saveConfig('extension_'+extension+'_'+key,value); }, - getExtensionConfig:function(extension,key){ - return lib.config['extension_'+extension+'_'+key]; - }, + getExtensionConfig:(extension,key)=>lib.config[`extension_${extension}_${key}`], clearModeConfig:mode=>{ if(_status.reloading) return; if(lib.db){ From 0a153bcf2461c43d421af777caeb43bd1ef91372 Mon Sep 17 00:00:00 2001 From: Tipx-L <138244655+Tipx-L@users.noreply.github.com> Date: Thu, 24 Aug 2023 08:15:15 -0700 Subject: [PATCH 21/43] Add game.saveExtensionConfigValue. (cherry picked from commit ee0c37fc6856458395d146996a89249cf7bee370) --- game/game.js | 1 + 1 file changed, 1 insertion(+) diff --git a/game/game.js b/game/game.js index 023b039a2..b16e60ed2 100644 --- a/game/game.js +++ b/game/game.js @@ -38451,6 +38451,7 @@ saveExtensionConfig:function(extension,key,value){ return game.saveConfig('extension_'+extension+'_'+key,value); }, + saveExtensionConfigValue:(extension,key)=>game.saveExtensionConfig(extension,key,game.getExtensionConfig(extension,key)), getExtensionConfig:(extension,key)=>lib.config[`extension_${extension}_${key}`], clearModeConfig:mode=>{ if(_status.reloading) return; From defc586b65bc218c7b124c2c77aa041279987dbc Mon Sep 17 00:00:00 2001 From: Tipx-L <138244655+Tipx-L@users.noreply.github.com> Date: Thu, 24 Aug 2023 08:17:24 -0700 Subject: [PATCH 22/43] Optimize game.saveExtensionConfig. (cherry picked from commit 8dedca3c072d5ea22d83717230658ff7eb4a92e4) --- game/game.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/game/game.js b/game/game.js index b16e60ed2..9976ee479 100644 --- a/game/game.js +++ b/game/game.js @@ -38448,9 +38448,7 @@ saveConfigValue:function(key){ game.saveConfig(key,lib.config[key]); }, - saveExtensionConfig:function(extension,key,value){ - return game.saveConfig('extension_'+extension+'_'+key,value); - }, + saveExtensionConfig:(extension,key,value)=>game.saveConfig(`extension_${extension}_${key}`,value), saveExtensionConfigValue:(extension,key)=>game.saveExtensionConfig(extension,key,game.getExtensionConfig(extension,key)), getExtensionConfig:(extension,key)=>lib.config[`extension_${extension}_${key}`], clearModeConfig:mode=>{ From 76422bd9eb776a8d31c9849b5d29ad0c6777c987 Mon Sep 17 00:00:00 2001 From: Tipx-L <138244655+Tipx-L@users.noreply.github.com> Date: Thu, 24 Aug 2023 08:18:28 -0700 Subject: [PATCH 23/43] Optimize game.saveConfigValue. (cherry picked from commit 55f527440f1f89139df738ea7e2539dd56a67d74) --- game/game.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/game/game.js b/game/game.js index 9976ee479..1ede6e959 100644 --- a/game/game.js +++ b/game/game.js @@ -38445,9 +38445,7 @@ } } }, - saveConfigValue:function(key){ - game.saveConfig(key,lib.config[key]); - }, + saveConfigValue:key=>game.saveConfig(key,lib.config[key]), saveExtensionConfig:(extension,key,value)=>game.saveConfig(`extension_${extension}_${key}`,value), saveExtensionConfigValue:(extension,key)=>game.saveExtensionConfig(extension,key,game.getExtensionConfig(extension,key)), getExtensionConfig:(extension,key)=>lib.config[`extension_${extension}_${key}`], From 4043bf1271d595089cc5c81aeb227278037dff0a Mon Sep 17 00:00:00 2001 From: Tipx-L <138244655+Tipx-L@users.noreply.github.com> Date: Thu, 24 Aug 2023 08:19:06 -0700 Subject: [PATCH 24/43] Optimize game.saveConfig. (cherry picked from commit 3b86a39de119067bd5c2342d2050e78fc45782a5) --- game/game.js | 73 ++++++++++++++++------------------------------------ 1 file changed, 22 insertions(+), 51 deletions(-) diff --git a/game/game.js b/game/game.js index 1ede6e959..092ac4731 100644 --- a/game/game.js +++ b/game/game.js @@ -38387,63 +38387,34 @@ } } }, - saveConfig:function(key,value,local,callback){ + saveConfig:(key,value,local,callback)=>{ if(_status.reloading) return; if(local){ - var localmode; - if(typeof local=='string'){ - localmode=local; - } - else{ - localmode=lib.config.mode; - } - if(!lib.config.mode_config[localmode]){ - lib.config.mode_config[localmode]={}; - } - if(value==undefined){ - delete lib.config.mode_config[localmode][key]; - } - else{ - lib.config.mode_config[localmode][key]=value; - } - key+='_mode_config_'+localmode; + const localmode=typeof local=='string'?local:lib.config.mode; + if(!lib.config.mode_config[localmode]) lib.config.mode_config[localmode]={}; + if(value==undefined) delete lib.config.mode_config[localmode][key]; + else lib.config.mode_config[localmode][key]=value; + key+=`_mode_config_${localmode}`; } - else{ - if(value==undefined){ - delete lib.config[key]; - } - else{ - lib.config[key]=value; - } + else if(value==undefined) delete lib.config[key]; + else lib.config[key]=value; + if(lib.db){ + if(value==undefined) game.deleteDB('config',key,callback); + else game.putDB('config',key,value,callback); + return; } - if(!lib.db){ - var config; - try{ - config=JSON.parse(localStorage.getItem(lib.configprefix+'config')); - if(!config||typeof config!='object') throw 'err' - } - catch(err){ - config={}; - } - if(value===undefined){ - delete config[key]; - } - else{ - config[key]=value; - } - localStorage.setItem(lib.configprefix+'config',JSON.stringify(config)); - if(callback){ - callback(); - } + let config; + try{ + config=JSON.parse(localStorage.getItem(`${lib.configprefix}config`)); + if(!config||typeof config!='object') throw 'err'; } - else{ - if(value==undefined){ - game.deleteDB('config',key,callback); - } - else{ - game.putDB('config',key,value,callback); - } + catch(err){ + config={}; } + if(value===undefined) delete config[key]; + else config[key]=value; + localStorage.setItem(`${lib.configprefix}config`,JSON.stringify(config)); + if(callback) callback(); }, saveConfigValue:key=>game.saveConfig(key,lib.config[key]), saveExtensionConfig:(extension,key,value)=>game.saveConfig(`extension_${extension}_${key}`,value), From 3d4f04860b2ba6b517733f228b79ce164ed1ffa1 Mon Sep 17 00:00:00 2001 From: Tipx-L <138244655+Tipx-L@users.noreply.github.com> Date: Thu, 24 Aug 2023 08:19:48 -0700 Subject: [PATCH 25/43] Optimize game.showExtensionChangeLog. (cherry picked from commit c5eeb67e390a232b1a577d2c04a72f4119592754) --- game/game.js | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/game/game.js b/game/game.js index 092ac4731..5ada22873 100644 --- a/game/game.js +++ b/game/game.js @@ -38376,16 +38376,14 @@ lib.init.onfree(); } }, - showExtensionChangeLog:function(str,extname){ + showExtensionChangeLog:(str,extname)=>{ extname=extname||_status.extension; - var cfg='extension_'+extname+'_changelog'; - if(lib.extensionPack[extname]&&lib.extensionPack[extname].version!=lib.config[cfg]){ - game.saveConfig(cfg,lib.extensionPack[extname].version); - if(!_status.extensionChangeLog){ - _status.extensionChangeLog={}; - _status.extensionChangeLog[extname]=str; - } - } + const cfg=`extension_${extname}_changelog`; + if(!lib.extensionPack[extname]||lib.extensionPack[extname].version==lib.config[cfg]) return; + game.saveConfig(cfg,lib.extensionPack[extname].version); + if(_status.extensionChangeLog) return; + _status.extensionChangeLog={}; + _status.extensionChangeLog[extname]=str; }, saveConfig:(key,value,local,callback)=>{ if(_status.reloading) return; From 61cedb172bde1cd906005edf4675ddb596978e7c Mon Sep 17 00:00:00 2001 From: Tipx-L <138244655+Tipx-L@users.noreply.github.com> Date: Thu, 24 Aug 2023 08:20:34 -0700 Subject: [PATCH 26/43] Optimize game.showChangeLog. (cherry picked from commit 62fdfe7fa2c58da1c9afcd82bf5b2f4931952f2b) --- game/game.js | 139 ++++++++++++++++++++------------------------------- 1 file changed, 55 insertions(+), 84 deletions(-) diff --git a/game/game.js b/game/game.js index 5ada22873..33b750fdd 100644 --- a/game/game.js +++ b/game/game.js @@ -38286,95 +38286,66 @@ } } }, - showChangeLog:function(){ - if(lib.version!=lib.config.version||_status.extensionChangeLog){ - var ul=document.createElement('ul'); - ul.style.textAlign='left'; - var caption; - var players=null,cards=null; - if(lib.version!=lib.config.version){ - for(var i=0;i{ + if(lib.version==lib.config.version&&!_status.extensionChangeLog) return; + const ul=document.createElement('ul'); + ul.style.textAlign='left'; + const caption=lib.version==lib.config.version?'扩展更新':`${lib.version}更新内容`; + let players=null,cards=null; + if(lib.version!=lib.config.version) lib.changeLog.forEach(value=>{ + if(value.indexOf('players://')==0) try{ + players=JSON.parse(value.slice(10)).filter(value=>lib.character[value]); + } + catch(e){ + players=null; + } + else if(value.indexOf('cards://')==0) try{ + cards=JSON.parse(value.slice(8)).filter(value=>lib.card[value]); + } + catch(e){ + cards=null; } else{ - caption='扩展更新'; - } - game.saveConfig('version',lib.version); - for(var i in _status.extensionChangeLog){ - var li=document.createElement('li'); - li.innerHTML=i+':'+_status.extensionChangeLog[i]; + const li=document.createElement('li'); + li.innerHTML=value; ul.appendChild(li); } - var dialog=ui.create.dialog(caption,'hidden'); - var lic=ui.create.div(dialog.content); - lic.style.display='block'; - ul.style.display='inline-block'; - ul.style.marginLeft='-40px'; - lic.appendChild(ul); - if(players){ - for(var i=0;i