#!/bin/sh

# Configure soundfonts if not already configured
if [ -z "$SDL_SOUNDFONTS" ]; then
  DEFAULT_SOUNDFONT="/usr/share/soundfonts/default.sf2"
  if [ -f "$DEFAULT_SOUNDFONT" ]; then
    # Use default soundfont since it exists
    export SDL_SOUNDFONTS="$DEFAULT_SOUNDFONT"
  else
    # Use first available soundfont
    export SDL_SOUNDFONTS="$(find /usr/share/soundfonts -type f,l -print -quit 2> /dev/null)"
  fi
fi

# Run program in correct directory so it can find it's resources
cd /usr/lib/spacecadetpinball
exec ./SpaceCadetPinball "$@"
