#!/usr/bin/env bash
# fix_format.sh — Auto-format all GDScript files with gdformat.
# Usage: ./tools/fix_format.sh
set -euo pipefail

ROOT="$(cd "$(dirname "$0")/.." && pwd)"
cd "$ROOT"

# detect gdformat
FMT=""
if command -v gdformat &>/dev/null; then
  FMT="gdformat"
elif python -m gdtoolkit.formatter --help &>/dev/null 2>&1; then
  FMT="python -m gdtoolkit.formatter"
fi

if [[ -z "$FMT" ]]; then
  echo "ERROR: gdformat not found. Install: pip install gdtoolkit"
  exit 1
fi

echo "Formatting all .gd files in $ROOT ..."
$FMT .
echo "Done."
