crossmate

A collaborative crossword app for iOS
Log | Files | Refs | LICENSE

commit 78278785c9acfd1ff3889f04946cece7a8fd3162
parent 544ca1e8bda386448aeb42aeecc2a20c1f80393c
Author: Michael Camilleri <[email protected]>
Date:   Tue, 19 May 2026 07:15:47 +0900

Add bundle-puzzles.sh to renumber picks into the app bundle

A new Scripts/bundle-puzzles.sh promotes a curated batch into Puzzles/Bundled,
the directory whose Crossmate-NNNN.xd puzzles ship as app resources. It reads
the .xd files from Crossmake/Picked (source and destination are overridable
positionally), takes them in sorted filename order, and copies each into
Puzzles/Bundled under the next number in sequence — continuing from the highest
existing Crossmate-NNNN.xd in the destination, not the Picked numbers, and
zero-padded to four digits to match the existing convention.

While copying, the first Title: line of each puzzle is rewritten to
'Crossmate #<n>' with leading zeros stripped (awk, every other line passed
through untouched). The script is purely additive: assigned numbers are
strictly above the current maximum, so existing bundled puzzles are never
overwritten and a re-run simply extends the sequence.

Co-Authored-By: Claude Opus 4.7 <[email protected]>

Diffstat:
AScripts/bundle-puzzles.sh | 47+++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 47 insertions(+), 0 deletions(-)

diff --git a/Scripts/bundle-puzzles.sh b/Scripts/bundle-puzzles.sh @@ -0,0 +1,47 @@ +#!/bin/bash +set -euo pipefail + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +REPO_DIR="$(cd "${SCRIPT_DIR}/.." && pwd)" + +SOURCE_DIR="${1:-${REPO_DIR}/Crossmake/Picked}" +DEST_DIR="${2:-${REPO_DIR}/Puzzles/Bundled}" + +if [[ ! -d "$SOURCE_DIR" ]]; then + echo "Source directory not found: $SOURCE_DIR" >&2 + exit 1 +fi + +source_files=("$SOURCE_DIR"/*.xd) +if [[ ! -e "${source_files[0]}" ]]; then + echo "No .xd puzzles found in $SOURCE_DIR" >&2 + exit 1 +fi + +mkdir -p "$DEST_DIR" + +highest=0 +for path in "$DEST_DIR"/Crossmate-*.xd; do + [[ -e "$path" ]] || continue + filename="${path##*/}" + [[ "$filename" =~ ^Crossmate-([0-9]+)\.xd$ ]] || continue + number=$((10#${BASH_REMATCH[1]})) + if ((number > highest)); then + highest="$number" + fi +done + +next=$((highest + 1)) +first="$next" + +for src in "${source_files[@]}"; do + printf -v dest_name "Crossmate-%04d.xd" "$next" + dest="${DEST_DIR}/${dest_name}" + awk -v title="Title: Crossmate #${next}" \ + '!retitled && /^Title:/ { print title; retitled = 1; next } { print }' \ + "$src" >"$dest" + echo "Bundled ${src##*/} -> ${dest_name} (Title: Crossmate #${next})" + next=$((next + 1)) +done + +echo "Bundled $((next - first)) puzzle(s) into ${DEST_DIR}; numbers ${first}-$((next - 1))." >&2