mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2025-02-12 11:15:53 +00:00
* Add destroy function to ui handlers * Implement destroy() for StarterSelectUiHandler * Update battlescene to free memory when resetting * Document destroy for starter select --------- Co-authored-by: damocleas <damocleas25@gmail.com>
This commit is contained in:
parent
e2c6bec418
commit
39b4d74e95
@ -1191,6 +1191,9 @@ export default class BattleScene extends SceneBase {
|
|||||||
onComplete: () => {
|
onComplete: () => {
|
||||||
this.clearPhaseQueue();
|
this.clearPhaseQueue();
|
||||||
|
|
||||||
|
this.ui.freeUIData();
|
||||||
|
this.uiContainer.remove(this.ui, true);
|
||||||
|
this.uiContainer.destroy();
|
||||||
this.children.removeAll(true);
|
this.children.removeAll(true);
|
||||||
this.game.domContainer.innerHTML = "";
|
this.game.domContainer.innerHTML = "";
|
||||||
this.launchBattle();
|
this.launchBattle();
|
||||||
|
@ -89,6 +89,13 @@ export class NavigationManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes menus from the manager in preparation for reset
|
||||||
|
*/
|
||||||
|
public clearNavigationMenus() {
|
||||||
|
this.navigationMenus.length = 0;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class NavigationMenu extends Phaser.GameObjects.Container {
|
export default class NavigationMenu extends Phaser.GameObjects.Container {
|
||||||
|
@ -2698,6 +2698,11 @@ export default class StarterSelectUiHandler extends MessageUiHandler {
|
|||||||
this.updateScroll();
|
this.updateScroll();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
override destroy(): void {
|
||||||
|
// Without this the reference gets hung up and no startercontainers get GCd
|
||||||
|
this.starterContainers = [];
|
||||||
|
}
|
||||||
|
|
||||||
updateScroll = () => {
|
updateScroll = () => {
|
||||||
const maxColumns = 9;
|
const maxColumns = 9;
|
||||||
const maxRows = 9;
|
const maxRows = 9;
|
||||||
|
@ -62,4 +62,9 @@ export default abstract class UiHandler {
|
|||||||
clear() {
|
clear() {
|
||||||
this.active = false;
|
this.active = false;
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* To be implemented by individual handlers when necessary to free memory
|
||||||
|
* Called when {@linkcode BattleScene} is reset
|
||||||
|
*/
|
||||||
|
destroy(): void {}
|
||||||
}
|
}
|
||||||
|
11
src/ui/ui.ts
11
src/ui/ui.ts
@ -53,6 +53,7 @@ import TestDialogueUiHandler from "#app/ui/test-dialogue-ui-handler";
|
|||||||
import AutoCompleteUiHandler from "./autocomplete-ui-handler";
|
import AutoCompleteUiHandler from "./autocomplete-ui-handler";
|
||||||
import { Device } from "#enums/devices";
|
import { Device } from "#enums/devices";
|
||||||
import MysteryEncounterUiHandler from "./mystery-encounter-ui-handler";
|
import MysteryEncounterUiHandler from "./mystery-encounter-ui-handler";
|
||||||
|
import { NavigationManager } from "./settings/navigationMenu";
|
||||||
|
|
||||||
export enum Mode {
|
export enum Mode {
|
||||||
MESSAGE,
|
MESSAGE,
|
||||||
@ -614,4 +615,14 @@ export default class UI extends Phaser.GameObjects.Container {
|
|||||||
return globalScene.inputMethod;
|
return globalScene.inputMethod;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Attempts to free memory held by UI handlers
|
||||||
|
* and clears menus from {@linkcode NavigationManager} to prepare for reset
|
||||||
|
*/
|
||||||
|
public freeUIData(): void {
|
||||||
|
this.handlers.forEach(h => h.destroy());
|
||||||
|
this.handlers = [];
|
||||||
|
NavigationManager.getInstance().clearNavigationMenus();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user