- CardCatalog: one list of card kinds for the palette, right-click New card and new-card names; Dice table and Deck are their own items. - LeftDock holds the palette and List view in the shared dock tab style. - Play greys the palette under a Switch to Build notice (replaces the greyed + Card button); + Card menu removed; Card palette button in Build. - Templates dropped from the palette land where they are let go. - Phones: + opens the palette full screen. - docs/SHEETS.md: the Sheets and unified editor plan. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
304 lines
11 KiB
GDScript
304 lines
11 KiB
GDScript
class_name MainCli
|
|
extends RefCounted
|
|
## Main's command-line flags, used for screenshots and checks (see
|
|
## docs/DESIGN.md §5). Only automation needs this file.
|
|
|
|
var m: Main
|
|
## The group, template and inspector flags (MainCliBuild).
|
|
var _build: MainCliBuild
|
|
## The --perf timings (MainCliPerf).
|
|
var _perf: MainCliPerf
|
|
|
|
|
|
func _init(p_main: Main) -> void:
|
|
m = p_main
|
|
_build = MainCliBuild.new(p_main)
|
|
_perf = MainCliPerf.new(p_main)
|
|
|
|
|
|
# ---------- Command line (used for screenshots and checks) ----------
|
|
# godot --path . -- --screenshot=/tmp/shot.png [--build] [--expand-all] [--collapse-all]
|
|
# [--roll=<table id>] [--fast] [--shot-delay=<seconds>]
|
|
# [--board=<collection.json>] (with --sample/--screenshot only: show that board instead)
|
|
# [--tray=variables] [--hover=<x>,<y>] [--details=<table id>] [--pipe=<pipe key>]
|
|
|
|
static func _arg_value(args: PackedStringArray, name: String) -> String:
|
|
for a in args:
|
|
if a.begins_with(name + "="):
|
|
return a.substr(name.length() + 1)
|
|
return ""
|
|
|
|
|
|
func _run_cli(args: PackedStringArray) -> void:
|
|
var board_file := _arg_value(args, "--board")
|
|
if board_file != "" and not m._saving_enabled:
|
|
await _load_board_file(board_file)
|
|
if args.has("--build"):
|
|
m.set_mode(Main.Mode.BUILD)
|
|
if args.has("--expand-all"):
|
|
m.set_all_collapsed(false)
|
|
if args.has("--collapse-all"):
|
|
m.set_all_collapsed(true)
|
|
_run_shell_cli(args)
|
|
_run_logic_cli(args)
|
|
await _build.run_group_cli(args)
|
|
var roll := _arg_value(args, "--roll")
|
|
if roll != "":
|
|
m.start_roll(roll, args.has("--fast"))
|
|
_run_cli_extras(args)
|
|
_run_test_board_cli(args)
|
|
var shot := _arg_value(args, "--screenshot")
|
|
if shot == "":
|
|
return
|
|
var delay := _arg_value(args, "--shot-delay")
|
|
if args.has("--fit") or _arg_value(args, "--view") != "":
|
|
# Let the tray settle first (it can change the board's size).
|
|
await m.get_tree().process_frame
|
|
await m.get_tree().process_frame
|
|
if args.has("--fit"):
|
|
m.board.fit()
|
|
_apply_view_flag(args)
|
|
await m.get_tree().create_timer(delay.to_float() if delay != "" else (2.5 if roll != "" else 0.8)).timeout
|
|
var img := m.get_viewport().get_texture().get_image()
|
|
img.save_png(shot)
|
|
print("Saved screenshot to ", shot)
|
|
m.get_tree().quit()
|
|
|
|
|
|
# ----- Extra screenshot flags -----
|
|
# --open-settings=<table id> open the settings dialog
|
|
# --demo-import=<file> show the import report for a file (nothing is saved)
|
|
# --demo-endless pipe the first two tables into each other
|
|
# --menu=board|collections|view|help|zoom|add|card pop up a menu (card: the
|
|
# first card's ⋯ menu, in Build)
|
|
# --help[=<topic>] open the Help window
|
|
|
|
func _run_shell_cli(args: PackedStringArray) -> void:
|
|
var tid := _arg_value(args, "--open-settings")
|
|
if tid != "":
|
|
m.open_table_settings(tid)
|
|
var file := _arg_value(args, "--demo-import")
|
|
if file != "":
|
|
var text := FileAccess.get_file_as_string(file)
|
|
var r := IoMenu.parse_import(text, IoMenu.detect_format(file, text))
|
|
m._add_modal(IoMenu.report_dialog("Imported “%s”" % file.get_file().get_basename(), r))
|
|
if args.has("--demo-endless") and m.data.tables.size() >= 2:
|
|
var a := m.data.tables[0]
|
|
var b := m.data.tables[1]
|
|
for e in a.entries:
|
|
e.pipes = [b.id] as Array[String]
|
|
for e in b.entries:
|
|
e.pipes = [a.id] as Array[String]
|
|
m._rebuild_cards()
|
|
m.mark_dirty()
|
|
var menu := _arg_value(args, "--menu")
|
|
if menu == "board":
|
|
m.top_bar._board_menu.show_popup()
|
|
elif menu == "collections":
|
|
m.top_bar._switcher.show_popup()
|
|
elif menu == "view":
|
|
m.top_bar.view_menu.show_popup()
|
|
elif menu == "help":
|
|
m.top_bar.help_menu.show_popup()
|
|
elif menu == "zoom":
|
|
m.top_bar.zoom.menu.show_popup()
|
|
elif menu == "card":
|
|
# The first card's ⋯ menu (Build mode).
|
|
await m.get_tree().process_frame
|
|
var card := m.card_for(m.data.tables[0].id)
|
|
var more := card.find_children("*", "MenuButton", true, false) if card else []
|
|
if not more.is_empty():
|
|
(more[0] as MenuButton).show_popup()
|
|
if args.has("--welcome"):
|
|
WelcomeDialog.open(m)
|
|
if args.has("--help") or _arg_value(args, "--help") != "":
|
|
m.top_bar.help_menu.open(_arg_value(args, "--help"))
|
|
if menu == "add":
|
|
# The Build tools were only just shown; let them lay out first.
|
|
await m.get_tree().process_frame
|
|
m.left_dock.show_tab(LeftDock.CARDS)
|
|
|
|
|
|
# ----- Logic-card screenshot flags -----
|
|
# --answers=<a>|<b>|… answer the first questions automatically, in order
|
|
# (an option index or -1 for a pick, a number, or text);
|
|
# later questions open the pop-up
|
|
# --demo-long=<n> add a table that pipes into itself n times, and fast-roll it
|
|
# --confirm-reset open the Variables tab's "Reset all…" confirmation
|
|
|
|
func _run_logic_cli(args: PackedStringArray) -> void:
|
|
var answers := _arg_value(args, "--answers")
|
|
if answers != "":
|
|
var queue: Array = Array(answers.split("|"))
|
|
m.prompt_hook = func(req: Dictionary) -> Variant:
|
|
if queue.is_empty():
|
|
return await m.rolling._ask_player(req)
|
|
var a := str(queue.pop_front())
|
|
return a if str(req.get("kind", "")) == "text" else a.to_int()
|
|
var n := _arg_value(args, "--demo-long").to_int()
|
|
if n > 0:
|
|
var head := RollTable.create(RollTable.KIND_ROLL, "long_start", "Long chain")
|
|
head.entries.resize(1)
|
|
head.entries[0].text = "Off we go"
|
|
head.entries[0].effects = "@k = 0"
|
|
head.entries[0].add_pipe("long_link")
|
|
var link := RollTable.create(RollTable.KIND_ROLL, "long_link", "Link")
|
|
link.entries.resize(1)
|
|
link.entries[0].text = "Link {@k}"
|
|
link.entries[0].effects = "@k += 1"
|
|
link.entries[0].add_pipe("long_link", "@k < %d" % n)
|
|
var y := 40.0
|
|
for t in m.data.tables:
|
|
y = maxf(y, t.position.y + 80.0)
|
|
head.position = Vector2(40, y + 400)
|
|
link.position = Vector2(360, y + 400)
|
|
m.data.tables.append(head)
|
|
m.data.tables.append(link)
|
|
m._rebuild_cards()
|
|
m.start_roll("long_start", true)
|
|
if args.has("--confirm-reset"):
|
|
m.tray.set_side(ResultTray.Side.VARIABLES)
|
|
m.tray._vars.confirm_reset_all()
|
|
|
|
|
|
# --clear-result empty the tray (the board stays lit)
|
|
# --view=<x>,<y>[,<zoom>] centre the view on a world point (after Fit)
|
|
|
|
func _apply_view_flag(args: PackedStringArray) -> void:
|
|
var v := _arg_value(args, "--view")
|
|
if v == "":
|
|
return
|
|
var parts := v.split(",")
|
|
if parts.size() >= 3:
|
|
m.board.set_zoom(parts[2].to_float())
|
|
var p := Vector2(parts[0].to_float(), parts[1].to_float())
|
|
m.board.world.position = m.board.size / 2.0 - p * m.board.zoom
|
|
|
|
|
|
# ---------- Command line extras ----------
|
|
|
|
## Shows a collection file instead of the sample (screenshots only; nothing is saved).
|
|
func _load_board_file(path: String) -> void:
|
|
var text := FileAccess.get_file_as_string(path)
|
|
if text == "" or not m.data.load_json(text):
|
|
push_warning("Couldn't load board file %s" % path)
|
|
return
|
|
m.rolling._token += 1
|
|
m.rolling.cancel_choice()
|
|
m.top_bar._switcher.refresh()
|
|
m._rebuild_cards()
|
|
m.rolling._seed_session()
|
|
await m.get_tree().process_frame
|
|
await m.get_tree().process_frame
|
|
m.board.fit()
|
|
|
|
|
|
func _run_cli_extras(args: PackedStringArray) -> void:
|
|
if args.has("--perf"):
|
|
_perf.run_perf()
|
|
await _run_undo_cli(args)
|
|
_run_nav_cli(args)
|
|
if args.has("--clear-result"):
|
|
# Keeps the board lit but empties the tray (a tall sheet result can fill it).
|
|
m.current = {}
|
|
m.tray.render()
|
|
if _arg_value(args, "--tray") == "variables":
|
|
m.tray.set_side(ResultTray.Side.VARIABLES)
|
|
var pipe := _arg_value(args, "--pipe")
|
|
if pipe != "":
|
|
m.open_pipe_options(pipe, Vector2(m.size.x * 0.45, m.size.y * 0.3))
|
|
await _build.run_inspector_cli(args)
|
|
var hover := _arg_value(args, "--hover")
|
|
if hover.contains(","):
|
|
# Synthetic mouse move, to check hover pop-ups in screenshots.
|
|
await m.get_tree().create_timer(0.3).timeout
|
|
var ev := InputEventMouseMotion.new()
|
|
ev.position = Vector2(hover.get_slice(",", 0).to_float(), hover.get_slice(",", 1).to_float())
|
|
ev.global_position = ev.position
|
|
m.get_viewport().notification(Control.NOTIFICATION_VP_MOUSE_ENTER)
|
|
m.get_viewport().push_input(ev)
|
|
var det := _arg_value(args, "--details")
|
|
var card := m.card_for(det)
|
|
if card:
|
|
await m.get_tree().process_frame
|
|
m.details().show_table(card, det)
|
|
m.details().pin(card.get_global_rect().position + Vector2(60, 46))
|
|
|
|
|
|
# --test-board open the Test board dialog (shows the last report if any)
|
|
# --test-board-run=<runs> ... and start a test with that many runs (100, 500 or 1000)
|
|
func _run_test_board_cli(args: PackedStringArray) -> void:
|
|
var n := _arg_value(args, "--test-board-run")
|
|
if not args.has("--test-board") and n == "":
|
|
return
|
|
m.set_mode(Main.Mode.BUILD)
|
|
var d := TestBoardDialog.new(m)
|
|
m._add_modal(d)
|
|
if n != "":
|
|
d.runs = n.to_int()
|
|
d.run_test()
|
|
|
|
|
|
# ----- Navigation screenshot flags -----
|
|
# --search=<text> open the search panel with that query
|
|
# --focus=<table id>[:<entry id>] jump to a card (and result)
|
|
# --minimap / --no-minimap show or hide the overview
|
|
# --pack Build ▸ Arrange ▸ Pack collapsed groups
|
|
# --perf print load and frame timings, then quit
|
|
# --list, --book show List view, the Book
|
|
# --demo=KEY open a Help demo spread (DemoSpreads)
|
|
|
|
func _run_nav_cli(args: PackedStringArray) -> void:
|
|
if args.has("--minimap"):
|
|
m.nav.set_minimap_visible(true)
|
|
if args.has("--no-minimap"):
|
|
m.nav.set_minimap_visible(false)
|
|
var demo := _arg_value(args, "--demo")
|
|
if demo != "":
|
|
m.demo.open(demo)
|
|
if args.has("--book"):
|
|
m.book.set_shown(true)
|
|
if args.has("--list"):
|
|
m.list_view.set_shown(true)
|
|
if args.has("--pack"):
|
|
await m.nav.pack_collapsed_groups()
|
|
var f := _arg_value(args, "--focus")
|
|
if f != "":
|
|
await m.get_tree().process_frame
|
|
m.focus_table(f.get_slice(":", 0), f.get_slice(":", 1) if f.contains(":") else "")
|
|
var q := _arg_value(args, "--search")
|
|
if q != "":
|
|
await m.get_tree().process_frame
|
|
var p := m.nav.open_search()
|
|
p.field.text = q
|
|
p.refresh()
|
|
|
|
|
|
# ----- Undo screenshot flags -----
|
|
# --undo-demo=<table id> delete that table (or the last one), then undo: the toast says so
|
|
# --undo-tooltip make an edit, then hover the Undo button so its tooltip shows
|
|
|
|
func _run_undo_cli(args: PackedStringArray) -> void:
|
|
var demo := _arg_value(args, "--undo-demo")
|
|
if args.has("--undo-demo") or demo != "":
|
|
m.set_mode(Main.Mode.BUILD)
|
|
var t: RollTable = m.data.get_table(demo) if demo != "" else (m.data.tables.back() if not m.data.tables.is_empty() else null)
|
|
if t:
|
|
m.delete_table(t.id)
|
|
await m.get_tree().process_frame
|
|
m.undo_redo.undo()
|
|
if args.has("--undo-tooltip"):
|
|
m.set_mode(Main.Mode.BUILD)
|
|
if not m.data.tables.is_empty():
|
|
m.delete_table(m.data.tables.back().id)
|
|
m.top_bar._toast.hide()
|
|
for i in 3:
|
|
await m.get_tree().process_frame
|
|
var at := m.undo_redo._undo_button.get_global_rect().get_center()
|
|
m.get_viewport().notification(Control.NOTIFICATION_VP_MOUSE_ENTER)
|
|
for i in 2:
|
|
var ev := InputEventMouseMotion.new()
|
|
ev.position = at + Vector2(i, 0)
|
|
ev.global_position = ev.position
|
|
m.get_viewport().push_input(ev)
|
|
await m.get_tree().process_frame
|