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] 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;