#!/bin/sh
# Install the wireBender layout where the Hydrogen 3D editor looks for
# layouts: $HOME/project/project-content/layouts/. The editor's layout
# picker lists every .json in that folder.
set -e

LAYOUT_DIR="$HOME/project/project-content/layouts"
TARGET="$LAYOUT_DIR/wireBender.json"

mkdir -p "$LAYOUT_DIR"

# Preserve local edits: if a different wireBender.json is already there
# (for example one the user re-saved from the editor), keep a backup
# beside it before overwriting with the packaged layout.
if [ -f "$TARGET" ] && ! cmp -s "$PWD/wireBender.json" "$TARGET"; then
  cp "$TARGET" "$TARGET.bak"
  echo "existing wireBender.json differed; saved a copy at $TARGET.bak"
fi

cp "$PWD/wireBender.json" "$TARGET"
echo "installed: wireBender layout at $TARGET"
echo "open it from the 3D Editor's layout picker, or ask the AI:"
echo "  \"open the wireBender layout in the 3D editor\""
