mirror of
https://github.com/rommapp/romm.git
synced 2026-11-30 18:42:34 +01:00
improve parsing default controls
This commit is contained in:
@@ -31,8 +31,18 @@ SQLITE_DB_BASE_PATH: Final = f"{ROMM_BASE_PATH}/database"
|
||||
|
||||
|
||||
class EjsControlsButton(TypedDict):
|
||||
value: NotRequired[str]
|
||||
value2: NotRequired[str]
|
||||
value: NotRequired[str] # Keyboard key
|
||||
value2: NotRequired[str] # Controller button
|
||||
|
||||
|
||||
class EjsControls(TypedDict):
|
||||
_0: dict[int, EjsControlsButton] # button_number -> EjsControlsButton
|
||||
_1: dict[int, EjsControlsButton]
|
||||
_2: dict[int, EjsControlsButton]
|
||||
_3: dict[int, EjsControlsButton]
|
||||
|
||||
|
||||
EjsOption = dict[str, str] # option_name -> option_value
|
||||
|
||||
|
||||
class Config:
|
||||
@@ -46,14 +56,10 @@ class Config:
|
||||
PLATFORMS_VERSIONS: dict[str, str]
|
||||
ROMS_FOLDER_NAME: str
|
||||
FIRMWARE_FOLDER_NAME: str
|
||||
EJS_DEBUG: bool
|
||||
EJS_OPTIONS: dict[
|
||||
str, dict[str, str]
|
||||
] # dict[core_name, dict[option_name, option_value]]
|
||||
EJS_CONTROLS: dict[
|
||||
str, dict[int, dict[int, EjsControlsButton]]
|
||||
] # dict[core_name, dict[player_number, dict[button_number, EjsControlsButton]]]
|
||||
HIGH_PRIO_STRUCTURE_PATH: str
|
||||
EJS_DEBUG: bool
|
||||
EJS_OPTIONS: dict[str, EjsOption] # core_name -> EjsOption
|
||||
EJS_CONTROLS: dict[str, EjsControls] # core_name -> EjsControls
|
||||
|
||||
def __init__(self, **entries):
|
||||
self.__dict__.update(entries)
|
||||
@@ -163,9 +169,25 @@ class ConfigManager:
|
||||
),
|
||||
EJS_DEBUG=pydash.get(self._raw_config, "emulatorjs.debug", False),
|
||||
EJS_OPTIONS=pydash.get(self._raw_config, "emulatorjs.options", {}),
|
||||
EJS_CONTROLS=pydash.get(self._raw_config, "emulatorjs.controls", {}),
|
||||
EJS_CONTROLS=self._get_ejs_controls(),
|
||||
)
|
||||
|
||||
def _get_ejs_controls(self) -> dict[str, EjsControls]:
|
||||
"""Get EJS controls with default player entries for each core"""
|
||||
raw_controls = pydash.get(self._raw_config, "emulatorjs.controls", {})
|
||||
controls = {}
|
||||
|
||||
for core, core_controls in raw_controls.items():
|
||||
# Create EjsControls object with default empty player dictionaries
|
||||
controls[core] = EjsControls(
|
||||
_0=core_controls.get(0, {}),
|
||||
_1=core_controls.get(1, {}),
|
||||
_2=core_controls.get(2, {}),
|
||||
_3=core_controls.get(3, {}),
|
||||
)
|
||||
|
||||
return controls
|
||||
|
||||
def _validate_config(self):
|
||||
"""Validates the config.yml file"""
|
||||
if not isinstance(self.config.EXCLUDED_PLATFORMS, list):
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
from typing import TypedDict
|
||||
|
||||
from config.config_manager import EjsControlsButton
|
||||
from config.config_manager import EjsControls
|
||||
|
||||
|
||||
class ConfigResponse(TypedDict):
|
||||
@@ -14,4 +14,4 @@ class ConfigResponse(TypedDict):
|
||||
PLATFORMS_VERSIONS: dict[str, str]
|
||||
EJS_DEBUG: bool
|
||||
EJS_OPTIONS: dict[str, dict[str, str]]
|
||||
EJS_CONTROLS: dict[str, dict[int, dict[int, EjsControlsButton]]]
|
||||
EJS_CONTROLS: dict[str, EjsControls]
|
||||
|
||||
1
frontend/src/__generated__/index.ts
generated
1
frontend/src/__generated__/index.ts
generated
@@ -24,6 +24,7 @@ export type { ConfigResponse } from './models/ConfigResponse';
|
||||
export type { CustomLimitOffsetPage_SimpleRomSchema_ } from './models/CustomLimitOffsetPage_SimpleRomSchema_';
|
||||
export type { DetailedRomSchema } from './models/DetailedRomSchema';
|
||||
export type { EarnedAchievement } from './models/EarnedAchievement';
|
||||
export type { EjsControls } from './models/EjsControls';
|
||||
export type { EjsControlsButton } from './models/EjsControlsButton';
|
||||
export type { EmulationDict } from './models/EmulationDict';
|
||||
export type { FilesystemDict } from './models/FilesystemDict';
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
/* istanbul ignore file */
|
||||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
import type { EjsControlsButton } from './EjsControlsButton';
|
||||
import type { EjsControls } from './EjsControls';
|
||||
export type ConfigResponse = {
|
||||
EXCLUDED_PLATFORMS: Array<string>;
|
||||
EXCLUDED_SINGLE_EXT: Array<string>;
|
||||
@@ -14,6 +14,6 @@ export type ConfigResponse = {
|
||||
PLATFORMS_VERSIONS: Record<string, string>;
|
||||
EJS_DEBUG: boolean;
|
||||
EJS_OPTIONS: Record<string, Record<string, string>>;
|
||||
EJS_CONTROLS: Record<string, Record<string, Record<string, EjsControlsButton>>>;
|
||||
EJS_CONTROLS: Record<string, EjsControls>;
|
||||
};
|
||||
|
||||
|
||||
12
frontend/src/__generated__/models/EjsControls.ts
generated
Normal file
12
frontend/src/__generated__/models/EjsControls.ts
generated
Normal file
@@ -0,0 +1,12 @@
|
||||
/* generated using openapi-typescript-codegen -- do not edit */
|
||||
/* istanbul ignore file */
|
||||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
import type { EjsControlsButton } from './EjsControlsButton';
|
||||
export type EjsControls = {
|
||||
_0: Record<string, EjsControlsButton>;
|
||||
_1: Record<string, EjsControlsButton>;
|
||||
_2: Record<string, EjsControlsButton>;
|
||||
_3: Record<string, EjsControlsButton>;
|
||||
};
|
||||
|
||||
@@ -79,12 +79,32 @@ export default defineStore("config", {
|
||||
},
|
||||
getEJSControls(
|
||||
core: string | null,
|
||||
): Record<string, Record<string, EjsControlsButton>> {
|
||||
const defaultControls = this.config.EJS_CONTROLS["default"] || {};
|
||||
): Record<number, Record<number, EjsControlsButton>> {
|
||||
const defaultControls = {
|
||||
0: this.config.EJS_CONTROLS["default"]?.["_0"] || {},
|
||||
1: this.config.EJS_CONTROLS["default"]?.["_1"] || {},
|
||||
2: this.config.EJS_CONTROLS["default"]?.["_2"] || {},
|
||||
3: this.config.EJS_CONTROLS["default"]?.["_3"] || {},
|
||||
};
|
||||
if (!core) return defaultControls;
|
||||
|
||||
return {
|
||||
...defaultControls,
|
||||
...this.config.EJS_CONTROLS[core],
|
||||
0: {
|
||||
...(this.config.EJS_CONTROLS[core]?.["_0"] || {}),
|
||||
...defaultControls[0],
|
||||
},
|
||||
1: {
|
||||
...(this.config.EJS_CONTROLS[core]?.["_1"] || {}),
|
||||
...defaultControls[1],
|
||||
},
|
||||
2: {
|
||||
...(this.config.EJS_CONTROLS[core]?.["_2"] || {}),
|
||||
...defaultControls[2],
|
||||
},
|
||||
3: {
|
||||
...(this.config.EJS_CONTROLS[core]?.["_3"] || {}),
|
||||
...defaultControls[3],
|
||||
},
|
||||
};
|
||||
},
|
||||
reset() {},
|
||||
|
||||
Reference in New Issue
Block a user