class_name Main extends Control ## The app window: top bar, felt board and result tray. Owns the board data, ## the Play/Build mode, roll animation, and editing actions with undo. enum Mode { PLAY, BUILD } const HISTORY_SIZE := 6 const SAVE_DELAY := 0.6 const HINTS := { Mode.PLAY: "Click a die to roll. Shift-click skips straight to the result.", Mode.BUILD: "Type to edit. Drag from a ● to another table to lay a pipe. Click a pipe for its options.", } var data: TowerBoard var library: LibraryStore var state: StateStore var mode: Mode = Mode.PLAY var cards: Dictionary = {} # table id -> TableCard var lit_entries: Dictionary = {} # "tid:eid" -> true var lit_pipes: Dictionary = {} # "tid:eid>to" -> true var current: Dictionary = {} var history: Array = [] var rng := RandomNumberGenerator.new() var board: BoardView var tray: ResultTray var _token := 0 var _pulse_tween: Tween var _link_from: Dictionary = {} var _drop_card: TableCard var _hint: Label var _play_button: Button var _build_button: Button var _build_tools: Control var _collapse_all: Button var _toast: PanelContainer var _toast_label: Label var _toast_undo: Button var _toast_timer: Timer var _save_timer: Timer var _undo_snapshot := "" var _saving_enabled := true # Local state for the current collection (see load_local_state). Kept in memory # and written to `state` when there is one (saving disabled: memory only). var decks: Dictionary = {} # table id -> DeckState var persistent_vars: Dictionary = {} # name without "@" -> {"value", "source"} var lit_texts: Dictionary = {} # "tid:eid" -> expanded BBCode from the last roll var _details_popup: DetailsPopup var _pipe_popover: PipePopover var _ref_cache: Dictionary = {} # entry text -> Array[String] of referenced table ids ## Choice cards: func(request: Dictionary) -> Variant, awaited by the roller ## (docs/LOGIC.md §8). It opens the choice pop-up (_ask_player); tests swap in ## a script. var prompt_hook: Callable = Callable() var _choice: ChoiceDialog ## The context of the roll in progress, or null; its root is the tree so far ## (Roller.progress()). var rolling_ctx: RollContext = null ## Chains longer than this show at once instead of animating. const LONG_CHAIN := 40 ## Copy-as-text indents by depth up to this many levels. const MAX_INDENT := 8 func _init() -> void: prompt_hook = _ask_player func _ready() -> void: rng.randomize() theme = Style.app_theme() var args := OS.get_cmdline_user_args() if args.has("--sample") or _arg_value(args, "--screenshot") != "": _saving_enabled = false if _saving_enabled: _open_library() if data == null: data = SampleBoard.create() data.id = "fantasy-loot" data.name = "Fantasy Loot" _build_ui() _rebuild_cards() _seed_session() _update_collapse_all() # Let the cards lay out before fitting them to the window. await get_tree().process_frame await get_tree().process_frame board.fit() _run_cli(args) func _exit_tree() -> void: _save_now() ## Migrates the old board.json if needed, then opens the last collection (or the ## first one, or a new "Fantasy Loot" made from the sample tables). func _open_library() -> void: state = StateStore.new() library = LibraryStore.new("user://", state) library.migrate_legacy() var last := str(state.get_setting("last_collection", "")) if last != "": data = library.load_collection(last) if data == null: for entry in library.list(): data = library.load_collection(str(entry["id"])) if data: break if data == null: data = library.create("Fantasy Loot") data.tables = SampleBoard.create().tables library.save(data) state.set_setting("last_collection", data.id) func _save_now() -> void: if _saving_enabled and data and library: library.save(data) state.set_setting("last_collection", data.id) state.save() # ---------- UI ---------- func _build_ui() -> void: set_anchors_and_offsets_preset(PRESET_FULL_RECT) var root := VBoxContainer.new() root.set_anchors_and_offsets_preset(PRESET_FULL_RECT) root.add_theme_constant_override("separation", 0) add_child(root) root.add_child(_build_top_bar()) board = BoardView.new() board.setup(self) root.add_child(board) _build_selection_bar() tray = ResultTray.new() tray.setup(self) root.add_child(tray) _build_toast() _save_timer = Timer.new() _save_timer.one_shot = true _save_timer.wait_time = SAVE_DELAY _save_timer.timeout.connect(func() -> void: _save_now() ) add_child(_save_timer) resized.connect(_place_toast) func _build_top_bar() -> Control: var bar := PanelContainer.new() var sb := Style.box(Style.FELT_DEEP, 0, [16, 10, 16, 10]) sb.border_width_bottom = 1 sb.border_color = Color(1, 1, 1, 0.07) bar.add_theme_stylebox_override("panel", sb) var h := HBoxContainer.new() h.add_theme_constant_override("separation", 16) bar.add_child(h) var brand := HBoxContainer.new() brand.add_theme_constant_override("separation", 9) var mark := Control.new() mark.custom_minimum_size = Vector2(20, 24) mark.size_flags_vertical = SIZE_SHRINK_CENTER mark.draw.connect(func() -> void: Icons.draw_tower(mark, Vector2(0, 0), 20.0 / 22.0, Style.ON_FELT, Style.BRASS)) brand.add_child(mark) var title := Style.make_label("TableTower", Style.display(), 23, Style.ON_FELT) title.size_flags_vertical = SIZE_SHRINK_CENTER brand.add_child(title) h.add_child(brand) var seg := PanelContainer.new() seg.add_theme_stylebox_override("panel", Style.box(Color(0, 0, 0, 0.28), 9, [3, 3, 3, 3])) seg.size_flags_vertical = SIZE_SHRINK_CENTER var seg_row := HBoxContainer.new() seg_row.add_theme_constant_override("separation", 0) seg.add_child(seg_row) var group := ButtonGroup.new() _play_button = _seg_button("Play", group) _build_button = _seg_button("Build", group) _play_button.button_pressed = true _play_button.pressed.connect(func() -> void: set_mode(Mode.PLAY)) _build_button.pressed.connect(func() -> void: set_mode(Mode.BUILD)) seg_row.add_child(_play_button) seg_row.add_child(_build_button) h.add_child(seg) _switcher = CollectionSwitcher.new() _switcher.size_flags_vertical = SIZE_SHRINK_CENTER _switcher.setup(self) h.add_child(_switcher) _hint = Style.make_label(HINTS[mode], Style.body(), 15, Style.ON_FELT_MUTED) _hint.size_flags_horizontal = SIZE_EXPAND_FILL _hint.size_flags_vertical = SIZE_SHRINK_CENTER _hint.text_overrun_behavior = TextServer.OVERRUN_TRIM_ELLIPSIS _hint.custom_minimum_size = Vector2(60, 0) h.add_child(_hint) var tools := HBoxContainer.new() tools.add_theme_constant_override("separation", 6) _build_tools = tools _add_menu = _make_add_menu() tools.add_child(_add_menu) _board_menu = IoMenu.new() _board_menu.setup(true, collections_enabled()) _board_menu.reset_requested.connect(reset_sample) _board_menu.import_requested.connect(import_collection) _board_menu.test_requested.connect(open_test_board) _board_menu.export_requested.connect(export_collection) tools.add_child(_board_menu) var test_btn := Style.bar_button("Test board…") test_btn.tooltip_text = "Roll the board many times and look for problems" test_btn.pressed.connect(open_test_board) tools.add_child(test_btn) tools.visible = false h.add_child(tools) _endless_chip = _make_endless_chip() h.add_child(_endless_chip) _collapse_all = Style.bar_button("Collapse all") _collapse_all.tooltip_text = "Collapse or expand every table at once" _collapse_all.pressed.connect(func() -> void: set_all_collapsed(_any_expanded())) h.add_child(_collapse_all) var zoom := HBoxContainer.new() zoom.add_theme_constant_override("separation", 6) var zout := Style.bar_button("−") zout.tooltip_text = "Zoom out" zout.custom_minimum_size = Vector2(34, 0) zout.pressed.connect(func() -> void: board.set_zoom(board.zoom / 1.15)) var zfit := Style.bar_button("Fit") zfit.tooltip_text = "Show every table" zfit.pressed.connect(func() -> void: board.fit()) var zin := Style.bar_button("+") zin.tooltip_text = "Zoom in" zin.custom_minimum_size = Vector2(34, 0) zin.pressed.connect(func() -> void: board.set_zoom(board.zoom * 1.15)) for b in [zout, zfit, zin]: zoom.add_child(b) h.add_child(zoom) return bar func _seg_button(text: String, group: ButtonGroup) -> Button: var b := Button.new() b.text = text b.toggle_mode = true b.button_group = group b.add_theme_font_override("font", Style.body_bold()) b.add_theme_font_size_override("font_size", 16) var normal := Style.box(Color(0, 0, 0, 0), 7, [16, 6, 16, 6]) var hover := Style.box(Color(1, 1, 1, 0.06), 7, [16, 6, 16, 6]) var pressed := Style.box(Style.CARD, 7, [16, 6, 16, 6]) Style.skin_button(b, normal, hover, pressed, Style.ON_FELT_MUTED, Style.ON_FELT, Style.INK) return b func _build_toast() -> void: _toast = PanelContainer.new() var sb := Style.box(Style.CARD, 10, [16, 9, 10, 9]) sb.shadow_color = Color(0, 0, 0, 0.4) sb.shadow_size = 18 sb.shadow_offset = Vector2(0, 8) _toast.add_theme_stylebox_override("panel", sb) var h := HBoxContainer.new() h.add_theme_constant_override("separation", 12) _toast.add_child(h) _toast_label = Style.make_label("", Style.body(), 15, Style.INK) _toast_label.size_flags_vertical = SIZE_SHRINK_CENTER h.add_child(_toast_label) _toast_undo = Button.new() _toast_undo.text = "Undo" _toast_undo.add_theme_font_override("font", Style.body_bold()) _toast_undo.add_theme_font_size_override("font_size", 15) var un := Style.box(Style.FELT, 7, [12, 5, 12, 5]) var uh := Style.box(Style.FELT_HOVER, 7, [12, 5, 12, 5]) Style.skin_button(_toast_undo, un, uh, uh, Style.BRASS) _toast_undo.pressed.connect(_undo) h.add_child(_toast_undo) _toast.hide() add_child(_toast) _toast_timer = Timer.new() _toast_timer.one_shot = true _toast_timer.wait_time = 5.0 _toast_timer.timeout.connect(func() -> void: _toast.hide() _undo_snapshot = "" ) add_child(_toast_timer) func toast(message: String, snapshot: String = "") -> void: _undo_snapshot = snapshot _toast_label.text = message _toast_undo.visible = snapshot != "" _toast.show() _toast.reset_size() _place_toast() _toast_timer.start() func _place_toast() -> void: if _toast and _toast.visible: _toast.reset_size() _toast.position = Vector2((size.x - _toast.size.x) / 2.0, size.y - _toast.size.y - 20.0) func _undo() -> void: if _undo_snapshot == "": return data.load_json(_undo_snapshot) _undo_snapshot = "" _toast.hide() _rebuild_cards() mark_dirty() func _snapshot() -> String: return data.to_json() # ---------- Cards ---------- func card_for(id: String) -> TableCard: return cards.get(id) func is_entry_lit(tid: String, eid: String) -> bool: return lit_entries.has(Roller.entry_key(tid, eid)) func _rebuild_cards() -> void: for c in board.cards.get_children(): board.cards.remove_child(c) c.queue_free() cards.clear() for t in data.tables: var card := TableCard.new() board.cards.add_child(card) card.setup(self, t) cards[t.id] = card selection.clear() _rebuild_groups() _update_selection_bar() _update_collapse_all() func _refresh_lit() -> void: for card in cards.values(): (card as TableCard).refresh_lit() _refresh_group_lits() func set_mode(m: Mode) -> void: if m == Mode.BUILD and _choice_waiting("Answer the waiting question before building"): _build_button.set_pressed_no_signal(mode == Mode.BUILD) _play_button.set_pressed_no_signal(mode == Mode.PLAY) return mode = m _play_button.set_pressed_no_signal(m == Mode.PLAY) _build_button.set_pressed_no_signal(m == Mode.BUILD) _hint.text = HINTS[m] _build_tools.visible = m == Mode.BUILD board.pipes.hover_key = "" clear_selection() for card in cards.values(): (card as TableCard).rebuild() for n in _group_nodes.values(): (n as GroupCard).rebuild() _update_endless_chip() func mark_dirty() -> void: if _saving_enabled: _save_timer.start() _ref_cache.clear() _update_collapse_all() _update_endless_chip() if mode == Mode.BUILD: refresh_live() ## True when an expanded group, or a table that isn't hidden in a collapsed ## group, could still be collapsed. func _any_expanded() -> bool: for g in data.groups: if not g.collapsed: return true var hidden := hidden_groups() for t in data.tables: if not t.collapsed and not hidden.has(t.id): return true return false func _update_collapse_all() -> void: if _collapse_all: _collapse_all.text = "Collapse all" if _any_expanded() else "Expand all" # ---------- Editing actions ---------- func toggle_collapse(tid: String) -> void: var t := data.get_table(tid) if t == null: return t.collapsed = not t.collapsed card_for(tid).rebuild() mark_dirty() ## Collapses or expands every table and every group. func set_all_collapsed(collapsed: bool) -> void: for t in data.tables: if t.collapsed != collapsed: t.collapsed = collapsed card_for(t.id).rebuild() var changed := false for g in data.groups: if g.collapsed != collapsed: g.collapsed = collapsed changed = true if changed: _rebuild_groups() mark_dirty() ## The "+ Table ▾" kinds: [label, kind, sub, default name]. const ADD_KINDS := [ ["Roll table", RollTable.KIND_ROLL, "", "New table"], ["Choice: which option", RollTable.KIND_CHOICE, "pick", "New choice"], ["Choice: how many", RollTable.KIND_CHOICE, "number", "How many?"], ["Choice: open ended", RollTable.KIND_CHOICE, "text", "What is it?"], ["Loop", RollTable.KIND_LOOP, "times", "Repeat"], ["Router: if / else if / otherwise", RollTable.KIND_ROUTER, "", "Router"], ["Variable", RollTable.KIND_VARIABLE, "number", "New variable"], ["Sheet", RollTable.KIND_SHEET, "", "Sheet"], ] var _add_menu: MenuButton func _make_add_menu() -> MenuButton: var mb := MenuButton.new() mb.text = "+ Table ▾" mb.tooltip_text = "Add a roll table or a logic card" mb.flat = false var ref := Style.bar_button("", true) for n in ["normal", "hover", "pressed", "hover_pressed", "disabled", "focus"]: mb.add_theme_stylebox_override(n, ref.get_theme_stylebox(n)) for c in ["font_color", "font_hover_color", "font_focus_color", "font_pressed_color", "font_hover_pressed_color"]: mb.add_theme_color_override(c, ref.get_theme_color(c)) mb.add_theme_font_override("font", Style.body_bold()) mb.add_theme_font_size_override("font_size", 15) mb.mouse_default_cursor_shape = CURSOR_POINTING_HAND ref.free() var pm := mb.get_popup() ModalCard.style_popup(pm) for i in ADD_KINDS.size(): if i == 1: pm.add_separator("Logic cards") pm.add_item(str(ADD_KINDS[i][0]), i) pm.add_separator("Groups and templates") pm.add_item("From template…", MENU_FROM_TEMPLATE) pm.add_item("Group selected cards Ctrl+G", MENU_GROUP) pm.add_item("Save selection as template…", MENU_SAVE_SELECTION) pm.about_to_popup.connect(func() -> void: pm.set_item_disabled(pm.get_item_index(MENU_GROUP), selection.is_empty()) pm.set_item_disabled(pm.get_item_index(MENU_SAVE_SELECTION), selection.is_empty()) ) pm.id_pressed.connect(func(id: int) -> void: match id: MENU_FROM_TEMPLATE: open_template_picker() MENU_GROUP: group_selection() MENU_SAVE_SELECTION: save_selection_as_template() _: var k: Array = ADD_KINDS[id] add_table(str(k[1]), str(k[2])) ) return mb const MENU_FROM_TEMPLATE := 100 const MENU_GROUP := 101 const MENU_SAVE_SELECTION := 102 ## Adds a card of any kind (RollTable.create) in the middle of the view. func add_table(kind: String = RollTable.KIND_ROLL, sub: String = "") -> RollTable: var center := board.screen_to_world(board.size / 2.0) var name := "New table" for k: Array in ADD_KINDS: if k[1] == kind and (sub == "" or k[2] == sub or kind != RollTable.KIND_CHOICE): name = str(k[3]) break var t := RollTable.create(kind, TowerBoard.new_id("t"), name, sub) if kind == RollTable.KIND_ROLL: for e in t.entries: e.id = TowerBoard.new_id("e") if kind == RollTable.KIND_VARIABLE: t.var_name = _free_var_name(t.var_name) t.position = Vector2(maxf(20.0, roundf(center.x - 128.0)), maxf(20.0, roundf(center.y - 120.0))) data.tables.append(t) var card := TableCard.new() board.cards.add_child(card) card.setup(self, t) cards[t.id] = card mark_dirty() return t ## `base`, or base_2, base_3… when another variable card already uses it. func _free_var_name(base: String) -> String: var used := {} for t in data.tables: if t.kind == RollTable.KIND_VARIABLE: used[t.var_name] = true var n := base var k := 2 while used.has(n): n = "%s_%d" % [base, k] k += 1 return n func reset_sample() -> void: var snap := _snapshot() data.tables = SampleBoard.create().tables data.groups.clear() lit_entries.clear() lit_pipes.clear() _rebuild_cards() mark_dirty() await get_tree().process_frame await get_tree().process_frame board.fit() toast("Board reset to the sample tables", snap) func add_entry(tid: String) -> void: var t := data.get_table(tid) var e := TableEntry.new(TowerBoard.new_id("e"), "Result %d" % (t.entries.size() + 1)) if t.is_ranged(): var hi := 0 for x in t.entries: hi = maxi(hi, x.range_hi) e.has_range = true e.range_lo = clampi(hi + 1, t.min_value(), t.die_size()) e.range_hi = e.range_lo e.text = "New range" t.entries.append(e) t.collapsed = false card_for(tid).rebuild() mark_dirty() func delete_entry(tid: String, eid: String) -> void: var t := data.get_table(tid) var e := t.find_entry(eid) if e == null: return var snap := _snapshot() t.entries.erase(e) card_for(tid).rebuild() mark_dirty() toast("Deleted “%s”" % e.text, snap) func delete_table(tid: String) -> void: var t := data.get_table(tid) if t == null: return var snap := _snapshot() var in_group := data.group_of(tid) data.remove_table(tid) forget_table_state(tid) selection.erase(tid) var card := card_for(tid) cards.erase(tid) card.queue_free() for c in cards.values(): (c as TableCard).rebuild() if in_group: _groups_changed() _update_selection_bar() mark_dirty() toast("Deleted %s" % t.name, snap) func remove_pipe(key: String) -> void: var from := key.get_slice(">", 0) var to := key.get_slice(">", 1) var t := data.get_table(from.get_slice(":", 0)) var target := data.get_table(to) if t == null: return var e := t.find_entry(from.get_slice(":", 1)) if e == null: return var snap := _snapshot() e.pipes.erase(to) lit_pipes.erase(key) board.pipes.hover_key = "" card_for(t.id).rebuild() mark_dirty() toast("Removed pipe from “%s” to %s" % [e.text, target.name if target else to], snap) func start_link(tid: String, eid: String) -> void: _link_from = {"tid": tid, "eid": eid} func update_link() -> void: var over := _card_under_mouse() if over != _drop_card: if is_instance_valid(_drop_card): _drop_card.set_drop_target(false) _drop_card = over if _drop_card: _drop_card.set_drop_target(true) func finish_link() -> void: var over := _card_under_mouse() if is_instance_valid(_drop_card): _drop_card.set_drop_target(false) _drop_card = null if _link_from.is_empty() or over == null: _link_from = {} return var t := data.get_table(_link_from["tid"]) var e := t.find_entry(_link_from["eid"]) if t else null _link_from = {} if e == null or e.pipes.has(over.table.id): return if over.table.kind == RollTable.KIND_VARIABLE: toast("Variable cards aren't rolled, so pipes can't lead into them. Use an effect such as @%s += 1." % over.table.var_name) return # Each range on a ranged table takes a single pipe, so a new one replaces the old. var replaced: RollTable = null if t.is_ranged(): if not e.pipes.is_empty(): replaced = data.get_table(e.pipes[0]) e.pipes.clear() e.pipes.append(over.table.id) card_for(t.id).rebuild() mark_dirty() var msg := "“%s” now rolls on %s" % [e.text, over.table.name] if replaced: msg += " instead of %s" % replaced.name toast(msg) func _card_under_mouse() -> TableCard: var gp := get_global_mouse_position() var kids := board.cards.get_children() for i in range(kids.size() - 1, -1, -1): var card := kids[i] as TableCard if card and card.visible and card.get_global_rect().has_point(gp): return card return null # ---------- Groups ---------- # A group is a frame around a block of cards (TableGroup). Expanded, its # GroupCard sits in board.groups behind the pipes; collapsed, it sits with the # cards and its members are hidden. Groups are presentation only: rolling, # lighting and the tray never look at them. var _group_nodes: Dictionary = {} # group id -> GroupCard var _hidden_cache: Variant = null # table id -> GroupCard, or null when stale ## Ids of the cards being dragged and the group the pointer is over (Build). var _drag_set: Array[String] = [] var _drag_over: GroupCard func group_node(gid: String) -> GroupCard: var n: GroupCard = _group_nodes.get(gid) return n if is_instance_valid(n) else null ## Table id -> the GroupCard of the collapsed group hiding it. func hidden_groups() -> Dictionary: if _hidden_cache == null: var out := {} if data: for g in data.groups: var n := group_node(g.id) if g.collapsed and n: for tid in g.members: out[tid] = n _hidden_cache = out return _hidden_cache ## Rebuilds every group's node, in the right layer, and hides the members of ## collapsed groups. func _rebuild_groups() -> void: for n in _group_nodes.values(): if is_instance_valid(n): if (n as Node).get_parent(): (n as Node).get_parent().remove_child(n) (n as Node).queue_free() _group_nodes.clear() _hidden_cache = null if data == null or board == null: return for g in data.groups: var n := GroupCard.new() if g.collapsed: board.cards.add_child(n) else: board.groups.add_child(n) n.setup(self, g) _group_nodes[g.id] = n _apply_group_visibility() ## After a membership or group change: rebuild the group nodes and keep the ## rest in step. func _groups_changed() -> void: _rebuild_groups() _update_collapse_all() func _apply_group_visibility() -> void: _hidden_cache = null var hidden := hidden_groups() for tid: String in cards: var c: TableCard = cards[tid] var hide := hidden.has(tid) c.visible = not hide if hide and selection.erase(tid): c.set_selected(false) _update_selection_bar() ## "tid:eid" keys of a group's lit results, in roll order. func lit_keys_for_group(g: TableGroup) -> Array: var members := {} for tid in g.members: members[tid] = true var out: Array = [] for k: String in lit_texts: var i := k.rfind(":") if i > 0 and members.has(k.substr(0, i)): out.append(k) return out func _refresh_group_lits() -> void: for g in data.groups: var n := group_node(g.id) if n and g.collapsed: n.refresh_lit(lit_keys_for_group(g)) func toggle_group(gid: String) -> void: var g := data.get_group(gid) if g == null: return g.collapsed = not g.collapsed details().hide_for() _groups_changed() mark_dirty() func set_group_collapsed(gid: String, collapsed: bool) -> void: var g := data.get_group(gid) if g and g.collapsed != collapsed: toggle_group(gid) ## Moves a group and its members (dragging the title bar). func move_group(gid: String, delta: Vector2) -> void: var g := data.get_group(gid) if g == null: return data.move_group(gid, delta) for tid in g.members: var c := card_for(tid) if c: c.position = data.get_table(tid).position var n := group_node(gid) if n: n.sync_rect() ## "Group 1", "Group 2"… whichever isn't used. func _free_group_name() -> String: var used := {} for g in data.groups: used[g.name] = true var k := 1 while used.has("Group %d" % k): k += 1 return "Group %d" % k ## Ctrl+G: groups the selected cards (taking them out of any other group). func group_selection() -> TableGroup: var ids: Array[String] = [] for t in data.tables: if selection.has(t.id): ids.append(t.id) if ids.is_empty(): toast("Select some cards first: Ctrl- or Shift-click their headers, or Ctrl-drag on the felt") return null var snap := _snapshot() var g := data.add_group(_free_group_name(), ids) var rects: Array = [] for tid in ids: var c := card_for(tid) rects.append(Rect2(c.position, c.size)) g.fit_to(rects) # Groups don't nest: emptied groups stay, so they can be refilled or ungrouped. clear_selection() _groups_changed() mark_dirty() toast("Grouped %d %s as “%s”" % [ids.size(), "card" if ids.size() == 1 else "cards", g.name], snap) return g ## Removes the group; its cards stay where they are. func ungroup(gid: String) -> void: var g := data.get_group(gid) if g == null: return var snap := _snapshot() data.ungroup(gid) _groups_changed() mark_dirty() toast("Ungrouped “%s”" % Formatter.strip_tags(g.name), snap) func confirm_delete_group(gid: String) -> void: var g := data.get_group(gid) if g == null: return var n := g.members.size() _add_modal(ModalCard.confirm("Delete group", "Delete “%s” and the %d %s in it? Pipes from other cards into them are removed too. You can undo this from the message that follows." % [Formatter.strip_tags(g.name), n, "card" if n == 1 else "cards"], "Delete group and cards", func() -> void: delete_group(gid), true)) ## Deletes a group and every card in it (undo from the toast). func delete_group(gid: String) -> void: var g := data.get_group(gid) if g == null: return var snap := _snapshot() var gname := Formatter.strip_tags(g.name) var gone := data.delete_group(gid) for tid in gone: forget_table_state(tid) selection.erase(tid) var card := card_for(tid) cards.erase(tid) if card: card.get_parent().remove_child(card) card.queue_free() for c in cards.values(): (c as TableCard).rebuild() _groups_changed() mark_dirty() toast("Deleted “%s” and its %d %s" % [gname, gone.size(), "card" if gone.size() == 1 else "cards"], snap) ## The group details editor (Build): a card-styled dialog with the text. func edit_group_details(gid: String) -> void: var g := data.get_group(gid) if g == null: return var d := ModalCard.new("Details for %s" % Formatter.strip_tags(g.name), 520.0) var te := TextEdit.new() te.text = g.details te.placeholder_text = "Shown when hovering the group's title (BBCode)" te.wrap_mode = TextEdit.LINE_WRAPPING_BOUNDARY te.custom_minimum_size = Vector2(0, 120) ModalCard.style_text_edit(te) d.body.add_child(te) d.add_button("Cancel", "plain", d.close) d.add_button("Save", "primary", func() -> void: g.details = te.text.strip_edges() d.close() var n := group_node(gid) if n: n.rebuild() mark_dirty() ) _add_modal(d) ## The expanded group frame containing a world point (the smallest, if they overlap). func _frame_at(p: Vector2) -> TableGroup: var best: TableGroup = null for g in data.groups: if g.collapsed or not g.rect().has_point(p): continue if best == null or g.rect().get_area() < best.rect().get_area(): best = g return best # ----- Card drags (TableCard calls these) ----- func begin_card_drag(card: TableCard) -> void: _drag_set.clear() if mode == Mode.BUILD and selection.has(card.table.id) and selection.size() > 1: for tid: String in selection: if cards.has(tid): _drag_set.append(tid) else: _drag_set.append(card.table.id) # The frames of the dragged cards' groups hold still, so a card can leave them. for tid in _drag_set: var g := data.group_of(tid) if g: board.groups.frozen[g.id] = true ## Moves the dragged card (and the rest of a multi-selection) so `card` lands at `to`. func drag_card(card: TableCard, to: Vector2) -> void: var delta := to - card.position if _drag_set.size() > 1: # Keep every selected card on the board. for tid in _drag_set: var c := card_for(tid) delta.x = maxf(delta.x, 10.0 - c.position.x) delta.y = maxf(delta.y, 10.0 - c.position.y) for tid in _drag_set: var c := card_for(tid) c.position += delta c.table.position = c.position else: card.position = to card.table.position = to if mode == Mode.BUILD: var over := _frame_at(card.position + card.size / 2.0) var node := group_node(over.id) if over else null if node != _drag_over: if is_instance_valid(_drag_over): _drag_over.set_drop_target(false) _drag_over = node if node: node.set_drop_target(true) ## Drop: in Build, a card dropped in a group frame joins it, and one dropped ## outside its own (held) frame leaves it. func end_card_drag(_card: TableCard) -> void: if is_instance_valid(_drag_over): _drag_over.set_drop_target(false) _drag_over = null var joined := {} var left := 0 if mode == Mode.BUILD: for tid in _drag_set: var c := card_for(tid) if c == null: continue var center := c.position + c.size / 2.0 var g0 := data.group_of(tid) var target := _frame_at(center) if target != null and target != g0: data.add_to_group(tid, target.id) joined[target.name] = int(joined.get(target.name, 0)) + 1 elif target == null and g0 != null and not g0.rect().has_point(center): data.remove_from_group(tid) left += 1 board.groups.frozen.clear() _drag_set.clear() if not joined.is_empty() or left > 0: _groups_changed() var parts := PackedStringArray() for gname: String in joined: parts.append("added %d to “%s”" % [joined[gname], Formatter.strip_tags(gname)]) if left > 0: parts.append("took %d out of %s" % [left, "its group" if left == 1 else "their groups"]) var msg := ", ".join(parts) toast(msg.substr(0, 1).to_upper() + msg.substr(1)) mark_dirty() # ----- Selection (Build) ----- ## Table ids selected in Build mode (Ctrl/Shift-click, Ctrl-drag on the felt). var selection: Dictionary = {} var _sel_bar: PanelContainer var _sel_label: Label func is_selected(tid: String) -> bool: return selection.has(tid) func toggle_selected(tid: String) -> void: var c := card_for(tid) if c == null or not c.visible: return if selection.has(tid): selection.erase(tid) else: selection[tid] = true c.set_selected(selection.has(tid)) _update_selection_bar() func set_selection(ids: Array) -> void: clear_selection() for tid: Variant in ids: var c := card_for(str(tid)) if c and c.visible: selection[str(tid)] = true c.set_selected(true) _update_selection_bar() func clear_selection() -> void: for tid: String in selection: var c := card_for(tid) if c: c.set_selected(false) selection.clear() _update_selection_bar() ## Adds every visible card touching a world rectangle to the selection. func select_in_rect(r: Rect2) -> void: for tid: String in cards: var c: TableCard = cards[tid] if c.visible and Rect2(c.position, c.size).intersects(r): selection[tid] = true c.set_selected(true) _update_selection_bar() func _build_selection_bar() -> void: _sel_bar = PanelContainer.new() var sb := Style.box(Style.FELT_DEEP, 10, [14, 7, 8, 7]) Style.bordered(sb, 1, Color(1, 1, 1, 0.12)) sb.shadow_color = Color(0, 0, 0, 0.4) sb.shadow_size = 14 sb.shadow_offset = Vector2(0, 6) _sel_bar.add_theme_stylebox_override("panel", sb) var h := HBoxContainer.new() h.add_theme_constant_override("separation", 8) _sel_bar.add_child(h) _sel_label = Style.make_label("", Style.body_bold(), 15, Style.ON_FELT) _sel_label.size_flags_vertical = SIZE_SHRINK_CENTER h.add_child(_sel_label) var grp := Style.bar_button("Group", true) grp.tooltip_text = "Put the selected cards in a group (Ctrl+G)" grp.pressed.connect(func() -> void: group_selection()) h.add_child(grp) var tpl := Style.bar_button("Save as template…") tpl.tooltip_text = "Save the selected cards as a reusable template" tpl.pressed.connect(save_selection_as_template) h.add_child(tpl) var clr := Style.bar_button("Clear") clr.tooltip_text = "Clear the selection (Esc)" clr.pressed.connect(clear_selection) h.add_child(clr) _sel_bar.hide() board.add_child(_sel_bar) board.resized.connect(_place_selection_bar) func _update_selection_bar() -> void: if _sel_bar == null: return var n := selection.size() _sel_bar.visible = n > 0 and mode == Mode.BUILD _sel_label.text = "%d %s selected" % [n, "card" if n == 1 else "cards"] _place_selection_bar.call_deferred() func _place_selection_bar() -> void: if _sel_bar and _sel_bar.visible: _sel_bar.reset_size() _sel_bar.position = Vector2((board.size.x - _sel_bar.size.x) / 2.0, 14.0) func _unhandled_input(ev: InputEvent) -> void: var k := ev as InputEventKey if k == null or not k.pressed or k.echo or mode != Mode.BUILD: return if k.keycode == KEY_G and (k.ctrl_pressed or k.meta_pressed): group_selection() get_viewport().set_input_as_handled() elif k.keycode == KEY_ESCAPE and not selection.is_empty(): clear_selection() get_viewport().set_input_as_handled() # ---------- Templates ---------- # Saved in user://templates (TemplateLibrary), shared by every collection. # --sample runs keep them in memory only. var _templates: TemplateLibrary func templates() -> TemplateLibrary: if _templates == null: _templates = TemplateLibrary.new("user://" if _saving_enabled else "") return _templates ## Opens the save dialog for a template of these tables (and groups). func save_template_from(table_ids: Array, kind: String, group_ids: Array = []) -> void: var tname := "Template" if kind == "card" and table_ids.size() == 1 and data.get_table(str(table_ids[0])): tname = Formatter.strip_tags(data.get_table(str(table_ids[0])).name) elif kind == "group" and group_ids.size() == 1 and data.get_group(str(group_ids[0])): tname = Formatter.strip_tags(data.get_group(str(group_ids[0])).name) var tpl := TemplateKit.make(data, table_ids, kind, tname, "", group_ids) if (tpl["tables"] as Array).is_empty(): toast("Nothing to save: the template would have no cards") return if kind == "selection": tpl["name"] = "%d cards" % (tpl["tables"] as Array).size() _add_modal(TemplateForms.save_dialog(tpl, func(out: Dictionary) -> void: var id := templates().add(out) if id == "": toast("Couldn't save the template") else: toast("Saved template “%s”. Insert it from + Table ▾ → From template…" % out["name"]) )) ## The selection as a template; groups whose cards are all selected come along. func save_selection_as_template() -> void: if selection.is_empty(): toast("Select some cards first") return var gids: Array = [] for g in data.groups: if g.members.is_empty(): continue var all := true for m in g.members: if not selection.has(m): all = false break if all: gids.append(g.id) save_template_from(selection.keys(), "selection", gids) func open_template_picker() -> TemplatePicker: var p := TemplatePicker.new(self, templates()) _add_modal(p) return p ## Asks for the template's parameters (if it has any), then inserts it. func begin_template_insert(tpl: Dictionary) -> void: if (tpl.get("params", []) as Array).is_empty(): insert_template(tpl, {}) return _add_modal(TemplateForms.params_dialog(tpl, func(values: Dictionary) -> void: insert_template(tpl, values))) ## Inserts a template at the view centre: parameters substituted, fresh ids, ## outside pipes relinked by name (or dropped and reported). Returns ## TemplateKit.instantiate's result. func insert_template(tpl: Dictionary, values: Dictionary) -> Dictionary: var snap := _snapshot() var ext := TemplateKit.extent(tpl) var center := board.screen_to_world(board.size / 2.0) var origin := (center - ext / 2.0).round() origin = Vector2(maxf(20.0, origin.x), maxf(20.0 + TableGroup.TITLE_H, origin.y)) var r := TemplateKit.insert(tpl, values, data, origin) for t: RollTable in r["tables"]: if t.kind == RollTable.KIND_VARIABLE and t.var_name == "": t.var_name = _free_var_name("var") var card := TableCard.new() board.cards.add_child(card) card.setup(self, t) cards[t.id] = card _groups_changed() mark_dirty() var n := (r["tables"] as Array).size() var msg := "Inserted “%s” (%d %s)" % [str(tpl.get("name", "template")), n, "card" if n == 1 else "cards"] var relinked: Array = r["relinked"] if not relinked.is_empty(): msg += " · %d %s relinked by name" % [relinked.size(), "pipe" if relinked.size() == 1 else "pipes"] var dropped: Array = r["dropped"] if dropped.is_empty(): toast(msg, snap) else: toast(msg + " · %d left out" % dropped.size(), snap) var d := ModalCard.new("Inserted “%s”" % str(tpl.get("name", "template")), 540.0) d.body.add_child(ModalCard.note("These pipes led to cards outside the template, and this collection has no card with that name, so they were left out. Lay them again by hand, or rename a card and insert again.", Style.INK)) d.body.add_child(ModalCard.section("Left out (%d)" % dropped.size())) for what: String in dropped: d.body.add_child(ModalCard.note("• " + what, Style.INK)) if not relinked.is_empty(): d.body.add_child(ModalCard.section("Relinked (%d)" % relinked.size())) for what: String in relinked: d.body.add_child(ModalCard.note("• " + what)) d.add_button("Done", "primary", d.close) _add_modal(d) return r func export_template(id: String) -> void: var text := templates().export_text(id) if text == "": toast("Couldn't read that template") return var dlg := FileDialog.new() dlg.use_native_dialog = true dlg.access = FileDialog.ACCESS_FILESYSTEM dlg.file_mode = FileDialog.FILE_MODE_SAVE_FILE dlg.title = "Export template" dlg.filters = PackedStringArray(["*.json ; TableTower template"]) dlg.current_file = id.trim_prefix(TemplateLibrary.BUILTIN_PREFIX) + ".template.json" dlg.file_selected.connect(func(path: String) -> void: var err := TowerBoard.write_text_atomic(path, text) toast("Exported to %s" % path.get_file() if err == OK else "Couldn't write %s" % path.get_file()) ) dlg.visibility_changed.connect(func() -> void: if not dlg.visible: dlg.queue_free.call_deferred() ) add_child(dlg) dlg.popup_centered_ratio(0.6) func import_template_file(picker: TemplatePicker = null) -> void: var dlg := FileDialog.new() dlg.use_native_dialog = true dlg.access = FileDialog.ACCESS_FILESYSTEM dlg.file_mode = FileDialog.FILE_MODE_OPEN_FILE dlg.title = "Import a template" dlg.filters = PackedStringArray(["*.json ; TableTower template"]) dlg.file_selected.connect(func(path: String) -> void: var r := templates().import_text(FileAccess.get_file_as_string(path)) if r["ok"]: toast("Imported template “%s”" % r["name"]) if is_instance_valid(picker): picker.refresh() picker.select(r["id"]) else: _add_modal(IoMenu.report_dialog("Couldn't import %s" % path.get_file(), {"errors": r["errors"]})) ) dlg.visibility_changed.connect(func() -> void: if not dlg.visible: dlg.queue_free.call_deferred() ) add_child(dlg) dlg.popup_centered_ratio(0.6) # ---------- Rolling ---------- ## Rolls a table and plays the result down its pipes. A fast roll (Shift held ## while clicking, or `fast`) skips the flicker and the beads and shows the ## whole result at once. Choice cards still ask (docs/LOGIC.md §8): before a ## question opens, the steps so far light up; after the last answer the rest ## of the roll shows at once. Starting a roll while a question is open cancels ## the old roll. func start_roll(tid: String, fast: bool = false) -> void: var t := data.get_table(tid) if t == null or t.kind == RollTable.KIND_VARIABLE: return # A minimized question keeps waiting; a new roll must not cancel it. if _choice_waiting("Answer the waiting question first"): return fast = fast or Input.is_key_pressed(KEY_SHIFT) _archive_current() _token += 1 var my := _token # A question left open by the previous roll answers Cancel; that roll then # sees it has been replaced and stops quietly. cancel_choice() if _pulse_tween and _pulse_tween.is_valid(): _pulse_tween.kill() board.pipes.pulse_key = "" for c in cards.values(): (c as TableCard).set_rolling(false) (c as TableCard).clear_flick() var ctx := Roller.new_context(data, rng, persistent_vars, decks) ctx.prompt = _prompt_for.bind(my) rolling_ctx = ctx current = {"collection": data.id, "root": tid, "root_name": t.name, "time": Time.get_unix_time_from_system(), "steps": [], "all": [], "done": false, "pending": true} var tree: Dictionary = await Roller.roll_async(data, tid, ctx) if rolling_ctx == ctx: rolling_ctx = null if my != _token or not is_inside_tree(): # Another roll started while this one waited for an answer. _store_decks() if ctx.persistent_changed: _store_variables() return var prompted: bool = current.get("prompted", false) lit_entries.clear() lit_pipes.clear() lit_texts.clear() current = {"collection": data.id, "root": tid, "root_name": t.name, "time": current.get("time", Time.get_unix_time_from_system()), "steps": [], "all": Roller.flatten(tree, []), "done": false, "chain_vars": ctx.chain_vars.duplicate()} if ctx.halted != "": current["halted"] = ctx.halted _store_roll(ctx) if fast or prompted or (current["all"] as Array).size() > LONG_CHAIN: _finish_fast_roll() return _refresh_lit() tray.render() await _play_node(tree, my) if my == _token: current["steps"] = current["all"] current["done"] = true tray.render() refresh_live() ## The roll's prompt hook: lights the steps so far, then asks through ## prompt_hook (the pop-up, or a test's script). A reply for a roll that has ## been replaced in the meantime is turned into Cancel. func _prompt_for(req: Dictionary, my: int) -> Variant: if my != _token: return null current["prompted"] = true current["asking"] = Formatter.strip_tags(str(req.get("title", ""))) show_progress() var reply: Variant = await prompt_hook.call(req) if my != _token: return null current.erase("asking") return reply ## Lights the steps of the running roll so far (Roller.progress) on the board ## and in the tray, all at once. Used just before a question opens. func show_progress() -> void: if rolling_ctx == null: return var steps := Roller.progress(rolling_ctx) lit_entries.clear() lit_pipes.clear() lit_texts.clear() _light_steps(steps) _refresh_lit() _reveal_steps(steps) current["steps"] = steps current["all"] = steps current["fast"] = true refresh_live() tray.render() ## The real prompt hook: opens the choice pop-up and waits for its answer ## (an index or -1 for a pick, an int, a String, or null for Cancel). func _ask_player(req: Dictionary) -> Variant: cancel_choice() var d := ChoiceDialog.new(req) _choice = d var waiter := d.reply _add_modal(d) var v: Variant = await waiter.done if _choice == d: _choice = null return v ## True (after a toast with a Show button) while a question is minimized. func _choice_waiting(message: String) -> bool: var d := pending_choice() if d == null or not d.minimized: return false d.nudge(message) return true ## The open choice pop-up, or null. func pending_choice() -> ChoiceDialog: return _choice if is_instance_valid(_choice) else null ## Closes an open choice pop-up as Cancel (its roll stops with "Cancelled"). func cancel_choice() -> void: var d := pending_choice() _choice = null if d != null: d.answer(null) ## Plays a result tree step by step. Iterative (an explicit stack), so long ## chains don't recurse. func _play_node(root_node: Dictionary, my: int) -> void: var stack: Array = [[root_node, 0, ""]] # node, depth, pipe key that led to it while not stack.is_empty(): var top: Array = stack.pop_back() var n: Dictionary = top[0] if my != _token or n.is_empty(): return var key: String = top[2] if key != "": lit_pipes[key] = true await _pulse(key, my) if my != _token: return await _play_one(n, my, int(top[1])) if my != _token: return if n.has("stop"): continue var kids: Array = n["children"] var eid := (n["entry"] as TableEntry).id var tid := (n["table"] as RollTable).id for k in range(kids.size() - 1, -1, -1): var c: Dictionary = kids[k] var ck := "" if (c.has("pass") or c.has("after")) else Roller.link_key(tid, eid, c) stack.append([c, int(top[1]) + 1, ck]) ## Animates one node: the card tumbles (plain rolls only), then the result lights. func _play_one(n: Dictionary, my: int, depth: int) -> void: var t: RollTable = n["table"] var stopped := n.has("stop") var card := card_for(t.id) var tumble: bool = not n.has("kind") or bool(n.get("random", false)) # A table hidden in a collapsed group rolls on the group's card. var gcard: GroupCard = hidden_groups().get(t.id) if not stopped and gcard and tumble: gcard.set_rolling(true) await get_tree().create_timer(0.35).timeout if my != _token: return gcard = hidden_groups().get(t.id) if gcard: gcard.set_rolling(false) elif not stopped and card and tumble: card.set_rolling(true) for k in 8: card = card_for(t.id) if card == null: break if t.collapsed: card.set_more_text("Rolling… %s" % t.fmt(rng.randi_range(t.min_value(), maxi(t.min_value(), t.die_size())))) else: card.flick_random() await get_tree().create_timer((40.0 + k * 16.0) / 1000.0).timeout if my != _token: return card = card_for(t.id) if card: card.clear_flick() card.set_rolling(false) if not stopped: var e: TableEntry = n["entry"] var ek := Roller.entry_key(t.id, e.id) lit_entries[ek] = true lit_texts[ek] = str(n.get("summary", e.text)) _refresh_lit() if card: card.reveal(e.id) (current["steps"] as Array).append(Roller.step_of(n, depth)) tray.render() ## Shows the whole current roll at once: every result and pipe on its path lit, ## long lists scrolled to their result, and the full chain in the tray. func _finish_fast_roll() -> void: var all: Array = current["all"] _light_steps(all) _refresh_lit() _reveal_steps(all) current["steps"] = all current["done"] = true current["fast"] = true refresh_live() tray.render() ## Scrolls long cards to the last result each table gave in `steps` (one ## reveal per table, so thousands of steps cost one pass). func _reveal_steps(steps: Array) -> void: var last := {} for s: Dictionary in steps: if s.has("entry_id") and not s.get("stop", false): last[str(s.get("table_id", ""))] = str(s["entry_id"]) for tid: String in last: var card := card_for(tid) if card: card.reveal(last[tid]) ## Re-renders the live cards (variables, sheets, questions). Called after a ## roll, after variable edits and after edits in Build, never per frame, so ## dice inside {= } don't re-roll all the time. func refresh_live() -> void: for card in cards.values(): (card as TableCard).refresh_live() func _pulse(key: String, my: int) -> void: var length := board.pipes.path_length(key) if length <= 0.0 or my != _token: return board.pipes.pulse_key = key board.pipes.pulse_t = 0.0 _pulse_tween = create_tween().set_trans(Tween.TRANS_QUAD).set_ease(Tween.EASE_IN_OUT) _pulse_tween.tween_property(board.pipes, "pulse_t", 1.0, clampf(length * 0.8, 260.0, 650.0) / 1000.0) await _pulse_tween.finished if board.pipes.pulse_key == key: board.pipes.pulse_key = "" ## Moves the current roll to the Earlier list (it's already in the saved history). func _archive_current() -> void: # A roll still waiting for an answer is cancelled, not kept. if current.is_empty() or current.get("archived", false) or current.get("pending", false): return current["archived"] = true var rec := current.duplicate() rec["steps"] = current["all"] history.push_front(rec) if history.size() > HISTORY_SIZE: history.resize(HISTORY_SIZE) ## Opens the session: the collection's saved history, decks and variables. With ## no saved history (a fresh start, or --sample / --screenshot), it seeds a game ## already under way: a couple of earlier rolls, saved variables for the ## Variables tab, and a current roll that runs through the d100 travel table ## into the collapsed trinket table. func _seed_session() -> void: load_local_state() if not current.is_empty(): _light_steps(current.get("all", [])) _refresh_lit() refresh_live() tray.render() return var now := Time.get_unix_time_from_system() # Seeded rolls draw from scratch decks so they don't use up real cards. var scratch := {} for seed_roll in [["monsters", 9], ["loot", 4]]: if data.get_table(seed_roll[0]): var tree := Roller.roll(data, seed_roll[0], rng, 0, scratch) var steps := Roller.flatten(tree, []) history.push_front({"collection": data.id, "root": seed_roll[0], "root_name": data.get_table(seed_roll[0]).name, "time": now - seed_roll[1] * 60, "steps": steps, "all": steps, "archived": true}) # A quest-style chain earlier in the session saved who guides the party and # the day's weather, so {@guide} and {@weather} have values. if persistent_vars.is_empty(): var ctx := Roller.new_context(data, rng, persistent_vars, scratch) for pair in [["@guide", "names"], ["@weather", "weather"]]: if data.get_table(pair[1]): var n := Roller.roll(data, pair[1], rng, 0, scratch, ctx) if not n.is_empty() and not n.has("stop"): ctx.save(pair[0], Formatter.to_export_bbcode(str(n["summary"])), pair[1]) var start := "wilderness" if data.get_table("wilderness") else _first_rollable() if start == "": refresh_live() tray.render() return var best: Dictionary if data.get_table("trinkets"): best = Roller.roll(data, start, rng, 0, scratch) for i in 400: if Roller.reaches(best, "trinkets"): break best = Roller.roll(data, start, rng, 0, scratch) else: # Any other board: one roll with the headless answers, through the real # variables, so variable and sheet cards have values to show. best = Roller.roll(data, start, rng, 0, scratch, Roller.new_context(data, rng, persistent_vars, scratch)) var all := Roller.flatten(best, []) current = {"collection": data.id, "root": start, "root_name": data.get_table(start).name, "time": now - 60, "steps": all, "all": all, "done": true, "chain_vars": {}} Roller.collect_lit(best, lit_entries, lit_pipes, lit_texts) _refresh_lit() refresh_live() tray.render() ## The first table that can start a roll (not a variable card), or "". func _first_rollable() -> String: for t in data.tables: if t.kind != RollTable.KIND_VARIABLE: return t.id return "" # ---------- Command line (used for screenshots and checks) ---------- # godot --path . -- --screenshot=/tmp/shot.png [--build] [--expand-all] [--collapse-all] # [--roll=