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