#!/bin/bash

# die on errors
set -e

COMPILED="@false@"

if [ "$COMPILED" != "true" ] ; then
  echo "You are trying to run the Severed Chains source code. Please see our installation instructions at https://legendofdragoon.org/projects/severed-chains/"
  read -p "Press enter to exit"
  exit 1;
fi

SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
cd "$SCRIPT_DIR"

if [[ $(pwd) == *":"* ]]; then
  echo "Java cannot launch with a colon (:) in the path. Please rename the directory or move Severed Chains to a different directory."
  echo "Current directory: $(pwd)"
  read -p "Press enter to exit"
  exit 1;
fi

JAVA=./jdk25/Contents/Home/bin/java

if [[ ! -f $JAVA ]]
then
  ./download-java
fi

"$JAVA" -XstartOnFirstThread -Djoml.fastmath -Djoml.sinLookup -Djoml.useMathFma --add-opens java.base/java.util=ALL-UNNAMED --add-exports java.base/jdk.internal.misc=ALL-UNNAMED --enable-native-access=ALL-UNNAMED -cp "@libs@:lod-game-@version@.jar" legend.game.Main -Xmx2G
read -p "Press enter to exit"
