#!/usr/bin/env bash # run-map-editor.sh — launcher for sporel-module-map-editor # Usage: bash scripts/run-map-editor.sh [target_map.json] # # If a target is given, copy it into the editor's work-slot before # launching, then copy the edited result back to the target after exit. # Without a target, edits the in-place work.map.json. set -e SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" EDITOR_DIR="$(cd "$SCRIPT_DIR/.." && pwd)" WORK_SLOT="$EDITOR_DIR/maps/work.map.json" SPOREL_ROOT="$(cd "$EDITOR_DIR/../.." && pwd)" SPOREL_BIN="${SPOREL_BIN:-$SPOREL_ROOT/sporel-engine/build/Sporel.exe}" if [ ! -x "$SPOREL_BIN" ]; then echo "error: Sporel binary not found at $SPOREL_BIN" >&2 echo "set SPOREL_BIN env-var or build the engine first" >&2 exit 1 fi TARGET="${1:-}" if [ -n "$TARGET" ]; then if [ ! -f "$TARGET" ]; then echo "error: target map not found: $TARGET" >&2 exit 1 fi echo "copying $TARGET -> $WORK_SLOT" cp "$TARGET" "$WORK_SLOT" fi echo "launching map-editor on $WORK_SLOT" export SPOREL_LIBS_DIR="$SPOREL_ROOT/sporel-libs" export SPOREL_MODULES_DIR="$SPOREL_ROOT/sporel-modules" export SPOREL_MODULE=map-editor LOG_FILE="${SPOREL_LOG:-/tmp/sporel-last-run.log}" set +e "$SPOREL_BIN" "$@" 2> >(tee "$LOG_FILE" >&2) rc=$? set -e if [ -n "$TARGET" ] && [ $rc -eq 0 ]; then echo "copying $WORK_SLOT -> $TARGET" cp "$WORK_SLOT" "$TARGET" fi echo "done (exit $rc)" exit $rc