Deck mode: faded drawn results, Wait for Shuffle with an Empty result

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>
This commit is contained in:
RobinFiredrake 2026-11-10 18:43:16 -06:00
parent 1358678889
commit f00f36b598
14 changed files with 97 additions and 15 deletions

View file

@ -38,6 +38,11 @@ static func copies_of(table: RollTable, e: TableEntry) -> int:
return maxi(0, e.weight) return maxi(0, e.weight)
## How many copies of this result are still in the deck.
func remaining(table: RollTable, e: TableEntry) -> int:
return _remaining(table, e)
func _remaining(table: RollTable, e: TableEntry) -> int: func _remaining(table: RollTable, e: TableEntry) -> int:
return maxi(0, copies_of(table, e) - int(drawn.get(e.id, 0))) return maxi(0, copies_of(table, e) - int(drawn.get(e.id, 0)))

View file

@ -22,7 +22,8 @@ static func pick_node(t: RollTable, ctx: RollContext) -> Dictionary:
return Roller._stop(t, "This table has no results") return Roller._stop(t, "This table has no results")
if deck.cards_left(t).x <= 0: if deck.cards_left(t).x <= 0:
if t.deck_empty == "stop": if t.deck_empty == "stop":
return Roller._stop(t, "Deck empty") # Waits for Shuffle: the card gives its empty result and the chain ends here.
return Roller._stop(t, t.empty_text(), {"deck_empty": true})
deck.reshuffle() deck.reshuffle()
reshuffled = true reshuffled = true
var card := deck.draw(t, rng) var card := deck.draw(t, rng)

View file

@ -65,6 +65,8 @@ var dice_mod: String = ""
var card_mode: bool = false var card_mode: bool = false
## What happens when the deck runs out: "reshuffle" or "stop". ## What happens when the deck runs out: "reshuffle" or "stop".
var deck_empty: String = "reshuffle" var deck_empty: String = "reshuffle"
## What a Deck-mode card that waits for Shuffle gives once it's empty ("" = "Empty").
var deck_empty_text: String = ""
var entries: Array[TableEntry] = [] var entries: Array[TableEntry] = []
## One of KINDS. ## One of KINDS.
@ -390,6 +392,11 @@ func find_entry(eid: String) -> TableEntry:
## Gaps, overlaps and out-of-reach ranges, or "" when clean (RollRange.problems). ## Gaps, overlaps and out-of-reach ranges, or "" when clean (RollRange.problems).
## The result an empty Deck-mode card gives when it waits for Shuffle.
func empty_text() -> String:
return deck_empty_text if deck_empty_text.strip_edges() != "" else "Empty"
func range_problems() -> String: func range_problems() -> String:
return RollRange.problems(self) return RollRange.problems(self)
@ -441,6 +448,8 @@ func to_dict() -> Dictionary:
d["card_mode"] = true d["card_mode"] = true
if deck_empty != "reshuffle": if deck_empty != "reshuffle":
d["deck_empty"] = deck_empty d["deck_empty"] = deck_empty
if deck_empty_text != "":
d["deck_empty_text"] = deck_empty_text
if kind == KIND_CHOICE: if kind == KIND_CHOICE:
if choice != "pick": if choice != "pick":
d["choice"] = choice d["choice"] = choice
@ -507,6 +516,7 @@ static func from_dict(d: Dictionary) -> RollTable:
t.dice_mod = expr_text(d.get("dice_mod", ""), "").strip_edges() t.dice_mod = expr_text(d.get("dice_mod", ""), "").strip_edges()
t.card_mode = bool(d.get("card_mode", false)) t.card_mode = bool(d.get("card_mode", false))
t.deck_empty = "stop" if str(d.get("deck_empty", "reshuffle")) == "stop" else "reshuffle" t.deck_empty = "stop" if str(d.get("deck_empty", "reshuffle")) == "stop" else "reshuffle"
t.deck_empty_text = str(d.get("deck_empty_text", ""))
var k := str(d.get("kind", KIND_ROLL)) var k := str(d.get("kind", KIND_ROLL))
t.kind = k if KINDS.has(k) else KIND_ROLL t.kind = k if KINDS.has(k) else KIND_ROLL
var c := str(d.get("choice", "pick")) var c := str(d.get("choice", "pick"))

View file

@ -36,7 +36,7 @@ static func step_of(n: Dictionary, depth: int = 0) -> Dictionary:
step["kind"] = n["kind"] step["kind"] = n["kind"]
if n.has("effects"): if n.has("effects"):
step["effects"] = (n["effects"] as Array).duplicate(true) step["effects"] = (n["effects"] as Array).duplicate(true)
for k in ["answer", "passes", "pass", "after", "picked", "random", "limit", "cancelled", "case", "option", "check", "inputs"]: for k in ["answer", "passes", "pass", "after", "picked", "random", "limit", "cancelled", "deck_empty", "case", "option", "check", "inputs"]:
if n.has(k): if n.has(k):
step[k] = n[k] step[k] = n[k]
if n.has("why"): if n.has("why"):

View file

@ -80,12 +80,12 @@ Deck mode decks ignore the modifier.
# Deck mode # Deck mode
[b]Deck mode[/b] turns a table into a deck of cards. Each result is dealt once, with no repeats, until the deck runs out. [b]Deck mode[/b] turns a table into a deck of cards. Each result is dealt once, with no repeats, until the deck runs out.
- Turn it on in [b]Table settings… → Deck mode[/b]. - Turn it on in the inspector (Build mode: click the card's name) under [b]Deck mode → Draw without repeats[/b].
- The card shows how many are left, for example [b]4 / 6 left[/b]. - The card shows how many are left, for example [b]4 / 6 left[/b], and results already drawn are faded.
- [b]↻ Reshuffle[/b] under the card's name puts every card back. - [b]↻ Shuffle[/b] under the card's name puts every card back. [b]Shuffle all decks[/b] (right-click the spread, or ☰) does every deck at once.
- [b]When the deck runs out[/b] can reshuffle by itself or stop until you reshuffle. - [b]When the deck is empty[/b] it can shuffle by itself, or wait for you to shuffle. While it waits, rolling it gives its [b]Empty result[/b] (“Empty” unless you write something else) and the roll goes no further.
[b]Party Roles[/b] in the sample is a deck: hand one role to each player, and nobody gets the same role twice until you reshuffle. [b]Party Roles[/b] in the sample is a deck: hand one role to each player, and nobody gets the same role twice until you shuffle.
# Choice cards # Choice cards
A choice card stops the roll and asks the player. Add one from [b]+ Card ▾[/b]. A choice card stops the roll and asks the player. Add one from [b]+ Card ▾[/b].

View file

@ -213,7 +213,7 @@ func _test_cards() -> void:
for i in 4: for i in 4:
Roller.roll(b, "deck", r, 0, d2) Roller.roll(b, "deck", r, 0, d2)
var stopped := Roller.roll(b, "deck", r, 0, d2) var stopped := Roller.roll(b, "deck", r, 0, d2)
_check(stopped.get("stop", "") == "Deck empty", "stop mode returns Deck empty") _check(stopped.get("stop", "") == "Empty" and stopped.get("deck_empty", false), "a deck that waits for Shuffle gives its Empty result")
(d2["deck"] as DeckState).reshuffle() (d2["deck"] as DeckState).reshuffle()
_check(not Roller.roll(b, "deck", r, 0, d2).has("stop"), "manual reshuffle deals again") _check(not Roller.roll(b, "deck", r, 0, d2).has("stop"), "manual reshuffle deals again")

View file

@ -20,6 +20,7 @@ func _init() -> void:
await _test_thread_lists() await _test_thread_lists()
_test_template_replace() _test_template_replace()
await _test_chip_and_export() await _test_chip_and_export()
await _test_deck_mode()
print("%s: %d failure(s)" % ["PASS" if _failures == 0 else "FAIL", _failures]) print("%s: %d failure(s)" % ["PASS" if _failures == 0 else "FAIL", _failures])
quit(1 if _failures else 0) quit(1 if _failures else 0)
@ -89,6 +90,32 @@ func _test_chip_and_export() -> void:
_check(subs.size() == 1 and (subs[0] as PopupMenu).item_count == IoMenu.EXPORTS.size() - 1, "rare formats sit under Other formats") _check(subs.size() == 1 and (subs[0] as PopupMenu).item_count == IoMenu.EXPORTS.size() - 1, "rare formats sit under Other formats")
## Deck mode: drawn results fade, an empty deck that waits for Shuffle gives
## its Empty result, and Shuffle all puts everything back.
func _test_deck_mode() -> void:
var t := main.data.get_table("party_roles")
_check(t != null and t.card_mode, "the sample's Party Roles is a deck")
t.deck_empty = "stop"
t.deck_empty_text = "No roles left"
for i in t.entries.size():
main.rolling.start_roll("party_roles", true)
await _frames(2)
var card := main.card_for("party_roles")
var faded := 0
for e in t.entries:
if card.rows.has(e.id) and (card.rows[e.id] as Control).modulate.a < 0.5:
faded += 1
_check(faded == t.entries.size(), "every drawn result is faded (%d of %d)" % [faded, t.entries.size()])
main.rolling.start_roll("party_roles", true)
await _frames(2)
var steps: Array = main.current.get("steps", [])
var last: Dictionary = steps[steps.size() - 1] if not steps.is_empty() else {}
_check(str(last.get("text", "")) == "No roles left" and last.get("deck_empty", false), "an empty deck gives its Empty result: %s" % str(last.get("text", "")))
main.local_state.reshuffle_all()
await _frames()
_check((card.rows[t.entries[0].id] as Control).modulate.a == 1.0, "Shuffle all brings them back")
func _frames(n: int = 2) -> void: func _frames(n: int = 2) -> void:
for i in n: for i in n:
await process_frame await process_frame

View file

@ -23,6 +23,7 @@ static func build(insp: Inspector, box: VBoxContainer, t: RollTable) -> void:
match t.kind: match t.kind:
RollTable.KIND_ROLL: RollTable.KIND_ROLL:
InspectorRoll.build(insp, box, t, plain) InspectorRoll.build(insp, box, t, plain)
InspectorRoll.deck(insp, box, t)
RollTable.KIND_CHECK: RollTable.KIND_CHECK:
_check(insp, box, t, plain) _check(insp, box, t, plain)
RollTable.KIND_CHOICE: RollTable.KIND_CHOICE:
@ -58,7 +59,7 @@ static func build(insp: Inspector, box: VBoxContainer, t: RollTable) -> void:
box.add_child(_inputs(insp, t)) box.add_child(_inputs(insp, t))
InspectorThreads.build(insp, box, t) InspectorThreads.build(insp, box, t)
var more := InspectorKit.link("More settings…", "Deck mode, colours and the other settings") var more := InspectorKit.link("More settings…", "Deck mode and the other settings")
more.pressed.connect(func() -> void: insp.main.open_table_settings(t.id)) more.pressed.connect(func() -> void: insp.main.open_table_settings(t.id))
box.add_child(more) box.add_child(more)

View file

@ -67,6 +67,27 @@ static func build(insp: Inspector, box: VBoxContainer, t: RollTable, plain: bool
refresh.call() 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 ## 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. ## modifier's value now, and how the ends work. "" without a modifier.
static func help(t: RollTable, main: Main) -> String: static func help(t: RollTable, main: Main) -> String:

View file

@ -113,7 +113,7 @@ func reshuffle_table(tid: String) -> void:
var card := m.card_for(tid) var card := m.card_for(tid)
if card: if card:
card.update_deck() card.update_deck()
m.toast("Reshuffled %s" % Formatter.strip_tags(t.name)) m.toast("Shuffled %s" % Formatter.strip_tags(t.name))
## Shuffles every Deck-mode card back to full. ## Shuffles every Deck-mode card back to full.

View file

@ -233,6 +233,7 @@ func rebuild() -> void:
_apply_style() _apply_style()
refresh_live() refresh_live()
_raise_covers() _raise_covers()
_dim_drawn()
if list_scroll != null: if list_scroll != null:
for eid in rows: for eid in rows:
if main.is_entry_lit(table.id, eid): if main.is_entry_lit(table.id, eid):
@ -375,6 +376,22 @@ func selected_entry() -> String:
## Refreshes the cards-left count of a card-mode table. ## Refreshes the cards-left count of a card-mode table.
func update_deck() -> void: func update_deck() -> void:
header_ui.update_deck() header_ui.update_deck()
_dim_drawn()
## Deck mode: results already drawn (none left in the deck) show faded until
## the deck is shuffled.
func _dim_drawn() -> void:
if not table.card_mode:
return
var deck: DeckState = main.decks.get(table.id)
for e in table.entries:
var row: Control = rows.get(e.id)
if row == null or not is_instance_valid(row):
continue
var gone := deck != null and deck.remaining(table, e) <= 0
row.modulate.a = 0.38 if gone else 1.0
row.tooltip_text = "Already drawn: Shuffle the deck to put it back" if gone else ""
## Re-renders the live parts (a variable's value, a sheet, a choice's ## Re-renders the live parts (a variable's value, a sheet, a choice's

View file

@ -372,7 +372,7 @@ static func draw_fork(ci: CanvasItem, c: Vector2, r: float, color: Color, width:
ci.draw_circle(base, width * 0.9, color) ci.draw_circle(base, width * 0.9, color)
## Card mode: "4 / 6 left" and a small Reshuffle link under the title. ## Deck mode: "4 / 6 left" and a small Shuffle link under the title.
func _make_deck_row() -> Control: func _make_deck_row() -> Control:
var h := TableCard.hbox(6) var h := TableCard.hbox(6)
var pad := Control.new() var pad := Control.new()
@ -384,7 +384,7 @@ func _make_deck_row() -> Control:
deck_label.mouse_filter = Control.MOUSE_FILTER_IGNORE deck_label.mouse_filter = Control.MOUSE_FILTER_IGNORE
h.add_child(deck_label) h.add_child(deck_label)
var b := Button.new() var b := Button.new()
b.text = "↻ Reshuffle" b.text = "↻ Shuffle"
b.tooltip_text = "Put every card back in the deck" b.tooltip_text = "Put every card back in the deck"
b.add_theme_font_override("font", Style.body(true)) b.add_theme_font_override("font", Style.body(true))
b.add_theme_font_size_override("font_size", 12) b.add_theme_font_size_override("font_size", 12)

View file

@ -165,8 +165,8 @@ func _build() -> void:
card_box.add_child(note("Results are dealt like cards, without repeats, until the deck runs out.")) card_box.add_child(note("Results are dealt like cards, without repeats, until the deck runs out."))
var deck := VBoxContainer.new() var deck := VBoxContainer.new()
deck.add_theme_constant_override("separation", 6) deck.add_theme_constant_override("separation", 6)
deck.add_child(section("When the deck runs out")) deck.add_child(section("When the deck is empty"))
deck.add_child(segmented(["Reshuffle", "Stop"], 1 if _deck_empty == "stop" else 0, func(i: int) -> void: deck.add_child(segmented(["Shuffle by itself", "Wait for Shuffle"], 1 if _deck_empty == "stop" else 0, func(i: int) -> void:
_deck_empty = "stop" if i == 1 else "reshuffle" _deck_empty = "stop" if i == 1 else "reshuffle"
_refresh() _refresh()
)) ))

View file

@ -54,7 +54,7 @@ static func chip(tray: ResultTray, step: Dictionary, last: bool, steps: Array =
if step.has("answer") and Formatter.strip_tags(raw).strip_edges() == "": if step.has("answer") and Formatter.strip_tags(raw).strip_edges() == "":
raw = "[i]no answer[/i]" raw = "[i]no answer[/i]"
var shown := RichText.decorate(raw) var shown := RichText.decorate(raw)
var body := RichText.display_label(shown, 16 if inline else 20, Style.DANGER_INK if step.get("stop", false) else Style.INK) var body := RichText.display_label(shown, 16 if inline else 20, Style.DANGER_INK if step.get("stop", false) and not step.get("deck_empty", false) else Style.INK)
if Formatter.strip_tags(shown).length() > 56: if Formatter.strip_tags(shown).length() > 56:
body.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART body.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART
body.custom_minimum_size = Vector2(420, 0) body.custom_minimum_size = Vector2(420, 0)