fix imports

This commit is contained in:
Greenlamp 2024-05-13 02:03:06 +02:00
parent 627a6cb66f
commit e798f72a63
7 changed files with 47 additions and 48 deletions

View File

@ -1,16 +1,15 @@
import {GamepadConfig} from "../inputs-controller"; import {InterfaceConfig} from "../inputs-controller";
import {SettingGamepad} from "#app/system/settings-gamepad";
import {Button} from "#app/enums/buttons"; import {Button} from "#app/enums/buttons";
// Given a button index from an input event, return its naming from the mapping config // Given a button index from an input event, return its naming from the mapping config
export function getKeyFromInputIndex(config: GamepadConfig, index: number): String | null { export function getKeyFromInputIndex(config: InterfaceConfig, index: number): String | null {
for (const key of Object.keys(config.gamepadMapping)) { for (const key of Object.keys(config.gamepadMapping)) {
if (config.gamepadMapping[key] === index) return key; if (config.gamepadMapping[key] === index) return key;
} }
return null; return null;
} }
export function getKeyFromKeyboardKey(config: GamepadConfig, key): String | null { export function getKeyFromKeyboardKey(config: InterfaceConfig, key): String | null {
for (const _key of Object.keys(config.gamepadMapping)) { for (const _key of Object.keys(config.gamepadMapping)) {
if (config.gamepadMapping[_key] === key) return _key; if (config.gamepadMapping[_key] === key) return _key;
} }
@ -18,7 +17,7 @@ export function getKeyFromKeyboardKey(config: GamepadConfig, key): String | null
} }
// Given a setting name, return the key assigned to it from the config file // Given a setting name, return the key assigned to it from the config file
export function getKeyForSettingName(config: GamepadConfig, settingName: string): String | null { export function getKeyForSettingName(config: InterfaceConfig, settingName: string): String | null {
for (const key of Object.keys(config.setting)) { for (const key of Object.keys(config.setting)) {
if (config.setting[key] === settingName) return key; if (config.setting[key] === settingName) return key;
} }
@ -26,7 +25,7 @@ export function getKeyForSettingName(config: GamepadConfig, settingName: string)
} }
// Given a Button, return the custom key assigned to it from the config file // Given a Button, return the custom key assigned to it from the config file
export function getCurrenlyAssignedKeyToAction(config: GamepadConfig, action: Button): String | null { export function getCurrenlyAssignedKeyToAction(config: InterfaceConfig, action: Button): String | null {
for (const key of Object.keys(config.custom)) { for (const key of Object.keys(config.custom)) {
if (config.custom[key] === action) return key; if (config.custom[key] === action) return key;
} }
@ -34,7 +33,7 @@ export function getCurrenlyAssignedKeyToAction(config: GamepadConfig, action: Bu
} }
// Given a setting name, return the custom key for the default action from the config file // Given a setting name, return the custom key for the default action from the config file
export function getCurrentlyAssignedToSettingName(config: GamepadConfig, settingName: string): String { export function getCurrentlyAssignedToSettingName(config: InterfaceConfig, settingName: string): String {
const oldKey = getKeyForSettingName(config, settingName) const oldKey = getKeyForSettingName(config, settingName)
const action = config.default[oldKey]; const action = config.default[oldKey];
const key = getCurrenlyAssignedKeyToAction(config, action); const key = getCurrenlyAssignedKeyToAction(config, action);
@ -42,18 +41,18 @@ export function getCurrentlyAssignedToSettingName(config: GamepadConfig, setting
} }
// Given a button index from an input event, return its icon from the config file // Given a button index from an input event, return its icon from the config file
export function getCurrenlyAssignedIconFromInputIndex(config: GamepadConfig, index: number): String { export function getCurrenlyAssignedIconFromInputIndex(config: InterfaceConfig, index: number): String {
const key = getKeyFromInputIndex(config, index); const key = getKeyFromInputIndex(config, index);
return config.icons[key]; return config.icons[key];
} }
export function getCurrenlyAssignedIconFromKeyboardKey(config: GamepadConfig, key): String { export function getCurrenlyAssignedIconFromKeyboardKey(config: InterfaceConfig, key): String {
const _key = getKeyFromKeyboardKey(config, key); const _key = getKeyFromKeyboardKey(config, key);
return config.icons[_key]; return config.icons[_key];
} }
// Given a setting name, return the icon currently assigned to this setting name // Given a setting name, return the icon currently assigned to this setting name
export function getCurrentlyAssignedIconToSettingName(config: GamepadConfig, settingName: string): string { export function getCurrentlyAssignedIconToSettingName(config: InterfaceConfig, settingName: string): string {
const key = getCurrentlyAssignedToSettingName(config, settingName); const key = getCurrentlyAssignedToSettingName(config, settingName);
return config.icons[key]; return config.icons[key];
} }

View File

@ -12,9 +12,9 @@ import {
getCurrenlyAssignedIconFromInputIndex, getCurrentlyAssignedIconToSettingName, getCurrenlyAssignedIconFromInputIndex, getCurrentlyAssignedIconToSettingName,
getKeyFromInputIndex, getCurrentlyAssignedToSettingName, getCurrenlyAssignedIconFromKeyboardKey getKeyFromInputIndex, getCurrentlyAssignedToSettingName, getCurrenlyAssignedIconFromKeyboardKey
} from "./configs/gamepad-utils"; } from "./configs/gamepad-utils";
import SettingsKeyboardUiHandler from "#app/ui/settings/settings-keyboard-ui-handler"; import SettingsKeyboardUiHandler from "./ui/settings/settings-keyboard-ui-handler";
import cfg_keyboard_azerty from "#app/configs/cfg_keyboard_azerty"; import cfg_keyboard_azerty from "./configs/cfg_keyboard_azerty";
import {SettingKeyboard} from "#app/system/settings-keyboard"; import {SettingKeyboard} from "./system/settings-keyboard";
export interface GamepadMapping { export interface GamepadMapping {
[key: string]: number; [key: string]: number;
@ -32,7 +32,7 @@ export interface MappingLayout {
[key: string]: Button; [key: string]: Button;
} }
export interface GamepadConfig { export interface InterfaceConfig {
padID: string; padID: string;
padType: string; padType: string;
gamepadMapping: GamepadMapping; gamepadMapping: GamepadMapping;
@ -76,8 +76,8 @@ export class InputsController {
private buttonLock2: Button; private buttonLock2: Button;
private interactions: Map<Button, Map<string, boolean>> = new Map(); private interactions: Map<Button, Map<string, boolean>> = new Map();
private time: Phaser.Time.Clock; private time: Phaser.Time.Clock;
private configs: Map<string, GamepadConfig> = new Map(); private configs: Map<string, InterfaceConfig> = new Map();
private keyboardConfigs: Map<string, GamepadConfig> = new Map(); private keyboardConfigs: Map<string, InterfaceConfig> = new Map();
private gamepadSupport: boolean = true; private gamepadSupport: boolean = true;
@ -204,6 +204,7 @@ export class InputsController {
this.deactivatePressedKey(); this.deactivatePressedKey();
this.initChosenGamepad(gamepad) this.initChosenGamepad(gamepad)
} }
setChosenKeyboardLayout(layoutKeyboard: String): void { setChosenKeyboardLayout(layoutKeyboard: String): void {
this.deactivatePressedKey(); this.deactivatePressedKey();
this.initChosenLayoutKeyboard(layoutKeyboard) this.initChosenLayoutKeyboard(layoutKeyboard)
@ -532,9 +533,9 @@ export class InputsController {
* If no specific configuration matches, it defaults to a generic gamepad configuration. * If no specific configuration matches, it defaults to a generic gamepad configuration.
* *
* @param id The identifier string of the gamepad. * @param id The identifier string of the gamepad.
* @returns GamepadConfig The configuration object corresponding to the identified gamepad type. * @returns InterfaceConfig The configuration object corresponding to the identified gamepad type.
*/ */
getConfig(id: string): GamepadConfig { getConfig(id: string): InterfaceConfig {
id = id.toLowerCase(); id = id.toLowerCase();
if (id.includes('081f') && id.includes('e401')) { if (id.includes('081f') && id.includes('e401')) {
@ -548,7 +549,7 @@ export class InputsController {
return pad_generic; return pad_generic;
} }
getConfigKeyboard(id: string): GamepadConfig { getConfigKeyboard(id: string): InterfaceConfig {
if (id === 'azerty') if (id === 'azerty')
return cfg_keyboard_azerty; return cfg_keyboard_azerty;
@ -699,9 +700,9 @@ export class InputsController {
* Retrieves the active configuration for the currently chosen gamepad. * Retrieves the active configuration for the currently chosen gamepad.
* It checks if a specific gamepad ID is stored under the chosen gamepad's configurations and returns it. * It checks if a specific gamepad ID is stored under the chosen gamepad's configurations and returns it.
* *
* @returns GamepadConfig The configuration object for the active gamepad, or null if not set. * @returns InterfaceConfig The configuration object for the active gamepad, or null if not set.
*/ */
getActiveConfig(): GamepadConfig | null { getActiveConfig(): InterfaceConfig | null {
if (this.configs[this.chosenGamepad]?.padID) return this.configs[this.chosenGamepad] if (this.configs[this.chosenGamepad]?.padID) return this.configs[this.chosenGamepad]
return null; return null;
} }
@ -710,9 +711,9 @@ export class InputsController {
* Retrieves the active configuration for the currently chosen gamepad. * Retrieves the active configuration for the currently chosen gamepad.
* It checks if a specific gamepad ID is stored under the chosen gamepad's configurations and returns it. * It checks if a specific gamepad ID is stored under the chosen gamepad's configurations and returns it.
* *
* @returns GamepadConfig The configuration object for the active gamepad, or null if not set. * @returns InterfaceConfig The configuration object for the active gamepad, or null if not set.
*/ */
getActiveKeyboardConfig(): GamepadConfig | null { getActiveKeyboardConfig(): InterfaceConfig | null {
if (this.keyboardConfigs[this.chosenKeyboard]?.padID) return this.keyboardConfigs[this.chosenKeyboard] if (this.keyboardConfigs[this.chosenKeyboard]?.padID) return this.keyboardConfigs[this.chosenKeyboard]
return null; return null;
} }

View File

@ -1,10 +1,9 @@
import UiHandler from "#app/ui/ui-handler"; import UiHandler from "../ui-handler";
import Phaser from "phaser"; import BattleScene from "../../battle-scene";
import BattleScene from "#app/battle-scene"; import {Mode} from "../ui";
import {Mode} from "#app/ui/ui"; import {addWindow} from "../ui-theme";
import {addWindow} from "#app/ui/ui-theme"; import {addTextObject, TextStyle} from "../text";
import {addTextObject, TextStyle} from "#app/ui/text"; import {Button} from "../../enums/buttons";
import {Button} from "#app/enums/buttons";
export default abstract class AbstractBindingUiHandler extends UiHandler { export default abstract class AbstractBindingUiHandler extends UiHandler {
@ -116,7 +115,7 @@ export default abstract class AbstractBindingUiHandler extends UiHandler {
this.getUi().bringToTop(this.actionsContainer); this.getUi().bringToTop(this.actionsContainer);
this.optionSelectContainer.setVisible(true); this.optionSelectContainer.setVisible(true);
setTimeout(() => this.listening = true, 150); setTimeout(() => this.listening = true, 300);
return true; return true;
} }
@ -177,6 +176,7 @@ export default abstract class AbstractBindingUiHandler extends UiHandler {
clear() { clear() {
super.clear(); super.clear();
this.listening = false;
this.target = null; this.target = null;
this.cancelFn = null; this.cancelFn = null;
this.optionSelectContainer.setVisible(false); this.optionSelectContainer.setVisible(false);

View File

@ -1,11 +1,11 @@
import UiHandler from "#app/ui/ui-handler"; import UiHandler from "../ui-handler";
import BattleScene from "#app/battle-scene"; import BattleScene from "../../battle-scene";
import {Mode} from "#app/ui/ui"; import {Mode} from "../ui";
import {GamepadConfig} from "#app/inputs-controller"; import {InterfaceConfig} from "../../inputs-controller";
import {addWindow} from "#app/ui/ui-theme"; import {addWindow} from "../ui-theme";
import {addTextObject, TextStyle} from "#app/ui/text"; import {addTextObject, TextStyle} from "../text";
import {getCurrentlyAssignedIconToSettingName, getKeyForSettingName} from "#app/configs/gamepad-utils"; import {getCurrentlyAssignedIconToSettingName, getKeyForSettingName} from "../../configs/gamepad-utils";
import {Button} from "#app/enums/buttons"; import {Button} from "../../enums/buttons";
export interface InputsIcons { export interface InputsIcons {
[key: string]: Phaser.GameObjects.Sprite; [key: string]: Phaser.GameObjects.Sprite;
@ -151,7 +151,7 @@ export default abstract class AbstractSettingsUiUiHandler extends UiHandler {
continue; continue;
} }
// For null options, add an icon for the key. // For null options, add an icon for the key.
const key = getKeyForSettingName(config as GamepadConfig, this.settingDevice[setting]); const key = getKeyForSettingName(config as InterfaceConfig, this.settingDevice[setting]);
const icon = this.scene.add.sprite(0, 0, this.textureOverride ? this.textureOverride : config.padType); const icon = this.scene.add.sprite(0, 0, this.textureOverride ? this.textureOverride : config.padType);
icon.setScale(0.1); icon.setScale(0.1);
icon.setOrigin(0, -0.1); icon.setOrigin(0, -0.1);
@ -270,7 +270,7 @@ export default abstract class AbstractSettingsUiUiHandler extends UiHandler {
return true; return true;
} }
setLayout(activeConfig: GamepadConfig): boolean { setLayout(activeConfig: InterfaceConfig): boolean {
// Check if there is no active configuration (e.g., no gamepad connected). // Check if there is no active configuration (e.g., no gamepad connected).
if (!activeConfig) { if (!activeConfig) {
// Retrieve the layout for when no gamepads are connected. // Retrieve the layout for when no gamepads are connected.

View File

@ -1,7 +1,6 @@
import BattleScene from "#app/battle-scene"; import BattleScene from "../../battle-scene";
import Phaser from "phaser"; import AbstractBindingUiHandler from "../settings/abrast-binding-ui-handler";
import AbstractBindingUiHandler from "#app/ui/settings/abrast-binding-ui-handler"; import {Mode} from "../ui";
import {Mode} from "#app/ui/ui";
export default class GamepadBindingUiHandler extends AbstractBindingUiHandler { export default class GamepadBindingUiHandler extends AbstractBindingUiHandler {

View File

@ -1,6 +1,6 @@
import BattleScene from "../../battle-scene"; import BattleScene from "../../battle-scene";
import AbstractBindingUiHandler from "../settings/abrast-binding-ui-handler";
import {Mode} from "../ui"; import {Mode} from "../ui";
import AbstractBindingUiHandler from "#app/ui/settings/abrast-binding-ui-handler";
export default class KeyboardBindingUiHandler extends AbstractBindingUiHandler { export default class KeyboardBindingUiHandler extends AbstractBindingUiHandler {

View File

@ -6,7 +6,7 @@ import {truncateString} from "../../utils";
import pad_xbox360 from "#app/configs/pad_xbox360"; import pad_xbox360 from "#app/configs/pad_xbox360";
import pad_dualshock from "#app/configs/pad_dualshock"; import pad_dualshock from "#app/configs/pad_dualshock";
import pad_unlicensedSNES from "#app/configs/pad_unlicensedSNES"; import pad_unlicensedSNES from "#app/configs/pad_unlicensedSNES";
import {GamepadConfig} from "#app/inputs-controller"; import {InterfaceConfig} from "#app/inputs-controller";
import AbstractSettingsUiUiHandler from "#app/ui/settings/abstract-settings-ui-handler"; import AbstractSettingsUiUiHandler from "#app/ui/settings/abstract-settings-ui-handler";
export default class SettingsGamepadUiHandler extends AbstractSettingsUiUiHandler { export default class SettingsGamepadUiHandler extends AbstractSettingsUiUiHandler {
@ -48,7 +48,7 @@ export default class SettingsGamepadUiHandler extends AbstractSettingsUiUiHandle
return settings; return settings;
} }
setLayout(activeConfig: GamepadConfig): boolean { setLayout(activeConfig: InterfaceConfig): boolean {
// Check if there is no active configuration (e.g., no gamepad connected). // Check if there is no active configuration (e.g., no gamepad connected).
if (!activeConfig) { if (!activeConfig) {
// Retrieve the layout for when no gamepads are connected. // Retrieve the layout for when no gamepads are connected.