diff --git a/config/retrodeck/reference_lists/features.json b/config/retrodeck/reference_lists/features.json index cc563727..1c55b43f 100644 --- a/config/retrodeck/reference_lists/features.json +++ b/config/retrodeck/reference_lists/features.json @@ -1061,6 +1061,7 @@ "url": "https://retrodeck.readthedocs.io/en/latest/wiki_about/what-is-retrodeck/", "launch": "Yuzu", "system": "switch", + "launch-args": "-f -g $game", "ponzu": true, "abxy_button": true }, @@ -1069,6 +1070,7 @@ "description": "Dolphin Wii and GameCube Emulator", "url": "https://retrodeck.readthedocs.io/en/latest/wiki_emulator_guides/dolphin-primehack/dolphin-primehack-guide/", "launch": "dolphin-emu-wrapper", + "launch-args": "-e $game", "system": [ "gc", "wii" @@ -1088,6 +1090,7 @@ "description": "A fork of Dolphiin to enhance Metroid Prime experience", "url": "https://retrodeck.readthedocs.io/en/latest/wiki_emulator_guides/dolphin-primehack/dolphin-primehack-guide/", "launch": "primehack-wrapper", + "launch-args": "-e $game", "system": [ "wii" ], @@ -1104,6 +1107,7 @@ "url": "https://retrodeck.readthedocs.io/en/latest/wiki_emulator_guides/cemu/cemu-guide/", "system": "wiiu", "launch": "Cemu-wrapper", + "launch-args": "-g $game", "properties": [ { "abxy_button": true, @@ -1116,7 +1120,8 @@ "name": "xemu", "url": "https://retrodeck.readthedocs.io/en/latest/wiki_emulator_guides/xemu/xemu-guide/", "system": "xbox", - "launch": "xemu" + "launch": "xemu", + "launch-args": "-dvd_path $game" }, "es-de": { "description": "ES-DE Emulation Frontend", diff --git a/functions/other_functions.sh b/functions/other_functions.sh index 99b6f05d..0bf40ba5 100644 --- a/functions/other_functions.sh +++ b/functions/other_functions.sh @@ -908,3 +908,55 @@ start_retrodeck() { log i "Starting RetroDECK v$version" es-de } + +run_game() { + # Arguments: $1 -> game path, $2 -> optional system + local game="$1" + local system="$2" + + # If no system is provided, extract it from the game path + if [[ -z "$system" ]]; then + system=$(echo "$game" | grep -oP '(?<=roms/)[^/]+') + fi + + log d "Run game: running $(basename "$game") for $system system" + + # Special case for retroarch + if [[ "$system" == "retroarch" ]]; then + log d "TODO: implement retroarch" + return + fi + + # Query the features JSON for emulators that support the system + local emulators=$(jq -r --arg system "$system" ' + .emulator | to_entries[] | + select( + (.value.system == $system) or + (.value.system[]? == $system) + ) | .key' "$features") + + # Check if multiple emulators are found and prompt the user to select one with zenity + if [[ $(echo "$emulators" | wc -l) -gt 1 ]]; then + emulator=$(echo "$emulators" | zenity --list --title="Select Emulator" --text="Multiple emulators found for $system. Select one to run." --column="Emulator") + else + emulator="$emulators" + fi + + # If no emulator was selected, exit + if [[ -z "$emulator" ]]; then + log e "No emulator selected. Exiting." + return 1 + fi + + log d "Run game: selected emulator $emulator" + + # Parse emulator launch command and arguments from the JSON file + local launch_command=$(jq -r ".emulator.$emulator.launch" "$features") + local launch_args=$(jq -r ".emulator.$emulator.\"launch-args\"" "$features") + + # Replace $game in launch_args with the actual game path, quoting it to handle spaces + launch_args=${launch_args//\$game/\"$game\"} + + # Form and execute the command + eval "$launch_command $launch_args" +} diff --git a/retrodeck.sh b/retrodeck.sh index c416de6c..47cacbe3 100644 --- a/retrodeck.sh +++ b/retrodeck.sh @@ -25,6 +25,7 @@ flatpak run [FLATPAK-RUN-OPTION] net.retrodeck-retrodeck [ARGUMENTS] Arguments: -h, --help Print this help -v, --version Print RetroDECK version + --run (system) Run a game from cli, if no system is defined it will deducted from the path. For example --run ~/retrodeck/roms/system/game.ext will be run with the system "system". --info-msg Print paths and config informations --configurator Starts the RetroDECK Configurator --compress-one Compresses target file to a compatible format @@ -42,6 +43,10 @@ https://retrodeck.net echo "RetroDECK v$version" exit ;; + --run*) + run_game "$2" "$3" + exit + ;; --info-msg*) echo "RetroDECK v$version" echo "RetroDECK config file is in: $rd_conf"