TableTower/ui/main_cli_sheets.gd

86 lines
3.9 KiB
GDScript3
Raw Normal View History

class_name MainCliSheets
extends RefCounted
## The sheet command-line flags, for screenshots and checks (see
## docs/DESIGN.md §5). MainCli uses it; only automation needs this file.
# --sheet-demo the example sheet in the Sheets screen
# [--sheet-build] [--sheet-tab=N] [--sheet-select=TITLE] [--sheet-lore]
# [--sheet-edit=TITLE] [--sheet-lore-index] (the Lore Index beside the sheet)
# --sheet-node the example sheet placed on the spread
# --new-sheet the New sheet dialog, with a template
var m: Main
func _init(p_main: Main) -> void:
m = p_main
func run(args: PackedStringArray) -> void:
if args.has("--sheet-demo"):
# The example sheet in the Sheets screen; --sheet-build opens it in Build.
m.screens.show(MainScreens.SHEETS)
var sheet := SheetDemo.create()
m.screens.sheets.store.save(sheet)
m.screens.sheets.open_doc(sheet)
if args.has("--sheet-build"):
m.screens.sheets.editor.set_mode(Main.Mode.BUILD)
var sheet_tab := MainCli._arg_value(args, "--sheet-tab")
if sheet_tab != "":
m.screens.sheets.editor.show_tab(str(sheet.tabs[clampi(sheet_tab.to_int(), 0, sheet.tabs.size() - 1)]["id"]))
var select := MainCli._arg_value(args, "--sheet-select")
for tab in sheet.tabs:
for b: SheetBox in tab["boxes"]:
if select != "" and b.title == select:
m.screens.sheets.editor.select(b.id) if args.has("--sheet-build") else m.screens.sheets.editor.show_details(b.id, 0)
if args.has("--sheet-lore"):
# A Lore Entry linked from the Oath box, open in the side panel.
var page := m.data.add_page("Abbey of Vel", "A ruined abbey on the moor. The monks left in a hurry; the bell still rings at night.")
var oath := box_titled(m.screens.sheets.editor.doc, "Oath")
oath.value = str(oath.value).replace("the abbey", "the [url=lore:%s]abbey[/url]" % page.id)
m.screens.sheets.editor.refresh()
m.screens.sheets.editor.details.open_lore(page.id)
if args.has("--sheet-lore-index"):
show_lore_items(m.screens.sheets.editor)
var edit_title := MainCli._arg_value(args, "--sheet-edit")
if edit_title != "":
# Opens that text box for editing, with its toolbar.
var view: SheetBoxView = m.screens.sheets.editor.canvas.views.get(box_titled(m.screens.sheets.editor.doc, edit_title).id)
var click := InputEventMouseButton.new()
click.button_index = MOUSE_BUTTON_LEFT
click.pressed = true
(view.find_child("Shown", true, false) as Control).gui_input.emit(click)
if args.has("--sheet-node"):
# The example sheet placed on the spread, as a Sheet card.
var placed := SheetDemo.create()
m.screens.sheets.store.save(placed)
m.sheet_links.add_card(placed.id, m.board.screen_to_world(m.board.size * Vector2(0.62, 0.3)))
if args.has("--new-sheet"):
m.screens.show(MainScreens.SHEETS)
m.screens.sheets.store.save_as_template(SheetDemo.create(), "OSR Character")
m.screens.sheets.refresh()
m.screens.sheets.open_new_sheet()
## The box called `title` on any tab of `doc` (CLI flags name boxes by title).
static func box_titled(doc: SheetDoc, title: String) -> SheetBox:
for tab in doc.tabs:
for box: SheetBox in tab["boxes"]:
if box.title == title:
return box
return null
## --sheet-lore-index: the Lore Index beside the sheet on My library, with an
## entry that has an item sheet, dropped linked into the Inventory and copied into Talents.
func show_lore_items(ed: SheetEditor) -> void:
ed.set_lore_shown(true)
var lore := ed.lore_dock.lore
lore.set_level(LoreLevel.LIBRARY)
var blade := lore.level.add_page("[b]Ashen Blade[/b]", "Burns what it cuts. Three charges; a spent charge returns at dawn.")
blade.name = "Ashen Blade"
lore.level.edit(func() -> void: SheetItems.make_sheet(ed.screen.store, blade))
SheetLoreDrop.add(ed, box_titled(ed.doc, "Inventory"), blade, lore.level.ref(blade), true)
SheetLoreDrop.add(ed, box_titled(ed.doc, "Talents"), blade, lore.level.ref(blade), false)
lore.refresh()
lore.select_page(blade.id)