From c87b241b29340a4287af9b5d912312da52d44122 Mon Sep 17 00:00:00 2001 From: Paul Bailey Date: Wed, 4 Nov 2026 18:12:56 +0000 Subject: [PATCH] play.sh to start the game; Godot checks shared with run_server.sh --- docs/SETUP_ON_NEW_MACHINE.md | 7 +++++++ play.sh | 12 ++++++++++++ server/run_server.sh | 32 ++------------------------------ tools/godot_env.sh | 34 ++++++++++++++++++++++++++++++++++ 4 files changed, 55 insertions(+), 30 deletions(-) create mode 100755 play.sh create mode 100644 tools/godot_env.sh diff --git a/docs/SETUP_ON_NEW_MACHINE.md b/docs/SETUP_ON_NEW_MACHINE.md index 0c7f5f7..9c051ba 100644 --- a/docs/SETUP_ON_NEW_MACHINE.md +++ b/docs/SETUP_ON_NEW_MACHINE.md @@ -25,6 +25,13 @@ godot --headless --path . --import Without it you get errors like `Could not find type "Inventory"`. `server/run_server.sh` and `tests/run_all.sh` do this for you. +## Playing +```bash +./play.sh +``` +It finds Godot (on the PATH, or `/Applications/Godot.app`; set `GODOT=` to +pick one), checks it's 4.7+, imports a fresh copy once, then opens the game. + ## 3. Running a dedicated server ```bash server/run_server.sh # settings from server.json diff --git a/play.sh b/play.sh new file mode 100755 index 0000000..3c5b9c6 --- /dev/null +++ b/play.sh @@ -0,0 +1,12 @@ +#!/bin/sh +# Starts Emberwild (the game, with its window and title screen). +# +# ./play.sh +# +# Set GODOT=/path/to/godot to use a particular Godot. Any extra arguments go +# to Godot (e.g. ./play.sh --fullscreen). Checks Godot is 4.7+ and imports a +# fresh copy once first, the same as server/run_server.sh. + +cd "$(dirname "$0")" || exit 1 +. tools/godot_env.sh +exec "$GODOT" --path . "$@" diff --git a/server/run_server.sh b/server/run_server.sh index 7cfcbe4..e574ed6 100755 --- a/server/run_server.sh +++ b/server/run_server.sh @@ -8,37 +8,9 @@ # Set GODOT=/path/to/godot to use a particular Godot. Stop it with Ctrl+C. # # Before starting it checks that Godot is 4.7 or newer, and imports a fresh -# copy of the project once (Godot's class cache lives in .godot/, which isn't -# in git, so a new clone can't run headless until it has been imported). +# copy of the project once (tools/godot_env.sh). cd "$(dirname "$0")/.." || exit 1 - -GODOT="${GODOT:-godot}" -if ! command -v "$GODOT" >/dev/null 2>&1; then - # macOS: use the app bundle if `godot` isn't on the PATH. - if [ -x /Applications/Godot.app/Contents/MacOS/Godot ]; then - GODOT=/Applications/Godot.app/Contents/MacOS/Godot - else - echo "Can't find Godot. Install 4.7.2 from https://godotengine.org/download, or set GODOT=/path/to/godot" >&2 - exit 1 - fi -fi - -version=$("$GODOT" --version 2>/dev/null | tail -n 1) -major=$(echo "$version" | cut -d. -f1) -minor=$(echo "$version" | cut -d. -f2) -if [ -z "$major" ] || [ "$major" -lt 4 ] || { [ "$major" -eq 4 ] && [ "$minor" -lt 7 ]; }; then - echo "This game needs Godot 4.7 or newer, but $GODOT is ${version:-unknown}." >&2 - echo "Download 4.7.2 from https://godotengine.org/download (or set GODOT=/path/to/a/newer/godot)" >&2 - exit 1 -fi - -if [ ! -f .godot/global_script_class_cache.cfg ]; then - echo "First run on this copy: importing the project (a few seconds)..." - if ! "$GODOT" --headless --path . --import >/dev/null 2>&1 || [ ! -f .godot/global_script_class_cache.cfg ]; then - echo "Import failed. Try: $GODOT --headless --path . --import" >&2 - exit 1 - fi -fi +. tools/godot_env.sh exec "$GODOT" --headless --path . -- --server "$@" diff --git a/tools/godot_env.sh b/tools/godot_env.sh new file mode 100644 index 0000000..7b57646 --- /dev/null +++ b/tools/godot_env.sh @@ -0,0 +1,34 @@ +# Shared by play.sh and server/run_server.sh (sourced, not run). Run from the +# project folder. Sets GODOT to a Godot 4.7+ binary and imports a fresh copy +# of the project once; exits with a message if either isn't possible. +# +# Godot's class cache lives in .godot/, which isn't in git, so a new clone +# can't run until it has been imported. + +GODOT="${GODOT:-godot}" +if ! command -v "$GODOT" >/dev/null 2>&1; then + # macOS: use the app bundle if `godot` isn't on the PATH. + if [ -x /Applications/Godot.app/Contents/MacOS/Godot ]; then + GODOT=/Applications/Godot.app/Contents/MacOS/Godot + else + echo "Can't find Godot. Install 4.7.2 from https://godotengine.org/download, or set GODOT=/path/to/godot" >&2 + exit 1 + fi +fi + +version=$("$GODOT" --version 2>/dev/null | tail -n 1) +major=$(echo "$version" | cut -d. -f1) +minor=$(echo "$version" | cut -d. -f2) +if [ -z "$major" ] || [ "$major" -lt 4 ] || { [ "$major" -eq 4 ] && [ "$minor" -lt 7 ]; }; then + echo "This game needs Godot 4.7 or newer, but $GODOT is ${version:-unknown}." >&2 + echo "Download 4.7.2 from https://godotengine.org/download (or set GODOT=/path/to/a/newer/godot)" >&2 + exit 1 +fi + +if [ ! -f .godot/global_script_class_cache.cfg ]; then + echo "First run on this copy: importing the project (a few seconds)..." + if ! "$GODOT" --headless --path . --import >/dev/null 2>&1 || [ ! -f .godot/global_script_class_cache.cfg ]; then + echo "Import failed. Try: $GODOT --headless --path . --import" >&2 + exit 1 + fi +fi