···11+#!/bin/sh
22+33+if [ "$#" -lt 1 ]; then
44+ echo "Usage: $0 [--force] <EXPORT_NAME> [<GODOT_BIN>]"
55+ exit 1
66+fi
77+88+FORCE_BUILD=false
99+1010+# Check for the --force parameter
1111+if [ "$1" == "--force" ]; then
1212+ FORCE_BUILD=true
1313+ shift
1414+fi
1515+1616+EXPORT_NAME="$1"
1717+GODOT_BIN="${2:-godot}"
1818+1919+# Check if the command is available
2020+if ! command -v "$GODOT_BIN" &> /dev/null; then
2121+ echo "Error: Godot binary not found at '$GODOT_BIN'"
2222+ exit 1
2323+fi
2424+2525+# Check for uncommitted changes or untracked files in the Git workspace
2626+if [ "$FORCE_BUILD" != "true" ] && [ -n "$(git status --porcelain)" ]; then
2727+ echo "Error: There are uncommitted changes or untracked files in the Git workspace."
2828+ echo "Please commit/stash them before building. Or run the script with --force flag."
2929+ exit 1
3030+fi
3131+3232+# Export the game and redirect Godot output to a file
3333+export_game() {
3434+ local export_preset="$1"
3535+ local output_dir="$2"
3636+ local build_name="$3"
3737+ local logfile="$output_dir/build.log"
3838+3939+ # Get the current date and time
4040+ current_datetime=$(date "+%Y-%m-%d %H:%M:%S")
4141+4242+ # Get the current Git commit hash (if available)
4343+ git_commit=$(git rev-parse --short HEAD 2>/dev/null || echo "No Git commit available")
4444+4545+ # Create a log entry with date, time, and Git commit
4646+ log_entry="$current_datetime - Git commit: $git_commit"
4747+4848+ echo "Building $export_preset..."
4949+5050+ # Append the log entry to the build log file
5151+ mkdir -p "$output_dir"
5252+ touch $logfile
5353+ echo "$log_entry" > "$logfile"
5454+5555+ $GODOT_BIN --headless --export-release "$export_preset" "$output_dir/$build_name" >> $logfile 2>&1
5656+5757+ echo "$export_preset built."
5858+ echo
5959+}
6060+6161+export_game "Linux/X11" "builds/$EXPORT_NAME/linux" "$EXPORT_NAME.x86_64"
6262+export_game "macOS" "builds/$EXPORT_NAME/osx" "$EXPORT_NAME.dmg"
6363+export_game "Windows Desktop" "builds/$EXPORT_NAME/windows" "$EXPORT_NAME.exe"
6464+export_game "Web" "builds/$EXPORT_NAME/html5" "index.html"