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