From e0e240848d367a5d1eaf4392c06a85f776eaf406 Mon Sep 17 00:00:00 2001 From: Storm Dragon Date: Sat, 28 Dec 2024 17:52:24 -0500 Subject: [PATCH] Added option for audio manual. --- .launch/FreeDoom.game | 80 +++++++++++++++++++++++++++++++++++++------ 1 file changed, 69 insertions(+), 11 deletions(-) diff --git a/.launch/FreeDoom.game b/.launch/FreeDoom.game index 0c5183c..5b5f63f 100755 --- a/.launch/FreeDoom.game +++ b/.launch/FreeDoom.game @@ -32,6 +32,58 @@ speak() { done } + +audio_manual() { + if command -v mpv &> /dev/null ; then + mediaPlayer=("mpv" "--really-quiet" "--no-video") + else + mediaPlayer=("play" "-qV0") + fi + local manualPath="${gamePath}/Manual" + declare -a menuList + for i in "${manualPath}"/*/ ; do + local path="${i%/}" + local name="${i/${manualPath}\//}" + local name="${name% *}" + menuList+=("$path" "$name") + done + manualPath="$(dialog --backtitle "Select a Manual" \ + --clear \ + --no-tags \ + --menu "Please select one" 0 0 0 "${menuList[@]}" --stdout)" + [[ $? -ne 0 ]] && exit 0 + # If user selected a manual, show the audio file menu + if [[ -n "$manualPath" ]]; then + declare -a audioList=("all" "Play All") # Start with "All" option + # Add all mp3 files to the menu + while IFS= read -r file; do + local filename="${file##*/}" + local menuname="${filename%.mp3}" + audioList+=("$file" "$menuname") + done < <(find "$manualPath" -name "*.mp3" | sort) + local selection + selection="$(dialog --backtitle "Select Audio Track" \ + --clear \ + --no-tags \ + --menu "Please select one" 0 0 0 "${audioList[@]}" --stdout)" + [[ $? -ne 0 ]] && exit 0 + if [[ -n "$selection" ]]; then + if [[ "$selection" == "all" ]]; then + # Play all files in order + find "$manualPath" -name "*.mp3" -print0 | sort -z | \ + while IFS= read -r -d '' file; do + "${mediaPlayer[@]}" "$file" + done + else + # Play selected file + "${mediaPlayer[@]}" "$selection" + return + fi + fi + fi +} + + # Dialog setup: DIALOG_ITEM_HELP="" export DIALOGOPTS='--no-lines --visit-items' @@ -180,17 +232,23 @@ if [[ "$doomLanguage" != "en" ]]; then init_translation_db fi -gameOption="$(dialog --backtitle "Select your Doom!" \ - --clear \ - --no-tags \ - --ok-label "Single Player" \ - --cancel-label "Death Match" \ - --extra-button \ - --extra-label "co-op" \ - --help-button \ - --help-label "Exit" \ - --menu "Please select one" 0 0 0 "${doomGames[@]}" --stdout)" -buttonCode=$? +doomGames+=("manual" "Audio Manual") +while [[ -z "${gameOption}" ]] || [[ "${gameOption}" == "manual" ]]; do + gameOption="$(dialog --backtitle "Select your Doom!" \ + --clear \ + --no-tags \ + --ok-label "Single Player" \ + --cancel-label "Death Match" \ + --extra-button \ + --extra-label "co-op" \ + --help-button \ + --help-label "Exit" \ + --menu "Please select one" 0 0 0 "${doomGames[@]}" --stdout)" + buttonCode=$? + if [[ "${gameOption}" == "manual" ]]; then + audio_manual + fi +done if [[ -e "${gamePath}/DoomMetalVol7.wad" ]]; then gameOption+=" DoomMetalVol7.wad" elif [[ -e "${gamePath}/DoomMetalVol6.wad" ]]; then