#!/bin/bash

version=2.1.4

adoptium_installer || exit 1
install_packages temurin-17-jre || exit 1

mkdir -p ~/.local/bin
wget -O ~/.local/bin/ShatteredPD-Desktop.jar https://github.com/00-Evan/shattered-pixel-dungeon/releases/download/v${version}/ShatteredPD-v${version}-Java.jar || error "Could not download game!"


case "$arch" in
  "64") path=/usr/lib/jvm/temurin-17-jre-arm64/bin/java ;;
  "32") path=/usr/lib/jvm/temurin-17-jre-armhf/bin/java ;;
  *) error "Failed to detect OS CPU architecture! Something is very wrong." ;;
esac

echo "[Desktop Entry]
Encoding=UTF-8
Name=Shattered Pixel Dungeon
Exec=$path -jar $HOME/.local/bin/ShatteredPD-Desktop.jar
Terminal=false
Icon=$(dirname "$0")/icon-64.png
Type=Application
Categories=Application;Game
Comment=Roguelike Dungeon Crawler RPG with pixel art graphics." > ~/.local/share/applications/shatteredpd.desktop || error "Could not create .desktop file!"
