TableTower/ui/spread_link_dialog.gd
RobinFiredrake 2ed91e7acd Spreads can roll cards from other spreads: [[Spread::Card]]
A result's text can name a card in another spread, as "[[Treasure::Loot]]".
It rolls there (its own threads and references resolve in that spread)
and its changes apply to this spread's values. The inspector has
"+ Roll a card from another spread…" to pick one. Links show as
"Treasure › Loot" chips; nodes from there are marked so this spread's
cards aren't lit for them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-14 14:45:01 -06:00

45 lines
1.9 KiB
GDScript

class_name SpreadLinkDialog
extends RefCounted
## "Roll a card from another spread…" in a result's inspector: pick a spread,
## then one of its cards; on Insert, [[Spread::Card]] goes at the end of the
## result's text (SpreadLinks rolls it).
static func open(main: Main, on_pick: Callable) -> void:
if main.library == null:
main.toast("Other spreads can't be read in this session")
return
var spreads: Array = main.library.list().filter(func(entry: Dictionary) -> bool: return str(entry["id"]) != main.data.id)
if spreads.is_empty():
main.toast("There's no other spread yet")
return
var dialog := ModalCard.new("Roll a card from another spread", 440.0)
var spread_pick := OptionButton.new()
ModalCard.style_popup(spread_pick.get_popup())
for entry: Dictionary in spreads:
spread_pick.add_item(str(entry["name"]))
dialog.body.add_child(ModalCard.field("Spread", spread_pick))
var card_pick := OptionButton.new()
ModalCard.style_popup(card_pick.get_popup())
dialog.body.add_child(ModalCard.field("Card", card_pick))
dialog.body.add_child(ModalCard.note("When this result comes up, that card rolls in its own spread, and its result goes into this text. Its changes apply to this spread's values."))
var names: Array[String] = []
var fill_cards := func(index: int) -> void:
card_pick.clear()
names.clear()
var board := main.library.load_collection(str(spreads[index]["id"]))
if board == null:
return
for table in board.tables:
if table.kind != RollTable.KIND_VARIABLE:
names.append(Formatter.strip_tags(table.name).strip_edges())
card_pick.add_item(names.back())
spread_pick.item_selected.connect(fill_cards)
fill_cards.call(0)
dialog.add_button("Cancel", "plain", dialog.close)
dialog.add_button("Insert", "primary", func() -> void:
if card_pick.selected < 0:
return
dialog.close()
on_pick.call("[[%s%s%s]]" % [str(spreads[spread_pick.selected]["name"]), SpreadLinks.SEP, names[card_pick.selected]]))
main._add_modal(dialog)