From 0f57a323d5c45677e528502ab5355c3e85694f01 Mon Sep 17 00:00:00 2001 From: Nayan Sawyer <33187059+opus-tango@users.noreply.github.com> Date: Thu, 2 Apr 2026 19:25:59 -0400 Subject: [PATCH] add reading files --- tfc-forge-macro/main.py | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/tfc-forge-macro/main.py b/tfc-forge-macro/main.py index e541a7a..e009513 100644 --- a/tfc-forge-macro/main.py +++ b/tfc-forge-macro/main.py @@ -2,6 +2,7 @@ from __future__ import annotations import argparse import json +import re import sys import time from pathlib import Path @@ -57,6 +58,11 @@ def resolve_coord_map(payload: dict[str, Any], name: str) -> dict[str, Any]: raise KeyError(f"Unknown slot {name!r} (not in anvil or recipe).") +def parse_slots_file(content: str) -> list[str]: + """Split slot names on commas, spaces, tabs, and newlines; empty tokens are dropped.""" + return [t for t in re.split(r"[\s,]+", content.strip()) if t] + + def parse_slot_token(token: str) -> tuple[str, bool]: """Underscore prefix means hold Shift for that click (_i2 -> i2 with shift).""" if token.startswith("_"): @@ -159,11 +165,25 @@ def main() -> None: default=None, help=f"Path to coords.json (default: {DEFAULT_COORDS_PATH}).", ) + parser.add_argument( + "-f", + "--file", + type=Path, + default=None, + metavar="PATH", + help=( + "Read slot names from this file (commas, spaces, and newlines separate tokens). " + "When set, positional SLOT arguments are ignored." + ), + ) parser.add_argument( "slots", nargs="*", metavar="SLOT", - help="Slot names from coords.json, e.g. M D P G i9 h6. Use _NAME for shift-click.", + help=( + "Slot names from coords.json, e.g. M D P G i9 h6. Use _NAME for shift-click. " + "Ignored when --file is set." + ), ) args = parser.parse_args() path = args.coords_file.expanduser().resolve() if args.coords_file else DEFAULT_COORDS_PATH @@ -172,7 +192,17 @@ def main() -> None: print(f"Missing coords file: {path}", file=sys.stderr) sys.exit(1) - slots = args.slots if args.slots else DEFAULT_TEST_SLOTS + if args.file is not None: + slots_path = args.file.expanduser().resolve() + if not slots_path.is_file(): + print(f"Missing slots file: {slots_path}", file=sys.stderr) + sys.exit(1) + slots = parse_slots_file(slots_path.read_text(encoding="utf-8")) + if not slots: + print("Slots file is empty or contains no slot names.", file=sys.stderr) + sys.exit(1) + else: + slots = args.slots if args.slots else DEFAULT_TEST_SLOTS time.sleep(args.start_delay / 1000)