#!/usr/bin/env bash
# AppImage entry point: starts the Rust launcher. The launcher picks the game folder, runs the game
# and handles --play (the game without a window, for Steam and shortcuts).
# Usage: spartanport-x86_64.AppImage [--play]
set -euo pipefail
here=$(dirname -- "$(readlink -f -- "$0")")
share=$here/usr/share/spartanport

export LD_LIBRARY_PATH="$here/usr/lib${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"
export SPARTAN_DATA_DIR=${SPARTAN_DATA_DIR:-${XDG_DATA_HOME:-$HOME/.local/share}/spartanport}
export SPARTAN_USER_DIR=${SPARTAN_USER_DIR:-$SPARTAN_DATA_DIR/user}
mkdir -p "$SPARTAN_DATA_DIR" "$SPARTAN_USER_DIR"

cd -- "$share"
exec "$share/spartanport-launcher" "$@"
