0
0
mirror of https://github.com/sp-tarkov/server.git synced 2025-02-12 15:50:42 -05:00

Update Bot Generation to use ProgressWriter

- The ProgressWriter class now resets it's cursor position to the beginning of the current line so that any log inbetween increments overwrites the current progress bar.
- Bot generation will now display a progress bar.
This commit is contained in:
Refringe 2024-12-23 16:34:06 -05:00
parent a9d76021bc
commit bc1d0c5fb4
Signed by: Refringe
SSH Key Fingerprint: SHA256:t865XsQpfTeqPRBMN2G6+N8wlDjkgUCZF3WGW6O9N/k
2 changed files with 7 additions and 2 deletions

View File

@ -25,6 +25,7 @@ import { DatabaseService } from "@spt/services/DatabaseService";
import { LocalisationService } from "@spt/services/LocalisationService";
import { MatchBotDetailsCacheService } from "@spt/services/MatchBotDetailsCacheService";
import { SeasonalEventService } from "@spt/services/SeasonalEventService";
import { ProgressWriter } from "@spt/utils/ProgressWriter";
import { RandomUtil } from "@spt/utils/RandomUtil";
import { ICloner } from "@spt/utils/cloners/ICloner";
import { inject, injectable } from "tsyringe";
@ -306,15 +307,17 @@ export class BotController {
}
// We're below desired count, add bots to cache
const progressWriter = new ProgressWriter(botGenerationDetails.botCountToGenerate);
for (let i = 0; i < botGenerationDetails.botCountToGenerate; i++) {
const detailsClone = this.cloner.clone(botGenerationDetails);
botPromises.push(this.generateSingleBotAndStoreInCache(detailsClone, sessionId, cacheKey));
progressWriter.increment();
}
return Promise.all(botPromises).then(() => {
return await Promise.all(botPromises).then(() => {
this.logger.debug(
`Generated ${botGenerationDetails.botCountToGenerate} ${botGenerationDetails.role} (${
botGenerationDetails.eventRole ?? ""
botGenerationDetails.eventRole ?? botGenerationDetails.role ?? ""
}) ${botGenerationDetails.botDifficulty} bots`,
);
});

View File

@ -48,5 +48,7 @@ export class ProgressWriter {
readline.cursorTo(process.stdout, 0, null);
this.done = true;
}
readline.cursorTo(process.stdout, 0, null);
}
}