Refactor and documentation

This commit is contained in:
Adrian 2024-08-19 14:19:25 -04:00
parent e7664b2d25
commit 6ea0f083a2

View File

@ -33,7 +33,7 @@ export default class AbstractSettingsUiHandler extends MessageUiHandler {
private cursorObj: Phaser.GameObjects.NineSlice | null; private cursorObj: Phaser.GameObjects.NineSlice | null;
private reloadSettings: Array<integer | null>; private reloadSettings: Array<number | null>;
private reloadRequired: boolean; private reloadRequired: boolean;
protected rowsToDisplay: number; protected rowsToDisplay: number;
@ -231,37 +231,44 @@ export default class AbstractSettingsUiHandler extends MessageUiHandler {
let success = false; let success = false;
const progressLosing = () => { /**
* Checks if the game is in a state where progress may be lost due to changes options with reloadRequired while at battle.
* @returns `false` if the warning process is triggered, `true` otherwise.
*/
const progressLosing = (): boolean => {
if (this.reloadRequired && this.scene.currentBattle && this.scene.currentBattle.turn > 1) { if (this.reloadRequired && this.scene.currentBattle && this.scene.currentBattle.turn > 1) {
this.showText(i18next.t("menuUiHandler:losingProgressionWarning"), null, () => { this.showText(i18next.t("menuUiHandler:losingProgressionWarning"), null, () => {
ui.setOverlayMode(Mode.CONFIRM, () => { ui.setOverlayMode(Mode.CONFIRM, () => {
NavigationManager.getInstance().reset(); NavigationManager.getInstance().reset();
// revert confirm mode.
this.scene.ui.revertMode(); this.scene.ui.revertMode();
// revert settings mode.
this.scene.ui.revertMode(); this.scene.ui.revertMode();
}, () => { }, () => {
// if user don't want accept losing progress for reload, revert options with reloadRequired for no reload.
this.reloadSettings.forEach((s,i) => { this.reloadSettings.forEach((s,i) => {
if (s !== null && s !== this.optionCursors[i]) { if (s !== null && s !== this.optionCursors[i]) {
this.setOptionCursor(i,s,true); this.setOptionCursor(i,s,true);
} }
}); });
this.scene.ui.revertMode(); this.scene.ui.revertMode();
ui.showText("", 0); this.showText("", 0);
}, false, 0,0); }, false, 0,0);
}); });
return false; return false;
} }
return true; return true;
}; };
if (button === Button.CANCEL) { if (button === Button.CANCEL) {
success = true;
if (progressLosing()) { if (progressLosing()) {
NavigationManager.getInstance().reset(); NavigationManager.getInstance().reset();
// Reverts UI to its previous state on cancel.
this.scene.ui.revertMode(); this.scene.ui.revertMode();
} }
success = true;
} else { } else {
const cursor = this.cursor + this.scrollCursor; const cursor = this.cursor + this.scrollCursor;
switch (button) { switch (button) {
@ -395,7 +402,6 @@ export default class AbstractSettingsUiHandler extends MessageUiHandler {
if (save) { if (save) {
this.scene.gameData.saveSetting(setting.key, cursor); this.scene.gameData.saveSetting(setting.key, cursor);
this.reloadRequired = this.reloadSettings.some((s,i)=> this.reloadRequired = this.reloadSettings.some((s,i)=>
s !== null && s !== this.optionCursors[i] s !== null && s !== this.optionCursors[i]
); );