Main (3679 lines) becomes a shell: shared state, start-up, cards, input, rules view and one-line delegators for the methods other files call. Each area moves with its state into a RefCounted helper holding a back-reference (m: Main): main_cli.gd command-line and screenshot flags main_top_bar.gd top bar, toast, endless-loop chip main_editing.gd add/delete cards, results and pipes, selection bar main_groups.gd groups and card drags main_templates.gd templates main_rolling.gd rolling, choice questions, playback, session seed, copy main_collections.gd collections, import/export, table settings, test board main_state.gd decks, variables, roll history (local state) main_navigation.gd search, focus, minimap, arrange/pack main_history.gd undo/redo and mark_dirty main_inspector.gd inspector selection and refresh Tests that reached moved private members now go through the helper (main.undo_redo.edits, main.rolling.pending_choice(), ...). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
112 lines
3.6 KiB
GDScript
112 lines
3.6 KiB
GDScript
class_name MainInspectorLink
|
|
extends RefCounted
|
|
## Main's side of the Build inspector (docs/PLAIN.md §5). The inspector edits
|
|
## the selected card, result or pipe. The display side calls select_card /
|
|
## select_result / select_pipe / clear_inspector; Main also selects from the
|
|
## board: a card's title (drag start), focus entering a result's field on a
|
|
## card, a clicked pipe, the ⚙.
|
|
|
|
var m: Main
|
|
|
|
var _pipe_popover: PipePopover
|
|
|
|
|
|
func _init(p_main: Main) -> void:
|
|
m = p_main
|
|
|
|
|
|
## Build mode: a clicked pipe opens in the inspector. The old pop-up
|
|
## (PipePopover) is only a fallback for when there is no inspector.
|
|
func open_pipe_options(key: String, at: Vector2) -> void:
|
|
if m.inspector != null:
|
|
m.details().hide_for()
|
|
select_pipe(key)
|
|
return
|
|
if _pipe_popover == null:
|
|
_pipe_popover = PipePopover.new()
|
|
m.add_child(_pipe_popover)
|
|
_pipe_popover.setup(m)
|
|
m.details().hide_for()
|
|
_pipe_popover.open(key, at)
|
|
|
|
|
|
## The card's ⚙ button. Main.open_table_settings comes from the app-shell work;
|
|
## until it exists this only says so.
|
|
func request_table_settings(tid: String) -> void:
|
|
if m.mode == Main.Mode.BUILD and m.inspector != null:
|
|
select_card(tid)
|
|
return
|
|
if m.has_method("open_table_settings"):
|
|
m.call("open_table_settings", tid)
|
|
else:
|
|
m.toast("Table settings aren't available yet")
|
|
|
|
|
|
func select_card(table_id: String) -> void:
|
|
if m.inspector == null or m.data.get_table(table_id) == null:
|
|
return
|
|
m.inspector.select({"kind": "card", "tid": table_id})
|
|
|
|
|
|
func select_result(table_id: String, entry_id: String) -> void:
|
|
var t := m.data.get_table(table_id)
|
|
if m.inspector == null or t == null or t.find_entry(entry_id) == null:
|
|
return
|
|
m.inspector.select({"kind": "result", "tid": table_id, "eid": entry_id})
|
|
|
|
|
|
## `key` is a pipe key, "tid:eid>to" (Roller.pipe_key).
|
|
func select_pipe(key: String) -> void:
|
|
var from := key.get_slice(">", 0)
|
|
var tid := from.get_slice(":", 0)
|
|
var eid := from.get_slice(":", 1)
|
|
var to := key.get_slice(">", 1)
|
|
var t := m.data.get_table(tid)
|
|
var e := t.find_entry(eid) if t else null
|
|
if m.inspector == null or e == null or not e.pipes.has(to):
|
|
return
|
|
m.inspector.select({"kind": "pipe", "tid": tid, "eid": eid, "to": to})
|
|
|
|
|
|
func clear_inspector() -> void:
|
|
if m.inspector:
|
|
m.inspector.clear()
|
|
|
|
|
|
## What the inspector shows: {kind: "card" | "result" | "pipe", tid, eid?, to?} or {}.
|
|
func inspector_selection() -> Dictionary:
|
|
return m.inspector.selection.duplicate() if m.inspector else {}
|
|
|
|
|
|
## After the inspector changed a card: refreshes it (every card when a
|
|
## variable's name or label changed, since other cards show it).
|
|
func inspector_edited(tid: String, all_cards: bool = false) -> void:
|
|
m.local_state._ref_cache.clear()
|
|
if all_cards:
|
|
for c in m.cards.values():
|
|
(c as TableCard).rebuild()
|
|
else:
|
|
var card := m.card_for(tid)
|
|
if card:
|
|
card.rebuild()
|
|
|
|
|
|
## Focus entering a field on a card in Build selects that result (or the card).
|
|
func _inspect_focus(c: Control) -> void:
|
|
if m.mode != Main.Mode.BUILD or m.inspector == null or c == null or m.inspector.is_ancestor_of(c):
|
|
return
|
|
var n: Node = c
|
|
while n != null and not (n is TableCard):
|
|
n = n.get_parent()
|
|
var card := n as TableCard
|
|
if card == null or card.table == null:
|
|
return
|
|
for eid: String in card.rows:
|
|
var row: Node = card.rows[eid]
|
|
if is_instance_valid(row) and row.is_ancestor_of(c):
|
|
var s := m.inspector.selection
|
|
if str(s.get("tid", "")) != card.table.id or str(s.get("eid", "")) != eid or str(s.get("kind", "")) == "card":
|
|
select_result(card.table.id, eid)
|
|
return
|
|
if str(m.inspector.selection.get("tid", "")) != card.table.id:
|
|
select_card(card.table.id)
|