move ??= outside for loop
All checks were successful
Build / build (20) (pull_request) Successful in 34s
Build / build (18) (pull_request) Successful in 55s
Build / build (22) (pull_request) Successful in 1m13s

This commit is contained in:
AMelonInsideLemon 2025-02-03 20:59:58 +01:00
parent 3098d3290f
commit 8492720fd0

View File

@ -62,8 +62,8 @@ export const uploadStats = async (playerStats: TStatsDatabaseDocument, payload:
} }
if (SCAN) { if (SCAN) {
for (const [key, scans] of Object.entries(SCAN)) {
playerStats.Scans ??= []; playerStats.Scans ??= [];
for (const [key, scans] of Object.entries(SCAN)) {
const scan = playerStats.Scans.find(element => element.type === key); const scan = playerStats.Scans.find(element => element.type === key);
if (scan) { if (scan) {
scan.scans ??= 0; scan.scans ??= 0;
@ -75,8 +75,8 @@ export const uploadStats = async (playerStats: TStatsDatabaseDocument, payload:
} }
if (USE_ABILITY) { if (USE_ABILITY) {
for (const [key, used] of Object.entries(USE_ABILITY)) {
playerStats.Abilities ??= []; playerStats.Abilities ??= [];
for (const [key, used] of Object.entries(USE_ABILITY)) {
const ability = playerStats.Abilities.find(element => element.type === key); const ability = playerStats.Abilities.find(element => element.type === key);
if (ability) { if (ability) {
ability.used ??= 0; ability.used ??= 0;
@ -88,8 +88,8 @@ export const uploadStats = async (playerStats: TStatsDatabaseDocument, payload:
} }
if (FIRE_WEAPON) { if (FIRE_WEAPON) {
for (const [key, fired] of Object.entries(FIRE_WEAPON)) {
playerStats.Weapons ??= []; playerStats.Weapons ??= [];
for (const [key, fired] of Object.entries(FIRE_WEAPON)) {
const weapon = playerStats.Weapons.find(element => element.type === key); const weapon = playerStats.Weapons.find(element => element.type === key);
if (weapon) { if (weapon) {
weapon.fired ??= 0; weapon.fired ??= 0;
@ -101,8 +101,8 @@ export const uploadStats = async (playerStats: TStatsDatabaseDocument, payload:
} }
if (HIT_ENTITY_ITEM) { if (HIT_ENTITY_ITEM) {
for (const [key, hits] of Object.entries(HIT_ENTITY_ITEM)) {
playerStats.Weapons ??= []; playerStats.Weapons ??= [];
for (const [key, hits] of Object.entries(HIT_ENTITY_ITEM)) {
const weapon = playerStats.Weapons.find(element => element.type === key); const weapon = playerStats.Weapons.find(element => element.type === key);
if (weapon) { if (weapon) {
weapon.hits ??= 0; weapon.hits ??= 0;
@ -114,8 +114,8 @@ export const uploadStats = async (playerStats: TStatsDatabaseDocument, payload:
} }
if (HEADSHOT_ITEM) { if (HEADSHOT_ITEM) {
for (const [key, headshots] of Object.entries(HEADSHOT_ITEM)) {
playerStats.Weapons ??= []; playerStats.Weapons ??= [];
for (const [key, headshots] of Object.entries(HEADSHOT_ITEM)) {
const weapon = playerStats.Weapons.find(element => element.type === key); const weapon = playerStats.Weapons.find(element => element.type === key);
if (weapon) { if (weapon) {
weapon.headshots ??= 0; weapon.headshots ??= 0;
@ -127,8 +127,8 @@ export const uploadStats = async (playerStats: TStatsDatabaseDocument, payload:
} }
if (KILL_ENEMY_ITEM) { if (KILL_ENEMY_ITEM) {
for (const [key, kills] of Object.entries(KILL_ENEMY_ITEM)) {
playerStats.Weapons ??= []; playerStats.Weapons ??= [];
for (const [key, kills] of Object.entries(KILL_ENEMY_ITEM)) {
const weapon = playerStats.Weapons.find(element => element.type === key); const weapon = playerStats.Weapons.find(element => element.type === key);
if (weapon) { if (weapon) {
weapon.kills ??= 0; weapon.kills ??= 0;
@ -140,8 +140,8 @@ export const uploadStats = async (playerStats: TStatsDatabaseDocument, payload:
} }
if (KILL_ENEMY) { if (KILL_ENEMY) {
for (const [key, kills] of Object.entries(KILL_ENEMY)) {
playerStats.Enemies ??= []; playerStats.Enemies ??= [];
for (const [key, kills] of Object.entries(KILL_ENEMY)) {
const enemy = playerStats.Enemies.find(element => element.type === key); const enemy = playerStats.Enemies.find(element => element.type === key);
if (enemy) { if (enemy) {
enemy.kills ??= 0; enemy.kills ??= 0;
@ -153,8 +153,8 @@ export const uploadStats = async (playerStats: TStatsDatabaseDocument, payload:
} }
if (EXECUTE_ENEMY) { if (EXECUTE_ENEMY) {
for (const [key, executions] of Object.entries(EXECUTE_ENEMY)) {
playerStats.Enemies ??= []; playerStats.Enemies ??= [];
for (const [key, executions] of Object.entries(EXECUTE_ENEMY)) {
const enemy = playerStats.Enemies.find(element => element.type === key); const enemy = playerStats.Enemies.find(element => element.type === key);
if (enemy) { if (enemy) {
enemy.executions ??= 0; enemy.executions ??= 0;
@ -166,8 +166,8 @@ export const uploadStats = async (playerStats: TStatsDatabaseDocument, payload:
} }
if (HEADSHOT) { if (HEADSHOT) {
for (const [key, headshots] of Object.entries(HEADSHOT)) {
playerStats.Enemies ??= []; playerStats.Enemies ??= [];
for (const [key, headshots] of Object.entries(HEADSHOT)) {
const enemy = playerStats.Enemies.find(element => element.type === key); const enemy = playerStats.Enemies.find(element => element.type === key);
if (enemy) { if (enemy) {
enemy.headshots ??= 0; enemy.headshots ??= 0;
@ -179,10 +179,10 @@ export const uploadStats = async (playerStats: TStatsDatabaseDocument, payload:
} }
if (DIE) { if (DIE) {
playerStats.Enemies ??= [];
for (const [key, deaths] of Object.entries(DIE)) { for (const [key, deaths] of Object.entries(DIE)) {
playerStats.Deaths ??= 0; playerStats.Deaths ??= 0;
playerStats.Deaths += deaths; playerStats.Deaths += deaths;
playerStats.Enemies ??= [];
const enemy = playerStats.Enemies.find(element => element.type === key); const enemy = playerStats.Enemies.find(element => element.type === key);
if (enemy) { if (enemy) {
enemy.deaths ??= 0; enemy.deaths ??= 0;
@ -221,8 +221,8 @@ export const uploadStats = async (playerStats: TStatsDatabaseDocument, payload:
const { EQUIP_WEAPON, CURRENT_MISSION_TIME, CIPHER_TIME } = payload.timers; const { EQUIP_WEAPON, CURRENT_MISSION_TIME, CIPHER_TIME } = payload.timers;
if (EQUIP_WEAPON) { if (EQUIP_WEAPON) {
for (const [key, equipTime] of Object.entries(EQUIP_WEAPON)) {
playerStats.Weapons ??= []; playerStats.Weapons ??= [];
for (const [key, equipTime] of Object.entries(EQUIP_WEAPON)) {
const weapon = playerStats.Weapons.find(element => element.type === key); const weapon = playerStats.Weapons.find(element => element.type === key);
if (weapon) { if (weapon) {
weapon.equipTime ??= 0; weapon.equipTime ??= 0;
@ -248,8 +248,8 @@ export const uploadStats = async (playerStats: TStatsDatabaseDocument, payload:
const { WEAPON_XP, MISSION_SCORE } = payload.max; const { WEAPON_XP, MISSION_SCORE } = payload.max;
if (WEAPON_XP) { if (WEAPON_XP) {
for (const [key, xp] of Object.entries(WEAPON_XP)) {
playerStats.Weapons ??= []; playerStats.Weapons ??= [];
for (const [key, xp] of Object.entries(WEAPON_XP)) {
const weapon = playerStats.Weapons.find(element => element.type === key); const weapon = playerStats.Weapons.find(element => element.type === key);
if (weapon) { if (weapon) {
weapon.xp = xp; weapon.xp = xp;
@ -260,8 +260,8 @@ export const uploadStats = async (playerStats: TStatsDatabaseDocument, payload:
} }
if (MISSION_SCORE) { if (MISSION_SCORE) {
for (const [key, highScore] of Object.entries(MISSION_SCORE)) {
playerStats.Missions ??= []; playerStats.Missions ??= [];
for (const [key, highScore] of Object.entries(MISSION_SCORE)) {
const mission = playerStats.Missions.find(element => element.type === key); const mission = playerStats.Missions.find(element => element.type === key);
if (mission) { if (mission) {
mission.highScore = highScore; mission.highScore = highScore;