From ffa7753618d7eb70e6b69df043c9efcaa55e765f Mon Sep 17 00:00:00 2001 From: icenine451 Date: Wed, 13 Nov 2024 10:08:09 -0500 Subject: [PATCH 1/3] Make change_preset_dialog() not dependent on shared vars from build_preset_list_options() --- functions/presets.sh | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/functions/presets.sh b/functions/presets.sh index af077ac6..f0913274 100644 --- a/functions/presets.sh +++ b/functions/presets.sh @@ -3,8 +3,19 @@ change_preset_dialog() { # This function will build a list of all systems compatible with a given preset, their current enable/disabled state and allow the user to change one or more # USAGE: change_preset_dialog "$preset" + + preset="$1" + pretty_preset_name=${preset//_/ } # Preset name prettification + pretty_preset_name=$(echo $pretty_preset_name | awk '{for(i=1;i<=NF;i++){$i=toupper(substr($i,1,1))substr($i,2)}}1') # Preset name prettification + current_preset_settings=() + local section_results=$(sed -n '/\['"$preset"'\]/, /\[/{ /\['"$preset"'\]/! { /\[/! p } }' $rd_conf | sed '/^$/d') - build_preset_list_options "$1" + while IFS= read -r config_line + do + system_name=$(get_setting_name "$config_line" "retrodeck") + system_value=$(get_setting_value "$rd_conf" "$system_name" "retrodeck" "$preset") + current_preset_settings=("${current_preset_settings[@]}" "$system_value" "$(make_name_pretty $system_name)" "$system_name") + done < <(printf '%s\n' "$section_results") choice=$(rd_zenity \ --list --width=1200 --height=720 \ @@ -21,7 +32,7 @@ change_preset_dialog() { if [[ ! -z $choice || "$rc" == 0 ]]; then ( - make_preset_changes + make_preset_changes "$choice" "$1" ) | rd_zenity --icon-name=net.retrodeck.retrodeck --progress --no-cancel --pulsate --auto-close \ --window-icon="/app/share/icons/hicolor/scalable/apps/net.retrodeck.retrodeck.svg" \ @@ -80,6 +91,11 @@ make_preset_changes() { ] | join("\n") ' $features) + choice="$1" + preset="$2" + + build_preset_list_options "$preset" + IFS="," read -ra choices <<< "$choice" for emulator in "${all_systems[@]}"; do if [[ " ${choices[*]} " =~ " ${emulator} " && ! " ${current_enabled_systems[*]} " =~ " ${emulator} " ]]; then From 155e331a43889fb53f309b460fa7e1409e1c79f2 Mon Sep 17 00:00:00 2001 From: icenine451 Date: Wed, 13 Nov 2024 10:10:07 -0500 Subject: [PATCH 2/3] Add comments to build_preset_list_options() --- functions/presets.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/functions/presets.sh b/functions/presets.sh index f0913274..86e15c16 100644 --- a/functions/presets.sh +++ b/functions/presets.sh @@ -3,7 +3,7 @@ change_preset_dialog() { # This function will build a list of all systems compatible with a given preset, their current enable/disabled state and allow the user to change one or more # USAGE: change_preset_dialog "$preset" - + preset="$1" pretty_preset_name=${preset//_/ } # Preset name prettification pretty_preset_name=$(echo $pretty_preset_name | awk '{for(i=1;i<=NF;i++){$i=toupper(substr($i,1,1))substr($i,2)}}1') # Preset name prettification @@ -46,6 +46,8 @@ change_preset_dialog() { build_preset_list_options() { # This function will build a list of all the systems available for a given preset # The list will be generated into a Godot temp file and the variable $current_preset_settings + # The other arrays built (all_systems, changed_systems etc.) are also used in the make_preset_changes() function, so this needs to be called in the same memory space as that function at least once + # USAGE: build_preset_list_options "$preset" if [[ -f "$godot_current_preset_settings" ]]; then rm -f "$godot_current_preset_settings" # Godot data transfer temp files From 353c626a3727cad095c1f70e4ef2b5ba57138988 Mon Sep 17 00:00:00 2001 From: icenine451 Date: Wed, 13 Nov 2024 10:13:01 -0500 Subject: [PATCH 3/3] Add comments on new usage of make_preset_changes(), which now can be called externally --- functions/presets.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/functions/presets.sh b/functions/presets.sh index 86e15c16..bb397d56 100644 --- a/functions/presets.sh +++ b/functions/presets.sh @@ -82,7 +82,9 @@ build_preset_list_options() { make_preset_changes() { - # This function will take an array $choices, which contains the names of systems that have been enabled for this preset and enable them in the backend + # This function will take a preset name $preset and a CSV list $choice, which contains the names of systems that have been enabled for this preset and enable them in the backend + # Any systems which are currently enabled and not in the CSV list $choice will instead be disabled in the backend + # USAGE: make_preset_changes $choice $preset # Fetch incompatible presets from JSON and create a lookup list incompatible_presets=$(jq -r '