// plugins/InputPlugin.js import { InputSystem } from './core/InputSystem.js'; import { PhaserInputAdapter } from './adapters/PhaserInputAdapter.js'; /** * InputPlugin 场景插件 * 作为 Phaser 场景插件的包装器,使用适配器架构 */ export class InputPlugin extends Phaser.Plugins.ScenePlugin { constructor(scene, pluginManager) { super(scene, pluginManager); console.log('InputPlugin 场景插件初始化'); // 创建 Phaser 适配器 this.adapter = new PhaserInputAdapter(scene); // 创建核心输入系统 this.inputSystem = new InputSystem(this.adapter); // 初始化 this.inputSystem.initialize(); } /** * 启动插件 */ boot() { console.log('InputPlugin 场景插件启动'); } /** * 测试方法 * @returns {string} 测试结果 */ testMethod() { return 'InputPlugin 测试方法'; } /** * 创建触摸轮盘 * @param {Object} config 轮盘配置 * @returns {string} 轮盘ID */ createJoystick(config) { return this.inputSystem.createJoystick(config); } /** * 创建屏幕按钮 * @param {Object} config 按钮配置 * @returns {string} 按钮ID */ createButton(config) { return this.inputSystem.createButton(config); } /** * 获取轮盘方向向量 * @param {string} joystickId 轮盘ID * @returns {Object} 方向向量 {x, y} */ getJoystickDirection(joystickId) { return this.inputSystem.getJoystickDirection(joystickId); } /** * 获取轮盘力度 * @param {string} joystickId 轮盘ID * @returns {number} 力度值 (0-1) */ getJoystickMagnitude(joystickId) { return this.inputSystem.getJoystickMagnitude(joystickId); } /** * 获取归一化的轮盘方向 * @param {string} joystickId 轮盘ID * @returns {Object} 归一化向量 {x, y} (-1 到 1) */ getJoystickNormalized(joystickId) { return this.inputSystem.getJoystickNormalized(joystickId); } /** * 检查按钮是否按下 * @param {string} buttonId 按钮ID * @returns {boolean} 是否按下 */ isButtonDown(buttonId) { return this.inputSystem.isButtonDown(buttonId); } /** * 检查按钮是否释放 * @param {string} buttonId 按钮ID * @returns {boolean} 是否释放 */ isButtonUp(buttonId) { return this.inputSystem.isButtonUp(buttonId); } /** * 销毁插件 */ destroy() { console.log('InputPlugin 场景插件销毁'); if (this.inputSystem) { this.inputSystem.destroy(); } super.destroy(); } }