diff --git a/.scripts/FreeDoom.sh b/.scripts/FreeDoom.sh index 6054635..1ea4097 100755 --- a/.scripts/FreeDoom.sh +++ b/.scripts/FreeDoom.sh @@ -10,8 +10,12 @@ export gamePath=~/.local/games/doom # Path where doom wads are stored export doomPath="$(find /usr/share -type d -name "doom" 2> /dev/null | head -1)" -# Path to gzdoom. -export gzdoom="$(command -v gzdoom)" +# Path to gzdoom or yadoom. +if [[ -x "yadoom" ]]; then + export gzdoom=$(readlink -f "yadoom") +else + export gzdoom="$(command -v gzdoom)" +fi # Version of the accessibility mod export tobyVersion="7-5" diff --git a/.scripts/yadoom b/.scripts/yadoom new file mode 100755 index 0000000..0d4a628 --- /dev/null +++ b/.scripts/yadoom @@ -0,0 +1,85 @@ +#!/usr/bin/env bash + + +help() { + echo "${0##*/}" + echo "Released under the terms of the GPL license." + echo -e "This is a Stormux project: https://stormux.org\n" + echo -e "Usage:\n" + echo "With no arguments, open ${0##*/}." + for i in "${!command[@]}" ; do + echo "-${i/:/ }: ${command[${i}]}" + done | sort + exit 0 +} + +# Function to check if a file is an IWAD +is_iwad() { + local file="$1" + if [[ -f "$file" ]]; then + # Extract the first four bytes and check if they match the IWAD signature + if hexdump -n 4 -e '4/1 "%02X"' "$file" | grep -q '^49574144$'; then + return 0 + else + return 1 + fi + fi + return 1 +} + + +declare -A command=( + [c:]="gzdoom configuration file to be used. Default: ${XDG_CONFIG_HOME:-$HOME/.config}/gzdoom/gzdoom.ini" + [h]="This help screen." +) +configFile="${configfile:-${XDG_CONFIG_HOME:-$HOME/.config}/gzdoom/gzdoom.ini}" + + +# Convert the keys of the associative array to a format usable by getopts +args="${!command[*]}" +args="${args//[[:space:]]/}" +while getopts "${args}" i 2> /dev/null ; do + case "$i" in + c) configFile="${OPTARG}" ;; + h) help ;; + *) continue ;; + esac +done + +# Extract the Path= lines from the [IWADSearch.Directories] section +mapfile -t wadPaths < <(sed -n "/^\[IWADSearch.Directories\]/,/^\[/{/Path=/p;}" "$configFile" | cut -d '=' -f 2) +declare -a wadList +# Loop through each path in wadPaths and find WAD files +for i in "${wadPaths[@]}"; do + # Use find and append results to wadList array + if [[ -d "$i" ]]; then + while IFS= read -r -d $'\0' wad; do + is_iwad "$wad" && wadList+=("$wad") + done < <(find "$i" -maxdepth 1 -type f -iname '*.wad' -print0) + fi +done + +# Set up the menu +declare -a wadMenu +for path in "${wadList[@]}" ; do + title="${path##*/}" + title="${title%.*}" + wadMenu+=("${title}" "${path}") +done +# Run yad to display the dialog +iwad=$(yad --list \ + --title="Yadoom" \ + --text="Select an Iwad" \ + --column="Iwad" \ + --column="Path" \ + --button="Launch:0" \ + --button="Close:1" \ + --hide-column=2 \ + --search-column=1 \ + --skip-taskbar \ + "${wadMenu[@]}") +yadCode="$?" +[[ ${yadCode} -eq 1 ]] && exit 0 +iwad="${iwad#*|}" +iwad="${iwad%|}" +gzdoom "$@" -iwad "${iwad}"