Move choice, router and ledger sections of the inspector card into InspectorChoice, InspectorRouter and InspectorCollection, and the collapsed group card build into GroupCardCompact. InspectorCard keeps one-line delegators for its public functions, so no caller changes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
105 lines
5.1 KiB
GDScript
105 lines
5.1 KiB
GDScript
class_name InspectorChoice
|
|
extends RefCounted
|
|
## The choice card's part of the inspector: the question, its type (pick,
|
|
## number, ...), where the answer is saved, the allowed numbers, and for pick
|
|
## cards whether the options are a fixed list or come from a value.
|
|
## InspectorCard.build() calls build() for choice cards.
|
|
|
|
|
|
static func build(insp: Inspector, box: VBoxContainer, card: RollTable, plain: bool) -> void:
|
|
var err := InspectorKit.error_label()
|
|
var seg := ModalCard.segmented(Describe.choice_labels(), maxi(0, RollTable.CHOICES.find(card.choice)), func(i: int) -> void:
|
|
InspectorKit.show_error(err, insp.apply_settings({"choice": RollTable.CHOICES[i]}, true))
|
|
)
|
|
box.add_child(InspectorKit.field("Type", seg))
|
|
var question := InspectorKit.line(card.prompt, "Which one?")
|
|
InspectorKit.tag(question, "card.prompt")
|
|
question.text_changed.connect(func(text: String) -> void: insp.apply_settings({"prompt": text}))
|
|
insp.fields["prompt"] = question
|
|
box.add_child(InspectorKit.field("Question", question))
|
|
var save := InspectorKit.line(card.save_as, "nothing (e.g. career, or @career to keep)")
|
|
InspectorKit.tag(save, "card.save_as")
|
|
insp.fields["save_as"] = save
|
|
save.text_changed.connect(func(text: String) -> void:
|
|
var msg := Inspector._save_error(text)
|
|
InspectorKit.mark(save, msg == "")
|
|
InspectorKit.show_error(err, msg if msg != "" else insp.apply_settings({"save_as": text}))
|
|
)
|
|
box.add_child(InspectorKit.field("Save the answer as", save))
|
|
if card.choice == "number":
|
|
var row := InspectorKit.flow()
|
|
row.add_child(InspectorKit.word("From"))
|
|
var low := InspectorKit.amount(card.min_expr, "0")
|
|
var high := InspectorKit.amount(card.max_expr, "99")
|
|
InspectorKit.tag(low, "card.min")
|
|
InspectorKit.tag(high, "card.max")
|
|
low.text_changed.connect(func(text: String) -> void: InspectorKit.show_error(err, insp.apply_settings({"min": text, "max": high.text})))
|
|
high.text_changed.connect(func(text: String) -> void: InspectorKit.show_error(err, insp.apply_settings({"min": low.text, "max": text})))
|
|
row.add_child(low)
|
|
row.add_child(InspectorKit.word("to"))
|
|
row.add_child(high)
|
|
box.add_child(InspectorKit.field("Allowed answers", row))
|
|
if card.choice == "pick":
|
|
box.add_child(_options(insp, card, plain, err))
|
|
box.add_child(err)
|
|
|
|
|
|
## Pick cards: Fixed list, or From [collection or list ▾] where [condition].
|
|
static func _options(insp: Inspector, card: RollTable, plain: bool, err: Label) -> Control:
|
|
var main := insp.main
|
|
var column := InspectorKit.vbox(6)
|
|
var dynamic := card.is_dynamic()
|
|
var from_picker := ValuePicker.new(main, card.options_from)
|
|
from_picker.kinds = ["collection", "list"]
|
|
from_picker.allow_patterns = true
|
|
from_picker.placeholder = "a ledger or list"
|
|
insp.fields["options_from"] = from_picker
|
|
var seg := ModalCard.segmented(["Fixed list", "From a value"], 1 if dynamic else 0, func(i: int) -> void:
|
|
if i == 0:
|
|
InspectorKit.show_error(err, insp.apply_settings({"options_mode": "fixed"}, true))
|
|
else:
|
|
var first := _first_source(main.data)
|
|
if first == "":
|
|
InspectorKit.show_error(err, "Add a ledger (+ Card ▾ → Ledger) or a list value first, then pick it here.")
|
|
return
|
|
InspectorKit.show_error(err, set_options(insp, first, ""))
|
|
)
|
|
column.add_child(seg)
|
|
if dynamic:
|
|
var row := InspectorKit.flow()
|
|
row.add_child(InspectorKit.word("From"))
|
|
from_picker.value_chosen.connect(func(value_name: String) -> void:
|
|
InspectorKit.show_error(err, set_options(insp, value_name, card.options_where)))
|
|
row.add_child(from_picker)
|
|
column.add_child(row)
|
|
var where := ConditionBuilder.new()
|
|
where.setup(main, card.options_where, not plain, "card.where", {"empty_note": "Every one is offered.",
|
|
"extras": [{"name": "option_value", "label": "Its value", "kind": "number"}, {"name": "option_label", "label": "Its name", "kind": "text"}],
|
|
"add_label": "+ Only where…"})
|
|
where.changed.connect(func(text: String) -> void:
|
|
if TableSettingsDialog.when_error(text) == "":
|
|
InspectorKit.show_error(err, set_options(insp, card.options_from, text)))
|
|
insp.fields["options_where"] = where
|
|
column.add_child(InspectorKit.word("where", Style.MUTED))
|
|
column.add_child(where)
|
|
var desc := Describe.options(card, main.data)
|
|
if desc != "" and plain:
|
|
column.add_child(InspectorKit.note("Offers %s, plus the fixed options. The Chosen result runs for the one picked." % desc, Style.MUTED, 13))
|
|
else:
|
|
column.add_child(InspectorKit.note("The player picks one of the card's results, or Random.", Style.MUTED, 13))
|
|
return InspectorKit.field("Options", column)
|
|
|
|
|
|
## The first collection (@stem_*) or list value on the board, or "".
|
|
static func _first_source(board: TowerBoard) -> String:
|
|
for known: Dictionary in Builder.known_values(board):
|
|
if str(known["kind"]) == "collection" or str(known["kind"]) == "list":
|
|
return str(known["name"])
|
|
return ""
|
|
|
|
|
|
## Options from `from` where `where` (a pick card). Returns "" or the problem.
|
|
static func set_options(insp: Inspector, from: String, where: String) -> String:
|
|
var card := insp.selected_table()
|
|
var was := card.is_dynamic()
|
|
return insp.apply_settings({"options_mode": "vars", "options_from": from, "options_where": where}, not was or from != card.options_from)
|