adds daily run to offline mode

This commit is contained in:
unknown 2024-05-12 22:18:10 -03:00
parent e61c63f6c8
commit ae0adfd367
2 changed files with 15 additions and 6 deletions

View File

@ -13,14 +13,15 @@ export interface DailyRunConfig {
}
export function fetchDailyRunSeed(): Promise<string> {
return new Promise<string>(resolve => {
return new Promise<string>((resolve, reject) => {
Utils.apiFetch('daily/seed').then(response => {
if (!response.ok) {
resolve(null);
return;
}
return response.text();
}).then(seed => resolve(seed));
}).then(seed => resolve(seed))
.catch(err => reject(err));
});
}

View File

@ -289,7 +289,7 @@ export class TitlePhase extends Phase {
}
this.scene.sessionSlotId = slotId;
fetchDailyRunSeed().then(seed => {
const generateDaily = (seed: string) => {
this.scene.gameMode = gameModes[GameModes.DAILY];
this.scene.setSeed(seed);
@ -332,9 +332,17 @@ export class TitlePhase extends Phase {
this.scene.sessionPlayTime = 0;
this.end();
});
}).catch(err => {
console.error("Failed to load daily run:\n", err);
});
};
if (!Utils.isLocal){
fetchDailyRunSeed().then(seed => {
generateDaily(seed);
}).catch(err => {
console.error("Failed to load daily run:\n", err);
});
} else {
generateDaily(btoa(new Date().toISOString().substring(0, 10)))
}
});
}