#!/bin/bash
set -e
SCRIPT_PATH=$(readlink -f "${BASH_SOURCE:-$0}")
SCRIPT_DIR=$(dirname "$SCRIPT_PATH")
exec_spacetime() {
# args: target, environment, build root
echo "[*] Running configure command: 'python3 $SCRIPT_DIR/spacetime/spacetime.py $1 $2 $SCRIPT_DIR'"
python3 "$SCRIPT_DIR/spacetime/spacetime.py" "$1" "$2" "$SCRIPT_DIR"
}
exec_ninja() {
# args: target
echo "[*] Running build command: 'ninja -C $SCRIPT_DIR $1'"
ninja -C "$SCRIPT_DIR" "$1"
}
sub_help() {
echo "Spacetime - StarKingdoms build utility"
echo "Spacetime is a small utility program to generate Ninja build manifests for compiling StarKingdoms."
echo "Available targets:"
echo " help - Show this help screen" # done
echo " run_http - Compile the client and run a development http server for testing it"
echo " run_http_prod - Compile the client in production mode and run a development http server for testing it"
echo " run_server (default) - Compile and run the game server"
echo " build_client_bundle - Compile an optimized WebAssembly client bundle"
echo " build_client_bundle_prod - Compile an optimized WebAssembly client bundle using textures-fast"
echo " install_tooling - Install the compilation utilities required for compiling StarKingdoms" # done
echo " build_assets - Compile spritesheets in all three texture sizes for textures-fast" # done
echo " build_assets_full - Compile spritesheets in full size for textures-fast" # done
echo " build_assets_375 - Commpile 37.5% spritesheets for textures-fast" # done
echo " build_assets_125 - Compile 12.5% spritesheets for textures-fast" # done
echo " clean - Remove all generated files"
}
check_install_cargo() {
echo "[*] Checking for $1"
if ! command -v "$1" &> /dev/null
then
echo "[+] $1 was not found, installing via Cargo..."
cargo install "$2" $3
fi
}
check() {
echo "[*] Checking for $1"
if ! command -v "$1" &> /dev/null
then
echo "[x] $1 was not found but is required for the build process to continue. Install it with your system package manager, or, if supported, 'st install_tooling'"
exit 1
fi
}
check_all() {
check wasm-pack
check sheep
check inkscape
}
sub_install_tooling() {
check_install_cargo wasm-pack wasm-pack --no-default-features
check_install_cargo sheep sheep_cli
check inkscape
echo "[*] All required tools are installed"
}
sub_build_client_bundle() {
check_all
exec_spacetime client dev "$SCRIPT_DIR"
exec_ninja client
}
sub_build_assets() {
check_all
exec_spacetime asset dev "$SCRIPT_DIR"
exec_ninja asset
}
sub_build_assets_full() {
check_all
exec_spacetime asset dev "$SCRIPT_DIR"
exec_ninja asset-full
}
sub_build_assets_375() {
check_all
exec_spacetime asset dev "$SCRIPT_DIR"
exec_ninja asset-375
}
sub_build_assets_125() {
check_all
exec_spacetime asset dev "$SCRIPT_DIR"
exec_ninja asset-125
}
subcommand=$1
case $subcommand in
"" | "-h" | "--help" | "help")
sub_help
;;
*)
echo "[*] Running build command $subcommand"
shift
sub_${subcommand} $@
if [ $? = 127 ]; then
echo "Error: '$subcommand' is not a known subcommand." >&2
echo " Run 'st --help' for a list of known subcommands." >&2
exit 1
fi
;;
esac