fixed infinite loop (#3887)

Co-authored-by: frutescens <info@laptop>
This commit is contained in:
Mumble 2024-08-28 22:44:26 -07:00 committed by GitHub
parent 35f522fd99
commit 781e25848d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 3 additions and 3 deletions

View File

@ -635,13 +635,13 @@ export class GameData {
async saveRunHistory(scene: BattleScene, runEntry : SessionSaveData, isVictory: boolean): Promise<boolean> { async saveRunHistory(scene: BattleScene, runEntry : SessionSaveData, isVictory: boolean): Promise<boolean> {
const runHistoryData = await this.getRunHistoryData(scene); const runHistoryData = await this.getRunHistoryData(scene);
// runHistoryData should always return run history or {} empty object // runHistoryData should always return run history or {} empty object
const timestamps = Object.keys(runHistoryData); let timestamps = Object.keys(runHistoryData).map(Number);
const timestampsNo = timestamps.map(Number);
// Arbitrary limit of 25 entries per user --> Can increase or decrease // Arbitrary limit of 25 entries per user --> Can increase or decrease
while (timestamps.length >= RUN_HISTORY_LIMIT ) { while (timestamps.length >= RUN_HISTORY_LIMIT ) {
const oldestTimestamp = Math.min.apply(Math, timestampsNo); const oldestTimestamp = (Math.min.apply(Math, timestamps)).toString();
delete runHistoryData[oldestTimestamp]; delete runHistoryData[oldestTimestamp];
timestamps = Object.keys(runHistoryData).map(Number);
} }
const timestamp = (runEntry.timestamp).toString(); const timestamp = (runEntry.timestamp).toString();