diff --git a/frontend/src/stores/config.ts b/frontend/src/stores/config.ts index 793df98e1..89824d39e 100644 --- a/frontend/src/stores/config.ts +++ b/frontend/src/stores/config.ts @@ -79,31 +79,45 @@ export default defineStore("config", { }, getEJSControls( core: string | null, - ): Record> { - 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; + ): Record> | null { + const defaultControls = this.config.EJS_CONTROLS["default"]; + if (!core) { + if (!defaultControls) return null; + return { + 0: defaultControls["_0"], + 1: defaultControls["_1"], + 2: defaultControls["_2"], + 3: defaultControls["_3"], + }; + } + + const coreControls = this.config.EJS_CONTROLS[core]; + if (!coreControls) return null; + if (!defaultControls) { + return { + 0: coreControls["_0"], + 1: coreControls["_1"], + 2: coreControls["_2"], + 3: coreControls["_3"], + }; + } return { 0: { - ...defaultControls[0], - ...(this.config.EJS_CONTROLS[core]?.["_0"] || {}), + ...defaultControls["_0"], + ...coreControls["_0"], }, 1: { - ...defaultControls[1], - ...(this.config.EJS_CONTROLS[core]?.["_1"] || {}), + ...defaultControls["_1"], + ...coreControls["_1"], }, 2: { - ...defaultControls[2], - ...(this.config.EJS_CONTROLS[core]?.["_2"] || {}), + ...defaultControls["_2"], + ...coreControls["_2"], }, 3: { - ...defaultControls[3], - ...(this.config.EJS_CONTROLS[core]?.["_3"] || {}), + ...defaultControls["_3"], + ...coreControls["_3"], }, }; }, diff --git a/frontend/src/views/Player/EmulatorJS/Player.vue b/frontend/src/views/Player/EmulatorJS/Player.vue index 278552e68..e261ba698 100644 --- a/frontend/src/views/Player/EmulatorJS/Player.vue +++ b/frontend/src/views/Player/EmulatorJS/Player.vue @@ -125,7 +125,8 @@ window.EJS_defaultOptions = { rewindEnabled: "enabled", ...coreOptions, }; -window.EJS_defaultControls = configStore.getEJSControls(props.core); +const ejsControls = configStore.getEJSControls(props.core); +if (ejsControls) window.EJS_defaultControls = ejsControls; // Set a valid game name window.EJS_gameName = romRef.value.fs_name_no_tags .replace(INVALID_CHARS_REGEX, "")