From e18a4f3d1609bdde738ff74c1e8ed8e6a398d509 Mon Sep 17 00:00:00 2001 From: Greenlamp Date: Sat, 4 May 2024 01:34:59 +0200 Subject: [PATCH] remove Plugins things as it's too uncertain how it works on prod --- src/battle-scene.ts | 6 +++++- src/inputs-controller.ts | 30 +++++++++++++----------------- src/main.ts | 10 ---------- src/ui-inputs.ts | 16 ++++++++-------- 4 files changed, 26 insertions(+), 36 deletions(-) diff --git a/src/battle-scene.ts b/src/battle-scene.ts index 94d4018b120..c863fb97822 100644 --- a/src/battle-scene.ts +++ b/src/battle-scene.ts @@ -84,6 +84,8 @@ export type AnySound = Phaser.Sound.WebAudioSound | Phaser.Sound.HTML5AudioSound export default class BattleScene extends SceneBase { public rexUI: UIPlugin; + public inputController: InputsController; + public uiInputs: UiInputs; public sessionPlayTime: integer = null; public masterVolume: number = 0.5; @@ -176,7 +178,6 @@ export default class BattleScene extends SceneBase { constructor() { super('battle'); - Phaser.Plugins.PluginCache.register('UiInputs', UiInputs, 'uiInputs'); initSpecies(); initMoves(); @@ -221,6 +222,8 @@ export default class BattleScene extends SceneBase { create() { initGameSpeed.apply(this); + this.inputController = new InputsController(this); + this.uiInputs = new UiInputs(this, this.inputController); this.gameData = new GameData(this); @@ -238,6 +241,7 @@ export default class BattleScene extends SceneBase { } update() { + this.inputController.update(); this.ui?.update(); } diff --git a/src/inputs-controller.ts b/src/inputs-controller.ts index 8d2cc6e595d..5df1f3ded7d 100644 --- a/src/inputs-controller.ts +++ b/src/inputs-controller.ts @@ -29,8 +29,7 @@ export enum Button { const repeatInputDelayMillis = 250; -export class InputsController extends Phaser.Plugins.ScenePlugin { - private game: Phaser.Game; +export class InputsController { private buttonKeys: Phaser.Input.Keyboard.Key[][]; private gamepads: Array = new Array(); private scene: Phaser.Scene; @@ -41,9 +40,7 @@ export class InputsController extends Phaser.Plugins.ScenePlugin { private interactions: Map> = new Map(); private time: Time; - constructor(scene: Phaser.Scene, pluginManager: Phaser.Plugins.PluginManager, pluginKey: string) { - super(scene, pluginManager, pluginKey); - this.game = pluginManager.game; + constructor(scene: Phaser.Scene) { this.scene = scene; this.time = this.scene.time; this.buttonKeys = []; @@ -56,30 +53,29 @@ export class InputsController extends Phaser.Plugins.ScenePlugin { } // We don't want the menu key to be repeated delete this.interactions[Button.MENU]; + this.init(); } - boot() { - this.eventEmitter = this.systems.events; + init() { this.events = new Phaser.Events.EventEmitter(); - this.game.events.on(Phaser.Core.Events.STEP, this.update, this); - if (typeof this.systems.input.gamepad !== 'undefined') { - this.systems.input.gamepad.on('connected', function (thisGamepad) { + if (typeof this.scene.input.gamepad !== 'undefined') { + this.scene.input.gamepad.on('connected', function (thisGamepad) { this.refreshGamepads(); this.setupGamepad(thisGamepad); }, this); // Check to see if the gamepad has already been setup by the browser - this.systems.input.gamepad.refreshPads(); - if (this.systems.input.gamepad.total) { + this.scene.input.gamepad.refreshPads(); + if (this.scene.input.gamepad.total) { this.refreshGamepads(); for (const thisGamepad of this.gamepads) { - this.systems.input.gamepad.emit('connected', thisGamepad); + this.scene.input.gamepad.emit('connected', thisGamepad); } } - this.systems.input.gamepad.on('down', this.gamepadButtonDown, this); - this.systems.input.gamepad.on('up', this.gamepadButtonUp, this); + this.scene.input.gamepad.on('down', this.gamepadButtonDown, this); + this.scene.input.gamepad.on('up', this.gamepadButtonUp, this); } // Keyboard @@ -109,7 +105,7 @@ export class InputsController extends Phaser.Plugins.ScenePlugin { refreshGamepads(): void { // Sometimes, gamepads are undefined. For some reason. - this.gamepads = this.systems.input.gamepad.gamepads.filter(function (el) { + this.gamepads = this.scene.input.gamepad.gamepads.filter(function (el) { return el != null; }); @@ -191,7 +187,7 @@ export class InputsController extends Phaser.Plugins.ScenePlugin { const keys: Phaser.Input.Keyboard.Key[] = []; if (keyConfig.hasOwnProperty(b)) { for (let k of keyConfig[b]) - keys.push(this.systems.input.keyboard.addKey(k, false)); + keys.push(this.scene.input.keyboard.addKey(k, false)); mobileKeyConfig[Button[b]] = keys[0]; } this.buttonKeys[b] = keys; diff --git a/src/main.ts b/src/main.ts index 542c979a009..f66ad885b8d 100644 --- a/src/main.ts +++ b/src/main.ts @@ -8,8 +8,6 @@ import InputTextPlugin from 'phaser3-rex-plugins/plugins/inputtext-plugin.js'; import BBCodeText from 'phaser3-rex-plugins/plugins/bbcodetext'; import TransitionImagePackPlugin from 'phaser3-rex-plugins/templates/transitionimagepack/transitionimagepack-plugin.js'; import { LoadingScene } from './loading-scene'; -import {InputsController} from "#app/inputs-controller"; -import {UiInputs} from "#app/ui-inputs"; // Catch global errors and display them in an alert so users can report the issue. @@ -54,14 +52,6 @@ const config: Phaser.Types.Core.GameConfig = { key: 'rexUI', plugin: UIPlugin, mapping: 'rexUI' - }, { - key: 'InputsController', - plugin: InputsController, - mapping: 'inputsController' - }, { - key: 'UiInputs', - plugin: UiInputs, - mapping: 'uiInputs' }] }, input: { diff --git a/src/ui-inputs.ts b/src/ui-inputs.ts index 03f42db6614..c965a74c1ac 100644 --- a/src/ui-inputs.ts +++ b/src/ui-inputs.ts @@ -1,25 +1,25 @@ import Phaser from "phaser"; import {Mode} from "./ui/ui"; -import {Button} from "./inputs-controller"; +import {Button, InputsController} from "./inputs-controller"; import MessageUiHandler from "./ui/message-ui-handler"; import StarterSelectUiHandler from "./ui/starter-select-ui-handler"; import {Setting, settingOptions} from "./system/settings"; import SettingsUiHandler from "./ui/settings-ui-handler"; -export class UiInputs extends Phaser.Plugins.ScenePlugin { - private game: Phaser.Game; +export class UiInputs { private scene: Phaser.Scene; private events; + private inputsController; - constructor(scene: Phaser.Scene, pluginManager: Phaser.Plugins.PluginManager, pluginKey: string) { - super(scene, pluginManager, pluginKey); - this.game = pluginManager.game; + constructor(scene: Phaser.Scene, inputsController: InputsController) { this.scene = scene; + this.inputsController = inputsController; + this.init(); } - boot() { - this.events = this.scene.inputsController.events; + init() { + this.events = this.inputsController.events; this.listenInputs(); }