Split ui/main.gd into area helpers (no behaviour change)
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>
2026-11-09 08:14:19 -06:00
|
|
|
class_name MainEditing
|
|
|
|
|
extends RefCounted
|
|
|
|
|
## Main's Build editing actions: adding and deleting cards, results and
|
|
|
|
|
## pipes, laying pipes by drag, and the card selection with its bar.
|
|
|
|
|
|
|
|
|
|
var m: Main
|
|
|
|
|
|
|
|
|
|
var _link_from: Dictionary = {}
|
2026-11-16 10:41:13 -06:00
|
|
|
## Tests only: the card a link drop lands on, instead of the one under the mouse.
|
|
|
|
|
var _card_under_mouse_override: TableCard = null
|
Split ui/main.gd into area helpers (no behaviour change)
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>
2026-11-09 08:14:19 -06:00
|
|
|
var _drop_card: TableCard
|
|
|
|
|
var _sel_bar: PanelContainer
|
|
|
|
|
var _sel_label: Label
|
|
|
|
|
|
2026-11-21 08:48:35 -06:00
|
|
|
## How close (screen pixels) a dragged thread must be to a card's input dot to drop on it.
|
2026-11-21 08:57:42 -06:00
|
|
|
const LINK_DROP_RADIUS := 24.0
|
Split ui/main.gd into area helpers (no behaviour change)
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>
2026-11-09 08:14:19 -06:00
|
|
|
|
|
|
|
|
|
|
|
|
|
func _init(p_main: Main) -> void:
|
|
|
|
|
m = p_main
|
|
|
|
|
|
|
|
|
|
|
2026-11-10 18:35:24 -06:00
|
|
|
## Adds a card of any kind (RollTable.create) in the middle of the view, or
|
2026-11-29 14:58:56 -06:00
|
|
|
## with its top-left corner at `at` (world coordinates). `variant` gives it a
|
|
|
|
|
## CardCatalog variant's start settings ("dice", "deck").
|
2026-11-29 16:52:41 -06:00
|
|
|
func add_table(kind: String = RollTable.KIND_ROLL, sub: String = "", at: Vector2 = Vector2.INF, variant: String = "", card_name: String = "") -> RollTable:
|
Split ui/main.gd into area helpers (no behaviour change)
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>
2026-11-09 08:14:19 -06:00
|
|
|
m.undo_redo._begin_edit()
|
2026-11-10 18:35:24 -06:00
|
|
|
var center := m.board.screen_to_world(m.board.size / 2.0) if at == Vector2.INF else at + Vector2(128, 120)
|
2026-11-29 16:52:41 -06:00
|
|
|
var item := CardCatalog.find(kind, sub, variant.get_slice(":", 0))
|
|
|
|
|
var name := card_name if card_name != "" else str(item.get("name", "New table"))
|
Split ui/main.gd into area helpers (no behaviour change)
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>
2026-11-09 08:14:19 -06:00
|
|
|
var t := RollTable.create(kind, TowerBoard.new_id("t"), name, sub)
|
|
|
|
|
if kind == RollTable.KIND_ROLL or kind == RollTable.KIND_CHECK:
|
|
|
|
|
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)
|
2026-11-29 14:58:56 -06:00
|
|
|
CardCatalog.apply_variant(t, variant)
|
2026-11-10 18:30:13 -06:00
|
|
|
t.position = Vector2(roundf(center.x - 128.0), roundf(center.y - 120.0))
|
Split ui/main.gd into area helpers (no behaviour change)
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>
2026-11-09 08:14:19 -06:00
|
|
|
m.data.tables.append(t)
|
|
|
|
|
var card := TableCard.new()
|
|
|
|
|
m.board.cards.add_child(card)
|
|
|
|
|
card.setup(m, t)
|
|
|
|
|
m.cards[t.id] = card
|
|
|
|
|
m.undo_redo._end_edit()
|
|
|
|
|
if m.mode == Main.Mode.BUILD:
|
|
|
|
|
m.select_card(t.id)
|
|
|
|
|
return t
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## Adds a variable card declaring @`var_name` (labelled `label`) beside the
|
|
|
|
|
## view's centre, for the value pickers' "+ New value…". An existing card
|
|
|
|
|
## for that name is returned as it is.
|
|
|
|
|
func add_variable_card(label: String, var_name: String, type: String = "number") -> RollTable:
|
|
|
|
|
var have := m.variable_card(var_name)
|
|
|
|
|
if have:
|
|
|
|
|
return have
|
|
|
|
|
m.undo_redo._begin_edit()
|
|
|
|
|
var center := m.board.screen_to_world(m.board.size / 2.0)
|
|
|
|
|
var t := RollTable.create(RollTable.KIND_VARIABLE, TowerBoard.new_id("t"), label, type)
|
|
|
|
|
t.var_name = _free_var_name(var_name)
|
2026-11-10 18:30:13 -06:00
|
|
|
t.position = Vector2(roundf(center.x - 300.0), roundf(center.y + 40.0))
|
Split ui/main.gd into area helpers (no behaviour change)
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>
2026-11-09 08:14:19 -06:00
|
|
|
m.data.tables.append(t)
|
|
|
|
|
var card := TableCard.new()
|
|
|
|
|
m.board.cards.add_child(card)
|
|
|
|
|
card.setup(m, t)
|
|
|
|
|
m.cards[t.id] = card
|
|
|
|
|
m.undo_redo._end_edit("Add value %s" % label)
|
|
|
|
|
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 m.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:
|
|
|
|
|
m.undo_redo._begin_edit()
|
|
|
|
|
m.data.tables = SampleBoard.create().tables
|
|
|
|
|
m.data.groups.clear()
|
|
|
|
|
m.lit_entries.clear()
|
|
|
|
|
m.lit_pipes.clear()
|
|
|
|
|
m.undo_redo._keep_history = true
|
|
|
|
|
m._rebuild_cards()
|
|
|
|
|
m.undo_redo._keep_history = false
|
|
|
|
|
m.undo_redo._end_edit("Reset sample")
|
|
|
|
|
await m.get_tree().process_frame
|
|
|
|
|
await m.get_tree().process_frame
|
|
|
|
|
m.board.fit()
|
2026-11-10 18:24:23 -06:00
|
|
|
m.toast("Spread reset to the sample tables", true)
|
Split ui/main.gd into area helpers (no behaviour change)
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>
2026-11-09 08:14:19 -06:00
|
|
|
|
|
|
|
|
|
|
|
|
|
func add_entry(tid: String) -> void:
|
|
|
|
|
m.undo_redo._begin_edit()
|
|
|
|
|
var t := m.data.get_table(tid)
|
|
|
|
|
var e := TableEntry.new(TowerBoard.new_id("e"), "Result %d" % (t.entries.size() + 1))
|
2026-11-15 12:29:52 -06:00
|
|
|
if RangeWeights.uses_weights(t):
|
|
|
|
|
e.has_range = true
|
|
|
|
|
e.weight = 1
|
|
|
|
|
e.text = "New result"
|
|
|
|
|
t.entries.append(e)
|
|
|
|
|
RangeWeights.reflow(t)
|
|
|
|
|
elif t.is_ranged():
|
Split ui/main.gd into area helpers (no behaviour change)
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>
2026-11-09 08:14:19 -06:00
|
|
|
var hi := 0
|
|
|
|
|
for x in t.entries:
|
|
|
|
|
hi = maxi(hi, x.range_hi)
|
|
|
|
|
e.has_range = true
|
2026-11-09 10:01:10 -06:00
|
|
|
# A table with a modifier grows past its dice; others stay within them.
|
|
|
|
|
e.range_lo = hi + 1 if t.has_mod() else clampi(hi + 1, t.min_value(), t.die_size())
|
Split ui/main.gd into area helpers (no behaviour change)
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>
2026-11-09 08:14:19 -06:00
|
|
|
e.range_hi = e.range_lo
|
|
|
|
|
e.text = "New range"
|
2026-11-15 12:29:52 -06:00
|
|
|
if not t.entries.has(e):
|
|
|
|
|
t.entries.append(e)
|
Split ui/main.gd into area helpers (no behaviour change)
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>
2026-11-09 08:14:19 -06:00
|
|
|
t.collapsed = false
|
|
|
|
|
m.card_for(tid).rebuild()
|
|
|
|
|
m.undo_redo._end_edit()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func delete_entry(tid: String, eid: String) -> void:
|
|
|
|
|
var t := m.data.get_table(tid)
|
|
|
|
|
var e := t.find_entry(eid)
|
|
|
|
|
if e == null:
|
|
|
|
|
return
|
|
|
|
|
m.undo_redo._begin_edit()
|
|
|
|
|
t.entries.erase(e)
|
|
|
|
|
m.card_for(tid).rebuild()
|
|
|
|
|
m.undo_redo._end_edit()
|
|
|
|
|
m.toast("Deleted “%s”" % e.text, true)
|
|
|
|
|
|
|
|
|
|
|
2026-11-14 14:28:59 -06:00
|
|
|
## Deletes a card. `commit` false leaves the undo step to the caller (several
|
|
|
|
|
## at once, DeleteKey).
|
|
|
|
|
func delete_table(tid: String, commit: bool = true) -> void:
|
Split ui/main.gd into area helpers (no behaviour change)
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>
2026-11-09 08:14:19 -06:00
|
|
|
var t := m.data.get_table(tid)
|
|
|
|
|
if t == null:
|
|
|
|
|
return
|
2026-11-14 14:28:59 -06:00
|
|
|
if commit:
|
|
|
|
|
m.undo_redo._begin_edit()
|
Split ui/main.gd into area helpers (no behaviour change)
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>
2026-11-09 08:14:19 -06:00
|
|
|
var in_group := m.data.group_of(tid)
|
|
|
|
|
m.data.remove_table(tid)
|
|
|
|
|
m.local_state.forget_table_state(tid)
|
|
|
|
|
m.selection.erase(tid)
|
|
|
|
|
var card := m.card_for(tid)
|
|
|
|
|
m.cards.erase(tid)
|
|
|
|
|
if card:
|
|
|
|
|
card.queue_free()
|
|
|
|
|
for c in m.cards.values():
|
|
|
|
|
(c as TableCard).rebuild()
|
|
|
|
|
if in_group:
|
|
|
|
|
m.grouping._groups_changed()
|
|
|
|
|
_update_selection_bar()
|
2026-11-14 14:28:59 -06:00
|
|
|
if commit:
|
|
|
|
|
m.undo_redo._end_edit()
|
|
|
|
|
m.toast("Deleted %s" % t.name, true)
|
Split ui/main.gd into area helpers (no behaviour change)
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>
2026-11-09 08:14:19 -06:00
|
|
|
|
|
|
|
|
|
|
|
|
|
func remove_pipe(key: String) -> void:
|
|
|
|
|
var from := key.get_slice(">", 0)
|
|
|
|
|
var to := key.get_slice(">", 1)
|
|
|
|
|
var t := m.data.get_table(from.get_slice(":", 0))
|
|
|
|
|
var target := m.data.get_table(to)
|
|
|
|
|
if t == null:
|
|
|
|
|
return
|
|
|
|
|
var e := t.find_entry(from.get_slice(":", 1))
|
|
|
|
|
if e == null:
|
|
|
|
|
return
|
|
|
|
|
m.undo_redo._begin_edit()
|
|
|
|
|
e.pipes.erase(to)
|
|
|
|
|
m.lit_pipes.erase(key)
|
|
|
|
|
m.board.pipes.hover_key = ""
|
|
|
|
|
var card := m.card_for(t.id)
|
|
|
|
|
if card:
|
|
|
|
|
card.rebuild()
|
|
|
|
|
m.undo_redo._end_edit()
|
2026-11-16 10:41:13 -06:00
|
|
|
if e == t.outlet:
|
|
|
|
|
m.toast("Deleted card thread from %s to %s" % [t.name, target.name if target else to], true)
|
|
|
|
|
else:
|
|
|
|
|
m.toast("Deleted thread from “%s” to %s" % [e.text, target.name if target else to], true)
|
Split ui/main.gd into area helpers (no behaviour change)
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>
2026-11-09 08:14:19 -06:00
|
|
|
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
|
|
|
2026-11-21 08:57:42 -06:00
|
|
|
## The input dot a dragged thread would land on if dropped now, or null when
|
|
|
|
|
## the mouse is not within LINK_DROP_RADIUS of one (the preview snaps to it).
|
|
|
|
|
func link_snap_point() -> Variant:
|
|
|
|
|
var card := _card_under_mouse()
|
|
|
|
|
if card == null or card.table.kind == RollTable.KIND_VARIABLE:
|
|
|
|
|
return null
|
|
|
|
|
var mouse := m.board.world.get_local_mouse_position()
|
|
|
|
|
return card.inlet_point() if card.inlet_point().distance_to(mouse) <= LINK_DROP_RADIUS / m.board.zoom else null
|
|
|
|
|
|
|
|
|
|
|
Split ui/main.gd into area helpers (no behaviour change)
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>
2026-11-09 08:14:19 -06:00
|
|
|
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 := m.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:
|
2026-11-10 18:24:23 -06:00
|
|
|
m.toast("Variable cards aren't rolled, so threads can't lead into them. Use a change such as @%s += 1." % over.table.var_name)
|
Split ui/main.gd into area helpers (no behaviour change)
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>
2026-11-09 08:14:19 -06:00
|
|
|
return
|
|
|
|
|
m.undo_redo._begin_edit()
|
2026-11-09 12:22:56 -06:00
|
|
|
# A result may pipe into several cards (fan-out); a new pipe adds to the others.
|
|
|
|
|
e.add_pipe(over.table.id)
|
Split ui/main.gd into area helpers (no behaviour change)
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>
2026-11-09 08:14:19 -06:00
|
|
|
m.card_for(t.id).rebuild()
|
|
|
|
|
m.undo_redo._end_edit()
|
2026-11-16 10:41:13 -06:00
|
|
|
if e == t.outlet:
|
|
|
|
|
m.toast("After any result of %s, %s rolls" % [t.name, over.table.name], true)
|
|
|
|
|
else:
|
|
|
|
|
m.toast("“%s” now rolls on %s" % [e.text, over.table.name], true)
|
Split ui/main.gd into area helpers (no behaviour change)
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>
2026-11-09 08:14:19 -06:00
|
|
|
|
|
|
|
|
|
|
|
|
|
func _card_under_mouse() -> TableCard:
|
2026-11-16 10:41:13 -06:00
|
|
|
if _card_under_mouse_override:
|
|
|
|
|
return _card_under_mouse_override
|
2026-11-21 08:48:35 -06:00
|
|
|
var mouse := m.board.world.get_local_mouse_position()
|
|
|
|
|
var reach := LINK_DROP_RADIUS / m.board.zoom
|
Split ui/main.gd into area helpers (no behaviour change)
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>
2026-11-09 08:14:19 -06:00
|
|
|
var kids := m.board.cards.get_children()
|
|
|
|
|
for i in range(kids.size() - 1, -1, -1):
|
|
|
|
|
var card := kids[i] as TableCard
|
2026-11-21 08:48:35 -06:00
|
|
|
if card and card.visible and (m.board.world_rect_of(card).has_point(mouse) or (card.table.kind != RollTable.KIND_VARIABLE and card.inlet_point().distance_to(mouse) <= reach)):
|
Split ui/main.gd into area helpers (no behaviour change)
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>
2026-11-09 08:14:19 -06:00
|
|
|
return card
|
|
|
|
|
return null
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# ----- Selection (Build) -----
|
|
|
|
|
|
|
|
|
|
func is_selected(tid: String) -> bool:
|
|
|
|
|
return m.selection.has(tid)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func toggle_selected(tid: String) -> void:
|
|
|
|
|
var c := m.card_for(tid)
|
|
|
|
|
if c == null or not c.visible:
|
|
|
|
|
return
|
|
|
|
|
if m.selection.has(tid):
|
|
|
|
|
m.selection.erase(tid)
|
|
|
|
|
else:
|
|
|
|
|
m.selection[tid] = true
|
|
|
|
|
c.set_selected(m.selection.has(tid))
|
|
|
|
|
_update_selection_bar()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func set_selection(ids: Array) -> void:
|
|
|
|
|
clear_selection()
|
|
|
|
|
for tid: Variant in ids:
|
|
|
|
|
var c := m.card_for(str(tid))
|
|
|
|
|
if c and c.visible:
|
|
|
|
|
m.selection[str(tid)] = true
|
|
|
|
|
c.set_selected(true)
|
|
|
|
|
_update_selection_bar()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func clear_selection() -> void:
|
|
|
|
|
for tid: String in m.selection:
|
|
|
|
|
var c := m.card_for(tid)
|
|
|
|
|
if c:
|
|
|
|
|
c.set_selected(false)
|
|
|
|
|
m.selection.clear()
|
2026-11-10 18:30:13 -06:00
|
|
|
m.selecting.clear()
|
Split ui/main.gd into area helpers (no behaviour change)
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>
2026-11-09 08:14:19 -06:00
|
|
|
_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 m.cards:
|
|
|
|
|
var c: TableCard = m.cards[tid]
|
|
|
|
|
if c.visible and Rect2(c.position, c.size).intersects(r):
|
|
|
|
|
m.selection[tid] = true
|
|
|
|
|
c.set_selected(true)
|
2026-11-10 18:30:13 -06:00
|
|
|
m.selecting.select_in_rect(r)
|
Split ui/main.gd into area helpers (no behaviour change)
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>
2026-11-09 08:14:19 -06:00
|
|
|
_update_selection_bar()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func _build_selection_bar() -> void:
|
|
|
|
|
_sel_bar = PanelContainer.new()
|
Theme system: runtime colour tokens, theme sets and a Theme dialog
Style's colours become static vars named by role (BG, PANEL, CARD, THREAD,
ACCENT, TRIM, GLOW…) instead of materials (felt, copper, brass), so a theme
can replace them. Stray hard-coded colours moved into tokens.
ThemeStore applies built-in sets (Tarot, the new default: jewel-purple
cloth with a shine; Felt, the old look) and the user's own sets from
user://themes/. Fills for the background and panels can be gradients; the
background pattern (dots, stars, none) and logo are per set. View ▾ →
Theme… edits a set; changes to a built-in save as a new set. Using a theme
reloads the UI and keeps the open spread.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-10 18:10:16 -06:00
|
|
|
var sb := Style.box(Style.BG_DEEP, 10, [14, 7, 8, 7])
|
Split ui/main.gd into area helpers (no behaviour change)
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>
2026-11-09 08:14:19 -06:00
|
|
|
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)
|
Theme system: runtime colour tokens, theme sets and a Theme dialog
Style's colours become static vars named by role (BG, PANEL, CARD, THREAD,
ACCENT, TRIM, GLOW…) instead of materials (felt, copper, brass), so a theme
can replace them. Stray hard-coded colours moved into tokens.
ThemeStore applies built-in sets (Tarot, the new default: jewel-purple
cloth with a shine; Felt, the old look) and the user's own sets from
user://themes/. Fills for the background and panels can be gradients; the
background pattern (dots, stars, none) and logo are per set. View ▾ →
Theme… edits a set; changes to a built-in save as a new set. Using a theme
reloads the UI and keeps the open spread.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-10 18:10:16 -06:00
|
|
|
_sel_label = Style.make_label("", Style.body_bold(), 15, Style.ON_BG)
|
Split ui/main.gd into area helpers (no behaviour change)
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>
2026-11-09 08:14:19 -06:00
|
|
|
_sel_label.size_flags_vertical = Control.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: m.grouping.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(m.templating.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()
|
|
|
|
|
m.board.add_child(_sel_bar)
|
|
|
|
|
m.board.resized.connect(_place_selection_bar)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func _update_selection_bar() -> void:
|
|
|
|
|
if _sel_bar == null:
|
|
|
|
|
return
|
|
|
|
|
var n := m.selection.size()
|
2026-11-10 18:30:13 -06:00
|
|
|
_sel_bar.visible = n + m.selecting.groups.size() > 0 and m.mode == Main.Mode.BUILD
|
|
|
|
|
_sel_label.text = m.selecting.describe(n) + " selected"
|
Split ui/main.gd into area helpers (no behaviour change)
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>
2026-11-09 08:14:19 -06:00
|
|
|
_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((m.board.size.x - _sel_bar.size.x) / 2.0, 14.0)
|