mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-12-18 12:15:44 +01:00
Fix Steam version trying to record every achievement player has every second
This commit is contained in:
parent
62ac7f7d17
commit
521889b027
@ -2,19 +2,25 @@
|
||||
const greenworks = require("./greenworks");
|
||||
const log = require("electron-log");
|
||||
|
||||
function enableAchievementsInterval(window) {
|
||||
async function enableAchievementsInterval(window) {
|
||||
// If the Steam API could not be initialized on game start, we'll abort this.
|
||||
if (global.greenworksError) return;
|
||||
|
||||
// This is backward but the game fills in an array called `document.achievements` and we retrieve it from
|
||||
// here. Hey if it works it works.
|
||||
const steamAchievements = greenworks.getAchievementNames();
|
||||
log.info(`All Steam achievements ${JSON.stringify(steamAchievements)}`);
|
||||
const playerAchieved = (await Promise.all(steamAchievements.map(name => new Promise((resolve, reject) => { greenworks.getAchievement(name, (playerHas) => resolve(playerHas ? name : ""), reject); })))).filter(name => !!name);
|
||||
log.info(`Player has Steam achievements ${JSON.stringify(playerAchieved)}`);
|
||||
const intervalID = setInterval(async () => {
|
||||
try {
|
||||
const playerAchievements = await window.webContents.executeJavaScript("document.achievements");
|
||||
for (const ach of playerAchievements) {
|
||||
if (!steamAchievements.includes(ach)) continue;
|
||||
if (!steamAchievements.includes(ach)) continue; // Don't try activating achievements that don't exist Steam-side
|
||||
if (playerAchieved.includes(ach)) continue; // Don't spam achievements that have already been recorded
|
||||
log.info(`Granting Steam achievement ${ach}`);
|
||||
greenworks.activateAchievement(ach, () => undefined);
|
||||
playerAchieved.push(ach);
|
||||
}
|
||||
} catch (error) {
|
||||
log.error(error);
|
||||
|
Loading…
Reference in New Issue
Block a user