46 lines
1.9 KiB
GDScript3
46 lines
1.9 KiB
GDScript3
|
|
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)
|