pokerogue/src/ui/ui-handler.ts
Sirz Benjie 5854b21da0
[Refactor] Remove circular imports part 1 (#5663)
* Extract Mode enum out of UI and into its own file

Reduces circular imports from 909 to 773

* Move around utility files

Reduces cyclical dependencies from 773 to 765

* Remove starterColors and bypassLogin from battle-scene

Reduces cyclical dependencies from 765 to 623

* Fix test runner error

* Update import for bypassLogin in test

* Update mocks for utils in tests

* Fix broken tests

* Update selectWithTera override

* Update path for utils in ab-attr.ts

* Update path for utils in ability-class.ts

* Fix utils import path in healer.test.ts
2025-04-19 11:57:03 +00:00

71 lines
1.6 KiB
TypeScript

import { globalScene } from "#app/global-scene";
import type { TextStyle } from "./text";
import { getTextColor } from "./text";
import type { UiMode } from "#enums/ui-mode";
import type { Button } from "#enums/buttons";
/**
* A basic abstract class to act as a holder and processor for UI elements.
*/
export default abstract class UiHandler {
protected mode: number | null;
protected cursor = 0;
public active = false;
/**
* @param mode The mode of the UI element. These should be unique.
*/
constructor(mode: UiMode | null = null) {
this.mode = mode;
}
abstract setup(): void;
show(_args: any[]): boolean {
this.active = true;
return true;
}
abstract processInput(button: Button): boolean;
getUi() {
return globalScene.ui;
}
getTextColor(style: TextStyle, shadow = false): string {
return getTextColor(style, shadow, globalScene.uiTheme);
}
getCursor(): number {
return this.cursor;
}
setCursor(cursor: number): boolean {
const changed = this.cursor !== cursor;
if (changed) {
this.cursor = cursor;
}
return changed;
}
/**
* Changes the style of the mouse cursor.
* @see {@link https://developer.mozilla.org/en-US/docs/Web/CSS/cursor}
* @param cursorStyle cursor style to apply
*/
protected setMouseCursorStyle(cursorStyle: "pointer" | "default") {
globalScene.input.manager.canvas.style.cursor = cursorStyle;
}
clear() {
this.active = false;
}
/**
* To be implemented by individual handlers when necessary to free memory
* Called when {@linkcode BattleScene} is reset
*/
destroy(): void {}
}