#!/bin/sh
PROG_DIR=$(dirname "$0")/easyrpg
cd ${PROG_DIR}

SAVE="saves"

if [ -f "$1" ]; then
	GAME=$1
	GAMEDIR=$(dirname "${GAME}")
	GAMENAME=$(basename "${GAME}")
	SAVE="saves/${GAMENAME%.*}"

	# new games will create "saves" sub-folder in the games folder (e.g. /Roms/EASYRPG/saves/)
	if [ ! -d "$SAVE" ]; then
		SAVE="$GAMEDIR/$SAVE"
	fi

	mkdir -p "${SAVE}"
fi

HOME=${PROG_DIR} \
LD_LIBRARY_PATH="$LD_LIBRARY_PATH":"${PROG_DIR}/libs" \
RPG2K_RTP_PATH="${PROG_DIR}/rtp/rtp2k" \
RPG2K3_RTP_PATH="${PROG_DIR}/rtp/rtp2k3" \
./easyrpg-player -c config --save-path "${SAVE}" --project-path "${GAME}" &> log.txt

sync
