remove Plugins things as it's too uncertain how it works on prod

This commit is contained in:
Greenlamp 2024-05-04 01:34:59 +02:00
parent f47b650a76
commit e18a4f3d16
4 changed files with 26 additions and 36 deletions

View File

@ -84,6 +84,8 @@ export type AnySound = Phaser.Sound.WebAudioSound | Phaser.Sound.HTML5AudioSound
export default class BattleScene extends SceneBase { export default class BattleScene extends SceneBase {
public rexUI: UIPlugin; public rexUI: UIPlugin;
public inputController: InputsController;
public uiInputs: UiInputs;
public sessionPlayTime: integer = null; public sessionPlayTime: integer = null;
public masterVolume: number = 0.5; public masterVolume: number = 0.5;
@ -176,7 +178,6 @@ export default class BattleScene extends SceneBase {
constructor() { constructor() {
super('battle'); super('battle');
Phaser.Plugins.PluginCache.register('UiInputs', UiInputs, 'uiInputs');
initSpecies(); initSpecies();
initMoves(); initMoves();
@ -221,6 +222,8 @@ export default class BattleScene extends SceneBase {
create() { create() {
initGameSpeed.apply(this); initGameSpeed.apply(this);
this.inputController = new InputsController(this);
this.uiInputs = new UiInputs(this, this.inputController);
this.gameData = new GameData(this); this.gameData = new GameData(this);
@ -238,6 +241,7 @@ export default class BattleScene extends SceneBase {
} }
update() { update() {
this.inputController.update();
this.ui?.update(); this.ui?.update();
} }

View File

@ -29,8 +29,7 @@ export enum Button {
const repeatInputDelayMillis = 250; const repeatInputDelayMillis = 250;
export class InputsController extends Phaser.Plugins.ScenePlugin { export class InputsController {
private game: Phaser.Game;
private buttonKeys: Phaser.Input.Keyboard.Key[][]; private buttonKeys: Phaser.Input.Keyboard.Key[][];
private gamepads: Array<string> = new Array(); private gamepads: Array<string> = new Array();
private scene: Phaser.Scene; private scene: Phaser.Scene;
@ -41,9 +40,7 @@ export class InputsController extends Phaser.Plugins.ScenePlugin {
private interactions: Map<Button, Map<string, boolean>> = new Map(); private interactions: Map<Button, Map<string, boolean>> = new Map();
private time: Time; private time: Time;
constructor(scene: Phaser.Scene, pluginManager: Phaser.Plugins.PluginManager, pluginKey: string) { constructor(scene: Phaser.Scene) {
super(scene, pluginManager, pluginKey);
this.game = pluginManager.game;
this.scene = scene; this.scene = scene;
this.time = this.scene.time; this.time = this.scene.time;
this.buttonKeys = []; this.buttonKeys = [];
@ -56,30 +53,29 @@ export class InputsController extends Phaser.Plugins.ScenePlugin {
} }
// We don't want the menu key to be repeated // We don't want the menu key to be repeated
delete this.interactions[Button.MENU]; delete this.interactions[Button.MENU];
this.init();
} }
boot() { init() {
this.eventEmitter = this.systems.events;
this.events = new Phaser.Events.EventEmitter(); this.events = new Phaser.Events.EventEmitter();
this.game.events.on(Phaser.Core.Events.STEP, this.update, this);
if (typeof this.systems.input.gamepad !== 'undefined') { if (typeof this.scene.input.gamepad !== 'undefined') {
this.systems.input.gamepad.on('connected', function (thisGamepad) { this.scene.input.gamepad.on('connected', function (thisGamepad) {
this.refreshGamepads(); this.refreshGamepads();
this.setupGamepad(thisGamepad); this.setupGamepad(thisGamepad);
}, this); }, this);
// Check to see if the gamepad has already been setup by the browser // Check to see if the gamepad has already been setup by the browser
this.systems.input.gamepad.refreshPads(); this.scene.input.gamepad.refreshPads();
if (this.systems.input.gamepad.total) { if (this.scene.input.gamepad.total) {
this.refreshGamepads(); this.refreshGamepads();
for (const thisGamepad of this.gamepads) { 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.scene.input.gamepad.on('down', this.gamepadButtonDown, this);
this.systems.input.gamepad.on('up', this.gamepadButtonUp, this); this.scene.input.gamepad.on('up', this.gamepadButtonUp, this);
} }
// Keyboard // Keyboard
@ -109,7 +105,7 @@ export class InputsController extends Phaser.Plugins.ScenePlugin {
refreshGamepads(): void { refreshGamepads(): void {
// Sometimes, gamepads are undefined. For some reason. // 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; return el != null;
}); });
@ -191,7 +187,7 @@ export class InputsController extends Phaser.Plugins.ScenePlugin {
const keys: Phaser.Input.Keyboard.Key[] = []; const keys: Phaser.Input.Keyboard.Key[] = [];
if (keyConfig.hasOwnProperty(b)) { if (keyConfig.hasOwnProperty(b)) {
for (let k of keyConfig[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]; mobileKeyConfig[Button[b]] = keys[0];
} }
this.buttonKeys[b] = keys; this.buttonKeys[b] = keys;

View File

@ -8,8 +8,6 @@ import InputTextPlugin from 'phaser3-rex-plugins/plugins/inputtext-plugin.js';
import BBCodeText from 'phaser3-rex-plugins/plugins/bbcodetext'; import BBCodeText from 'phaser3-rex-plugins/plugins/bbcodetext';
import TransitionImagePackPlugin from 'phaser3-rex-plugins/templates/transitionimagepack/transitionimagepack-plugin.js'; import TransitionImagePackPlugin from 'phaser3-rex-plugins/templates/transitionimagepack/transitionimagepack-plugin.js';
import { LoadingScene } from './loading-scene'; 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. // 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', key: 'rexUI',
plugin: UIPlugin, plugin: UIPlugin,
mapping: 'rexUI' mapping: 'rexUI'
}, {
key: 'InputsController',
plugin: InputsController,
mapping: 'inputsController'
}, {
key: 'UiInputs',
plugin: UiInputs,
mapping: 'uiInputs'
}] }]
}, },
input: { input: {

View File

@ -1,25 +1,25 @@
import Phaser from "phaser"; import Phaser from "phaser";
import {Mode} from "./ui/ui"; import {Mode} from "./ui/ui";
import {Button} from "./inputs-controller"; import {Button, InputsController} from "./inputs-controller";
import MessageUiHandler from "./ui/message-ui-handler"; import MessageUiHandler from "./ui/message-ui-handler";
import StarterSelectUiHandler from "./ui/starter-select-ui-handler"; import StarterSelectUiHandler from "./ui/starter-select-ui-handler";
import {Setting, settingOptions} from "./system/settings"; import {Setting, settingOptions} from "./system/settings";
import SettingsUiHandler from "./ui/settings-ui-handler"; import SettingsUiHandler from "./ui/settings-ui-handler";
export class UiInputs extends Phaser.Plugins.ScenePlugin { export class UiInputs {
private game: Phaser.Game;
private scene: Phaser.Scene; private scene: Phaser.Scene;
private events; private events;
private inputsController;
constructor(scene: Phaser.Scene, pluginManager: Phaser.Plugins.PluginManager, pluginKey: string) { constructor(scene: Phaser.Scene, inputsController: InputsController) {
super(scene, pluginManager, pluginKey);
this.game = pluginManager.game;
this.scene = scene; this.scene = scene;
this.inputsController = inputsController;
this.init();
} }
boot() { init() {
this.events = this.scene.inputsController.events; this.events = this.inputsController.events;
this.listenInputs(); this.listenInputs();
} }