From a7fb931bb476f10617f545e49a18112b41a7cfd4 Mon Sep 17 00:00:00 2001 From: RobinFiredrake Date: Sat, 14 Nov 2026 14:25:21 -0600 Subject: [PATCH] Rerolls show in the roll animation; MainRollingShow split out A result that came up but was rolled again (a thread's roll again, Only if) now flickers with a floating "rolled again" before the kept result lights. main_rolling.gd hit 412 lines, so showing a roll at once moved to MainRollingShow (delegators kept). Co-Authored-By: Claude Opus 5.5 --- core/roll_cards.gd | 3 +- tests/test_book_tables.gd | 1 + tests/test_fast_roll.gd | 10 ++++ ui/main_rolling.gd | 96 ++++++++++++------------------------- ui/main_rolling_show.gd | 83 ++++++++++++++++++++++++++++++++ ui/main_rolling_show.gd.uid | 1 + ui/table_card.gd | 4 ++ ui/table_card_list.gd | 19 ++++++++ 8 files changed, 150 insertions(+), 67 deletions(-) create mode 100644 ui/main_rolling_show.gd create mode 100644 ui/main_rolling_show.gd.uid diff --git a/core/roll_cards.gd b/core/roll_cards.gd index 0519d87..fe45289 100644 --- a/core/roll_cards.gd +++ b/core/roll_cards.gd @@ -39,7 +39,8 @@ static func pick_for(t: RollTable, ctx: RollContext, f: Dictionary) -> Dictionar if not skipped.is_empty(): Roller._why(node, [{"type": "reroll", "skipped": skipped}]) return node - skipped.append({"value": node["value"], "text": Formatter.strip_tags((node["entry"] as TableEntry).text).strip_edges()}) + skipped.append({"value": node["value"], "text": Formatter.strip_tags((node["entry"] as TableEntry).text).strip_edges(), + "entry_id": (node["entry"] as TableEntry).id}) return Roller._stop(t, ALL_REROLLED) diff --git a/tests/test_book_tables.gd b/tests/test_book_tables.gd index 041a7c1..0c0e987 100644 --- a/tests/test_book_tables.gd +++ b/tests/test_book_tables.gd @@ -181,6 +181,7 @@ func _test_reroll() -> void: for f: Dictionary in kid.get("why", []): if f["type"] == "reroll": skipped = true + _eq(str((f["skipped"] as Array)[0].get("entry_id", "")), "f96", "a skipped roll names its result, so the animation can show it") _check(skipped, "a reroll why fact is recorded") _eq(DescribeCards.pipe(e, "feat", b), "again on 96–00", "the label lists the numbers") e.set_pipe_reroll("feat", ["f1", "f71", "f96"]) diff --git a/tests/test_fast_roll.gd b/tests/test_fast_roll.gd index 03e334d..36698d4 100644 --- a/tests/test_fast_roll.gd +++ b/tests/test_fast_roll.gd @@ -41,9 +41,19 @@ func _init() -> void: await _test_deck_waits() await _test_batch_history() + _test_reroll_mark() finish() +## "Roll again" shows: the skipped result flickers with a floating note. +func _test_reroll_mark() -> void: + var card := main.card_for("names") + var eid: String = card.rows.keys()[0] + card.mark_rerolled(eid) + var notes := card.get_parent().find_children("*", "Label", false, false).filter(func(l: Label) -> bool: return l.text.contains("rolled again")) + _check(not notes.is_empty(), "a rolled-again result gets a floating note") + + ## A batch of rolls goes into the tray's Earlier list, newest first. func _test_batch_history() -> void: var before := main.history.size() diff --git a/ui/main_rolling.gd b/ui/main_rolling.gd index 8881f96..43cd8d7 100644 --- a/ui/main_rolling.gd +++ b/ui/main_rolling.gd @@ -19,6 +19,7 @@ var pauses: RollPauses var deck_reveal: DeckReveal var _seed: MainRollingSeed var _copy: MainRollingCopy +var _show: MainRollingShow func _init(p_main: Main) -> void: @@ -27,6 +28,7 @@ func _init(p_main: Main) -> void: deck_reveal = DeckReveal.new(self) _seed = MainRollingSeed.new(p_main) _copy = MainRollingCopy.new(p_main) + _show = MainRollingShow.new(p_main) ## Rolls a table and plays the result down its pipes. A fast roll (Shift held @@ -143,26 +145,6 @@ func _prompt_for(req: Dictionary, run: Dictionary) -> Variant: return reply -## Lights the steps of the running roll so far (Roller.progress) on the board -## and in the tray, all at once. Used just before a question opens. -func show_progress() -> void: - if m.rolling_ctx == null: - return - var steps := Roller.progress(m.rolling_ctx) - m.lit_entries.clear() - m.lit_pipes.clear() - m.lit_texts.clear() - m.lit_columns.clear() - _light_steps(steps) - m._refresh_lit() - _reveal_steps(steps) - m.current["steps"] = steps - m.current["all"] = steps - m.current["fast"] = true - m.refresh_live() - m.tray.render() - - ## The real prompt hook: opens the choice pop-up and waits for its answer ## (an index or -1 for a pick, an int, a String, or null for Cancel). func _ask_player(req: Dictionary) -> Variant: @@ -274,6 +256,11 @@ func _play_one(n: Dictionary, my: int, depth: int) -> void: card = m.card_for(t.id) if card: card.clear_flick() + await _show_rerolls(n, card, my) + if my != _token: + return + card = m.card_for(t.id) + if card: card.set_rolling(false) if not stopped: var e: TableEntry = n["entry"] @@ -294,34 +281,21 @@ func _play_one(n: Dictionary, my: int, depth: int) -> void: m.tray.render() -## Shows the whole current roll at once: every result and pipe on its path lit, -## long lists scrolled to their result, and the full chain in the tray. -func _finish_fast_roll() -> void: - var all: Array = m.current["all"] - deck_reveal.clear() - _light_steps(all) - m._refresh_lit() - _reveal_steps(all) - m.current["steps"] = all - m.current["done"] = true - m.current["fast"] = true - m.refresh_live() - m.tray.render() - - -## Scrolls long cards to the last result each table gave in `steps` (one -## reveal per table, so thousands of steps cost one pass). -func _reveal_steps(steps: Array) -> void: - var last := {} - for s: Dictionary in steps: - if s.has("entry_id") and not s.get("stop", false): - last[str(s.get("table_id", ""))] = str(s["entry_id"]) - for tid: String in last: - var card := m.card_for(tid) - if card: - card.reveal(last[tid]) - if card.table.card_mode and m.sound: - m.sound.play("card_turn") +## Before the kept result lights: each result that came up but was rolled +## again ("roll again if it comes up", Only if) flickers with "↻ rolled again". +func _show_rerolls(n: Dictionary, card: TableCard, my: int) -> void: + for fact: Dictionary in n.get("why", []): + if str(fact.get("type", "")) != "reroll": + continue + for skipped: Dictionary in fact.get("skipped", []): + var eid := str(skipped.get("entry_id", "")) + if eid == "" or not card.rows.has(eid): + continue + card.mark_rerolled(eid) + await m.get_tree().create_timer(0.45).timeout + if my != _token or not is_instance_valid(card): + return + card.rows_ui.restate(eid) func _pulse(key: String, my: int) -> void: @@ -357,25 +331,15 @@ func _seed_session() -> void: _seed.seed_session() -## Lights the entries and pipes of a roll from its saved steps. +## Showing a roll at once (MainRollingShow). +func show_progress() -> void: + _show.show_progress() +func _finish_fast_roll() -> void: + _show._finish_fast_roll() +func _reveal_steps(steps: Array) -> void: + _show._reveal_steps(steps) func _light_steps(steps: Array) -> void: - var stack: Array = [] - for s: Dictionary in steps: - var d := int(s.get("depth", 0)) - stack.resize(d) - stack.append(s) - if s.get("stop", false) or not s.has("entry_id"): - continue - var tid := str(s.get("table_id", "")) - var ek := Roller.entry_key(tid, str(s["entry_id"])) - m.lit_entries[ek] = true - m.lit_texts[ek] = str(s.get("text", "")) - TableCardColumns.note_lit(m, ek, s) - if d > 0 and not (s.has("pass") or s.has("after")) and stack[d - 1] is Dictionary and (stack[d - 1] as Dictionary).has("entry_id"): - var p: Dictionary = stack[d - 1] - var ptid := str(p.get("table_id", "")) - var peid := str(p["entry_id"]) - m.lit_pipes[Roller.ref_key(ptid, peid, tid) if s.get("inline", false) else Roller.pipe_key(ptid, peid, tid)] = true + _show._light_steps(steps) # ----- Copy ----- diff --git a/ui/main_rolling_show.gd b/ui/main_rolling_show.gd new file mode 100644 index 0000000..06d0016 --- /dev/null +++ b/ui/main_rolling_show.gd @@ -0,0 +1,83 @@ +class_name MainRollingShow +extends RefCounted +## Showing a roll all at once instead of animating it: a fast roll (Shift), +## a roll that asked questions, a long chain, the steps so far before a +## question, and lighting a saved roll's steps (reopening a spread). +## MainRolling keeps one-line delegators. + +var m: Main + + +func _init(p_main: Main) -> void: + m = p_main + + +## Lights the steps of the running roll so far (Roller.progress) on the board +## and in the tray, all at once. Used just before a question opens. +func show_progress() -> void: + if m.rolling_ctx == null: + return + var steps := Roller.progress(m.rolling_ctx) + m.lit_entries.clear() + m.lit_pipes.clear() + m.lit_texts.clear() + m.lit_columns.clear() + _light_steps(steps) + m._refresh_lit() + _reveal_steps(steps) + m.current["steps"] = steps + m.current["all"] = steps + m.current["fast"] = true + m.refresh_live() + m.tray.render() + + +## Shows the whole current roll at once: every result and pipe on its path lit, +## long lists scrolled to their result, and the full chain in the tray. +func _finish_fast_roll() -> void: + var all: Array = m.current["all"] + m.rolling.deck_reveal.clear() + _light_steps(all) + m._refresh_lit() + _reveal_steps(all) + m.current["steps"] = all + m.current["done"] = true + m.current["fast"] = true + m.refresh_live() + m.tray.render() + + +## Scrolls long cards to the last result each table gave in `steps` (one +## reveal per table, so thousands of steps cost one pass). +func _reveal_steps(steps: Array) -> void: + var last := {} + for s: Dictionary in steps: + if s.has("entry_id") and not s.get("stop", false): + last[str(s.get("table_id", ""))] = str(s["entry_id"]) + for tid: String in last: + var card := m.card_for(tid) + if card: + card.reveal(last[tid]) + if card.table.card_mode and m.sound: + m.sound.play("card_turn") + + +## Lights the entries and pipes of a roll from its saved steps. +func _light_steps(steps: Array) -> void: + var stack: Array = [] + for s: Dictionary in steps: + var d := int(s.get("depth", 0)) + stack.resize(d) + stack.append(s) + if s.get("stop", false) or not s.has("entry_id"): + continue + var tid := str(s.get("table_id", "")) + var ek := Roller.entry_key(tid, str(s["entry_id"])) + m.lit_entries[ek] = true + m.lit_texts[ek] = str(s.get("text", "")) + TableCardColumns.note_lit(m, ek, s) + if d > 0 and not (s.has("pass") or s.has("after")) and stack[d - 1] is Dictionary and (stack[d - 1] as Dictionary).has("entry_id"): + var p: Dictionary = stack[d - 1] + var ptid := str(p.get("table_id", "")) + var peid := str(p["entry_id"]) + m.lit_pipes[Roller.ref_key(ptid, peid, tid) if s.get("inline", false) else Roller.pipe_key(ptid, peid, tid)] = true diff --git a/ui/main_rolling_show.gd.uid b/ui/main_rolling_show.gd.uid new file mode 100644 index 0000000..73c94ca --- /dev/null +++ b/ui/main_rolling_show.gd.uid @@ -0,0 +1 @@ +uid://cbf6n7ep8h1hk diff --git a/ui/table_card.gd b/ui/table_card.gd index d095c26..34a1078 100644 --- a/ui/table_card.gd +++ b/ui/table_card.gd @@ -334,5 +334,9 @@ func sparkle(eid: String) -> void: list_ui.sparkle(eid) +func mark_rerolled(eid: String) -> void: + list_ui.mark_rerolled(eid) + + func hidden_has_pipes() -> bool: return list_ui.hidden_has_pipes() diff --git a/ui/table_card_list.gd b/ui/table_card_list.gd index 4324e4e..0526c4b 100644 --- a/ui/table_card_list.gd +++ b/ui/table_card_list.gd @@ -85,6 +85,25 @@ func sparkle(eid: String) -> void: Sparkles.burst(card.get_parent(), Rect2(card.position + at, row.size)) +## A result that came up but was rolled again: it flickers and a small +## "↻ rolled again" floats up from it and fades. +func mark_rerolled(eid: String) -> void: + var row: Control = card.rows.get(eid) + if row == null or not row.is_inside_tree() or not row.is_visible_in_tree(): + return + card.rows_ui.set_row_state(eid, TableCardRows.RowState.FLICK) + var at := card.get_global_transform().affine_inverse() * row.get_global_transform().origin + var note := Style.make_label("↻ rolled again", Style.body_bold(true), 13, Style.ACCENT_DARK) + note.mouse_filter = Control.MOUSE_FILTER_IGNORE + note.position = card.position + at + Vector2(row.size.x - 120.0, 2.0) + # Into the card layer, so a rebuild of this card doesn't cut it short. + card.get_parent().add_child(note) + var tween := note.create_tween() + tween.tween_property(note, "position:y", note.position.y - 22.0, 0.7) + tween.parallel().tween_property(note, "modulate:a", 0.0, 0.7).set_delay(0.25) + tween.tween_callback(note.queue_free) + + func hidden_has_pipes() -> bool: for e in card.table.entries: if not card.rows.has(e.id) and (not e.pipes.is_empty() or not card.main.ref_targets_for(e).is_empty()):