Skip to content

Commit

Permalink
only show start options if available
Browse files Browse the repository at this point in the history
  • Loading branch information
myin142 committed Jun 2, 2023
1 parent 44738d9 commit 6af74eb
Showing 1 changed file with 19 additions and 16 deletions.
35 changes: 19 additions & 16 deletions src/nethack-wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,31 +163,34 @@ export class NetHackWrapper implements NetHackJS {

private async openStartScreen() {
while (!this.isGameRunning()) {
const id = await this.openCustomMenu("Welcome to NetHack", [
"Start Game",
"Load from backup",
"Leaderboard",
]);

switch (id) {
case 0:
this.startGame();
break;
case 1:
const files = listBackupFiles();
const files = listBackupFiles();
const records = loadRecords();

const actions = [async () => this.startGame()];
const startMenu = ["Start Game"];

if (files.length > 0) {
startMenu.push("Load from backup");
actions.push(async () => {
const backupId = await this.openCustomMenu("Select backup file", files);
if (backupId !== -1) {
this.backupFile = files[backupId];
this.startGame();
}
break;
case 2:
const records = loadRecords();
});
}

if (records.length) {
startMenu.push("Leaderboard");
actions.push(async () => {
this.ui.openDialog(-1, records);
await this.waitInput(true);
this.ui.closeDialog(-1);
break;
});
}

const id = await this.openCustomMenu("Welcome to NetHack", startMenu);
await actions[id]();
}

this.ui.closeDialog(-1);
Expand Down

0 comments on commit 6af74eb

Please sign in to comment.