Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add colors to d2r-loot-filters #591

Merged
merged 3 commits into from
Sep 22, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 24 additions & 24 deletions core/tabs/gaming/diablo-ii/d2r-loot-filters.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@

# Check for required commands
for cmd in find curl unzip stty; do
if ! command -v "$cmd" >/dev/null 2>&1; then
printf "%s\n" "Error: $cmd is not installed."
if ! command_exists "$cmd" >/dev/null 2>&1; then
nnyyxxxx marked this conversation as resolved.
Show resolved Hide resolved
printf "%b\n" "${RED}$cmd is not installed.${RC}"
exit 1
fi
done

# Search for possible Diablo II Resurrected folder locations
printf "%s\n" "Searching for Diablo II Resurrected folders..."
printf "%b\n" "${YELLOW}Searching for Diablo II Resurrected folders...${RC}"
possible_paths=$(find "$HOME" -type d -path "*/drive_c/Program Files (x86)/Diablo II Resurrected" 2>/dev/null)

if [ -z "$possible_paths" ]; then
printf "%s\n" "Error: No Diablo II Resurrected folders found."
printf "%b\n" "${RED}No Diablo II Resurrected folders found.${RC}"
exit 1
fi

# Display possible paths and allow selection
printf "%s\n" "Possible Diablo II Resurrected folder locations:"
printf "%b\n" "Possible Diablo II Resurrected folder locations:"
paths_string=""
i=0
IFS='
Expand All @@ -35,14 +35,14 @@ total=$i
selected=0

print_menu() {
command -v clear >/dev/null 2>&1 && clear
clear
max_display=$((total < 10 ? total : 10))
start=$((selected - max_display / 2))
if [ $start -lt 0 ]; then start=0; fi
if [ $((start + max_display)) -gt $total ]; then start=$((total - max_display)); fi
if [ $start -lt 0 ]; then start=0; fi

printf "%s\n" "Please select the Diablo II: Resurrected installation path:"
printf "%b\n" "Please select the Diablo II: Resurrected installation path:"
i=0
echo "$paths_string" | tr '|' '\n' | while IFS= read -r path; do
if [ $i -ge $start ] && [ $i -lt $((start + max_display)) ]; then
Expand Down Expand Up @@ -70,12 +70,12 @@ select_path() {
stty echo

case "$key" in
$(printf '\033')A | k)
"$(printf '\033')A" | k)
if [ $selected -gt 0 ]; then
selected=$((selected - 1))
fi
;;
$(printf '\033')B | j)
"$(printf '\033')B" | j)
if [ $selected -lt $((total - 1)) ]; then
selected=$((selected + 1))
fi
Expand All @@ -87,15 +87,15 @@ select_path() {
esac
done

command -v clear >/dev/null 2>&1 && clear
clear
}

# Use the select_path function
select_path

# Validate the path
if [ ! -d "$d2r_path" ]; then
printf "%s\n" "Error: The specified path does not exist."
printf "%b\n" "${RED}The specified path does not exist.${RC}"
exit 1
fi

Expand All @@ -104,29 +104,29 @@ mods_path="$d2r_path/mods"
mkdir -p "$mods_path"

# Download the latest release
printf "%s\n" "Downloading the latest loot filter..."
printf "%b\n" "Downloading the latest loot filter..."
if ! curl -sSLo /tmp/lootfilter.zip https://github.com/ChrisTitusTech/d2r-loot-filter/releases/latest/download/lootfilter.zip; then
printf "%s\n" "Error: Failed to download the loot filter."
printf "%b\n" "${RED}Failed to download the loot filter.${RC}"
exit 1
fi

# Extract the contents to the mods folder
printf "%s\n" "Extracting loot filter to $mods_path..."
printf "%b\n" "Extracting loot filter to $mods_path..."
if ! unzip -q -o /tmp/lootfilter.zip -d "$mods_path"; then
printf "%s\n" "Error: Failed to extract the loot filter."
printf "%b\n" "${RED}Failed to extract the loot filter.${RC}"
exit 1
fi

# Clean up
rm /tmp/lootfilter.zip

printf "%s\n" "Loot filter installed successfully in $mods_path"
printf "%b\n" "${GREEN}Loot filter installed successfully in $mods_path${RC}"

printf "\nTo complete the setup, please follow these steps to add launch options in Battle.net:\n"
printf "1. Open the Battle.net launcher\n"
printf "2. Select Diablo II: Resurrected\n"
printf "3. Click the gear icon next to the 'Play' button\n"
printf "4. Select 'Game Settings'\n"
printf "5. In the 'Additional command line arguments' field, enter: -mod lootfilter -txt\n"
printf "6. Click 'Done' to save the changes\n"
printf "\nAfter completing these steps, launch Diablo II: Resurrected through Battle.net to use the loot filter.\n"
printf "%b\n" "${YELLOW}To complete the setup, please follow these steps to add launch options in Battle.net:${RC}"
printf "%b\n" "1. Open the Battle.net launcher"
printf "%b\n" "2. Select Diablo II: Resurrected"
printf "%b\n" "3. Click the gear icon next to the 'Play' button"
printf "%b\n" "4. Select 'Game Settings'"
printf "%b\n" "5. In the 'Additional command line arguments' field, enter: -mod lootfilter -txt"
printf "%b\n" "6. Click 'Done' to save the changes"
printf "%b\n" "After completing these steps, launch Diablo II: Resurrected through Battle.net to use the loot filter."