Support number keys for campaign save slots
This commit is contained in:
@@ -10755,6 +10755,7 @@ export class CampScene extends Phaser.Scene {
|
|||||||
this.selectedVisitId = this.availableCampVisits()[0]?.id ?? campVisits[0].id;
|
this.selectedVisitId = this.availableCampVisits()[0]?.id ?? campVisits[0].id;
|
||||||
soundDirector.playMusic('militia-theme');
|
soundDirector.playMusic('militia-theme');
|
||||||
this.input.keyboard?.on('keydown-ESC', () => this.handleEscapeKey());
|
this.input.keyboard?.on('keydown-ESC', () => this.handleEscapeKey());
|
||||||
|
this.input.keyboard?.on('keydown', (event: KeyboardEvent) => this.handleSaveSlotKey(event));
|
||||||
loadBattleUiIcons(this, () => this.ensureCampAssets(() => this.drawCampScene()));
|
loadBattleUiIcons(this, () => this.ensureCampAssets(() => this.drawCampScene()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -11980,6 +11981,20 @@ export class CampScene extends Phaser.Scene {
|
|||||||
this.render();
|
this.render();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private handleSaveSlotKey(event: KeyboardEvent) {
|
||||||
|
if (this.saveSlotObjects.length === 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const slot = Number(event.key);
|
||||||
|
if (!Number.isInteger(slot) || slot < 1 || slot > campaignSaveSlotCount) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
event.preventDefault();
|
||||||
|
this.saveCampToSlot(slot);
|
||||||
|
}
|
||||||
|
|
||||||
private hideCampSaveSlotPanel() {
|
private hideCampSaveSlotPanel() {
|
||||||
this.saveSlotObjects.forEach((object) => object.destroy());
|
this.saveSlotObjects.forEach((object) => object.destroy());
|
||||||
this.saveSlotObjects = [];
|
this.saveSlotObjects = [];
|
||||||
|
|||||||
@@ -64,6 +64,7 @@ export class TitleScene extends Phaser.Scene {
|
|||||||
this.input.once('pointerdown', unlockAudio);
|
this.input.once('pointerdown', unlockAudio);
|
||||||
this.input.keyboard?.once('keydown', unlockAudio);
|
this.input.keyboard?.once('keydown', unlockAudio);
|
||||||
this.input.keyboard?.once('keydown-ENTER', () => this.activateDefaultMenuAction());
|
this.input.keyboard?.once('keydown-ENTER', () => this.activateDefaultMenuAction());
|
||||||
|
this.input.keyboard?.on('keydown', (event: KeyboardEvent) => this.handleSaveSlotKey(event));
|
||||||
this.input.keyboard?.on('keydown-ESC', () => this.handleEscapeKey());
|
this.input.keyboard?.on('keydown-ESC', () => this.handleEscapeKey());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -525,14 +526,36 @@ export class TitleScene extends Phaser.Scene {
|
|||||||
background.setStrokeStyle(1, palette.gold, 0.42);
|
background.setStrokeStyle(1, palette.gold, 0.42);
|
||||||
});
|
});
|
||||||
background.on('pointerdown', () => {
|
background.on('pointerdown', () => {
|
||||||
this.closeSaveSlotPanel();
|
this.activateSaveSlot(slot.slot);
|
||||||
this.continueGame(slot.slot);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return row;
|
return row;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private handleSaveSlotKey(event: KeyboardEvent) {
|
||||||
|
if (!this.saveSlotPanel) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const slot = Number(event.key);
|
||||||
|
if (!Number.isInteger(slot)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
event.preventDefault();
|
||||||
|
this.activateSaveSlot(slot);
|
||||||
|
}
|
||||||
|
|
||||||
|
private activateSaveSlot(slot: number) {
|
||||||
|
if (!listCampaignSaveSlots().some((summary) => summary.slot === slot && summary.exists)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.closeSaveSlotPanel();
|
||||||
|
this.continueGame(slot);
|
||||||
|
}
|
||||||
|
|
||||||
private closeSaveSlotPanel() {
|
private closeSaveSlotPanel() {
|
||||||
this.saveSlotPanel?.destroy();
|
this.saveSlotPanel?.destroy();
|
||||||
this.saveSlotPanel = undefined;
|
this.saveSlotPanel = undefined;
|
||||||
|
|||||||
Reference in New Issue
Block a user