Deck-mode cards fade the results already drawn until the deck is shuffled. The inspector gets a Deck mode section (Draw without repeats; when empty, Shuffle by itself or Wait for Shuffle; the Empty result's text, saved as deck_empty_text). A waiting empty deck gives its Empty result in normal ink, not as an error. Reshuffle reads Shuffle everywhere. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
104 lines
4.6 KiB
GDScript
104 lines
4.6 KiB
GDScript
class_name InspectorRoll
|
||
extends RefCounted
|
||
## The inspector's section for a roll table: Plain or Ranged, the dice, the
|
||
## modifier (ModifierEditor) and a live sentence ("Roll d20 + Luck") with
|
||
## what the modifier does now. Writes go through Inspector.apply_settings, so
|
||
## the settings dialog's rules apply.
|
||
|
||
|
||
static func build(insp: Inspector, box: VBoxContainer, t: RollTable, plain: bool) -> void:
|
||
var v := InspectorKit.vbox(6)
|
||
var ranged := t.is_ranged()
|
||
var dice := InspectorKit.line(t.dice, "2d6", 90.0)
|
||
InspectorKit.tag(dice, "card.dice")
|
||
insp.fields["dice"] = dice
|
||
var err := InspectorKit.error_label()
|
||
var seg := ModalCard.segmented(["Plain", "Ranged"], 1 if ranged else 0, func(i: int) -> void:
|
||
var msg := insp.apply_settings({"ranged": i == 1, "dice": dice.text.strip_edges() if dice.text.strip_edges() != "" else "1d6"}, true)
|
||
InspectorKit.show_error(err, msg)
|
||
)
|
||
v.add_child(seg)
|
||
if not ranged:
|
||
v.add_child(InspectorKit.note("Each result is equally likely, unless you give it a weight on the card. Switch to Ranged to add a modifier to the roll.", Style.MUTED, 13))
|
||
v.add_child(err)
|
||
box.add_child(InspectorKit.field("Rolls", v))
|
||
return
|
||
var row := InspectorKit.hbox(6)
|
||
row.add_child(InspectorKit.word("Roll"))
|
||
row.add_child(dice)
|
||
v.add_child(row)
|
||
dice.text_changed.connect(func(s: String) -> void:
|
||
if not TableSettingsDialog.dice_ok_text(s):
|
||
InspectorKit.show_error(err, "“%s” isn't dice such as 2d6 or 1d100." % s.strip_edges())
|
||
InspectorKit.mark(dice, false)
|
||
return
|
||
InspectorKit.mark(dice, true)
|
||
InspectorKit.show_error(err, insp.apply_settings({"ranged": true, "dice": s.strip_edges()}))
|
||
)
|
||
v.add_child(err)
|
||
box.add_child(InspectorKit.field("Rolls", v))
|
||
|
||
var mod := ModifierEditor.new(insp.main, t.dice_mod, plain, "card.dice_mod")
|
||
insp.fields["dice_mod"] = mod
|
||
var merr := InspectorKit.error_label()
|
||
mod.changed.connect(func(s: String) -> void: InspectorKit.show_error(merr, insp.apply_settings({"dice_mod": s})))
|
||
var mbox := InspectorKit.vbox(5)
|
||
mbox.add_child(mod)
|
||
mbox.add_child(merr)
|
||
box.add_child(InspectorKit.field("Modifier", mbox))
|
||
|
||
# A live sentence, what the modifier does, and any range problems.
|
||
var sentence := InspectorKit.note("", Style.INK, 14)
|
||
sentence.add_theme_font_override("font", Style.body_bold())
|
||
var how := InspectorKit.note("", Style.MUTED, 13)
|
||
var probs := InspectorKit.note("", Style.WARN_INK, 13)
|
||
insp.fields["roll_sentence"] = sentence
|
||
insp.fields["roll_help"] = how
|
||
box.add_child(sentence)
|
||
box.add_child(how)
|
||
box.add_child(probs)
|
||
var refresh := func() -> void:
|
||
sentence.text = RulesView.roll_line(t, insp.main.data, plain)
|
||
how.text = help(t, insp.main)
|
||
how.visible = how.text != ""
|
||
probs.text = t.range_problems()
|
||
probs.visible = probs.text != ""
|
||
insp._live.append(refresh)
|
||
refresh.call()
|
||
|
||
|
||
## Deck mode: draw results without repeats, and what an empty deck does.
|
||
static func deck(insp: Inspector, box: VBoxContainer, t: RollTable) -> void:
|
||
var v := InspectorKit.vbox(6)
|
||
var on := InspectorKit.check_box("Draw without repeats", t.card_mode)
|
||
on.tooltip_text = "Each result is dealt like a card and stays out until the deck is shuffled"
|
||
on.toggled.connect(func(b: bool) -> void: insp.apply_settings({"card_mode": b}, true))
|
||
v.add_child(on)
|
||
if t.card_mode:
|
||
v.add_child(InspectorKit.note("When the deck is empty:", Style.MUTED, 13))
|
||
v.add_child(ModalCard.segmented(["Shuffle by itself", "Wait for Shuffle"], 1 if t.deck_empty == "stop" else 0, func(i: int) -> void:
|
||
insp.apply_settings({"deck_empty": "stop" if i == 1 else "reshuffle"}, true)))
|
||
if t.deck_empty == "stop":
|
||
var empty := InspectorKit.line(t.deck_empty_text, "Empty")
|
||
empty.tooltip_text = "What the card gives while its deck is empty"
|
||
empty.text_changed.connect(func(s: String) -> void:
|
||
t.deck_empty_text = s.strip_edges()
|
||
insp.wrote(t))
|
||
v.add_child(InspectorKit.field("Empty result", empty))
|
||
box.add_child(InspectorKit.field("Deck mode", v))
|
||
|
||
|
||
## What a ranged table's modifier means, in words: the dice's own range, the
|
||
## modifier's value now, and how the ends work. "" without a modifier.
|
||
static func help(t: RollTable, main: Main) -> String:
|
||
if not t.has_mod():
|
||
return ""
|
||
var parts := PackedStringArray()
|
||
if not t.is_expr_dice():
|
||
var nat := RollRange.natural(t)
|
||
parts.append("The dice alone roll %s–%s." % [t.fmt(nat.x), t.fmt(nat.y)])
|
||
var lm := RollRange.live_mod(t, Roller.live_context(main.data, main.persistent_vars))
|
||
if lm["known"]:
|
||
parts.append("The modifier is %s right now." % Describe.signed_number(int(lm["value"])))
|
||
parts.append("A total past the lowest or highest result counts as that result.")
|
||
return " ".join(parts)
|