mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2025-10-19 19:45:51 +02:00
* 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
71 lines
1.6 KiB
TypeScript
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 {}
|
|
}
|