#!/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/bin/java

if [[ ! -f $JAVA ]]
then
  LD_PRELOAD=${LD_PRELOAD/_32/_64} konsole --fullscreen -e /bin/bash -c './download-java'
fi

"$JAVA" -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 "lod-game-@version@.jar:@libs@" legend.game.Main -Xmx2G -ea
read -p "Press enter to exit"
