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 <noreply@anthropic.com>
This commit is contained in:
parent
983d2bd839
commit
a7fb931bb4
8 changed files with 150 additions and 67 deletions
|
|
@ -39,7 +39,8 @@ static func pick_for(t: RollTable, ctx: RollContext, f: Dictionary) -> Dictionar
|
||||||
if not skipped.is_empty():
|
if not skipped.is_empty():
|
||||||
Roller._why(node, [{"type": "reroll", "skipped": skipped}])
|
Roller._why(node, [{"type": "reroll", "skipped": skipped}])
|
||||||
return node
|
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)
|
return Roller._stop(t, ALL_REROLLED)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -181,6 +181,7 @@ func _test_reroll() -> void:
|
||||||
for f: Dictionary in kid.get("why", []):
|
for f: Dictionary in kid.get("why", []):
|
||||||
if f["type"] == "reroll":
|
if f["type"] == "reroll":
|
||||||
skipped = true
|
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")
|
_check(skipped, "a reroll why fact is recorded")
|
||||||
_eq(DescribeCards.pipe(e, "feat", b), "again on 96–00", "the label lists the numbers")
|
_eq(DescribeCards.pipe(e, "feat", b), "again on 96–00", "the label lists the numbers")
|
||||||
e.set_pipe_reroll("feat", ["f1", "f71", "f96"])
|
e.set_pipe_reroll("feat", ["f1", "f71", "f96"])
|
||||||
|
|
|
||||||
|
|
@ -41,9 +41,19 @@ func _init() -> void:
|
||||||
|
|
||||||
await _test_deck_waits()
|
await _test_deck_waits()
|
||||||
await _test_batch_history()
|
await _test_batch_history()
|
||||||
|
_test_reroll_mark()
|
||||||
finish()
|
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.
|
## A batch of rolls goes into the tray's Earlier list, newest first.
|
||||||
func _test_batch_history() -> void:
|
func _test_batch_history() -> void:
|
||||||
var before := main.history.size()
|
var before := main.history.size()
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,7 @@ var pauses: RollPauses
|
||||||
var deck_reveal: DeckReveal
|
var deck_reveal: DeckReveal
|
||||||
var _seed: MainRollingSeed
|
var _seed: MainRollingSeed
|
||||||
var _copy: MainRollingCopy
|
var _copy: MainRollingCopy
|
||||||
|
var _show: MainRollingShow
|
||||||
|
|
||||||
|
|
||||||
func _init(p_main: Main) -> void:
|
func _init(p_main: Main) -> void:
|
||||||
|
|
@ -27,6 +28,7 @@ func _init(p_main: Main) -> void:
|
||||||
deck_reveal = DeckReveal.new(self)
|
deck_reveal = DeckReveal.new(self)
|
||||||
_seed = MainRollingSeed.new(p_main)
|
_seed = MainRollingSeed.new(p_main)
|
||||||
_copy = MainRollingCopy.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
|
## 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
|
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
|
## 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).
|
## (an index or -1 for a pick, an int, a String, or null for Cancel).
|
||||||
func _ask_player(req: Dictionary) -> Variant:
|
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)
|
card = m.card_for(t.id)
|
||||||
if card:
|
if card:
|
||||||
card.clear_flick()
|
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)
|
card.set_rolling(false)
|
||||||
if not stopped:
|
if not stopped:
|
||||||
var e: TableEntry = n["entry"]
|
var e: TableEntry = n["entry"]
|
||||||
|
|
@ -294,34 +281,21 @@ func _play_one(n: Dictionary, my: int, depth: int) -> void:
|
||||||
m.tray.render()
|
m.tray.render()
|
||||||
|
|
||||||
|
|
||||||
## Shows the whole current roll at once: every result and pipe on its path lit,
|
## Before the kept result lights: each result that came up but was rolled
|
||||||
## long lists scrolled to their result, and the full chain in the tray.
|
## again ("roll again if it comes up", Only if) flickers with "↻ rolled again".
|
||||||
func _finish_fast_roll() -> void:
|
func _show_rerolls(n: Dictionary, card: TableCard, my: int) -> void:
|
||||||
var all: Array = m.current["all"]
|
for fact: Dictionary in n.get("why", []):
|
||||||
deck_reveal.clear()
|
if str(fact.get("type", "")) != "reroll":
|
||||||
_light_steps(all)
|
continue
|
||||||
m._refresh_lit()
|
for skipped: Dictionary in fact.get("skipped", []):
|
||||||
_reveal_steps(all)
|
var eid := str(skipped.get("entry_id", ""))
|
||||||
m.current["steps"] = all
|
if eid == "" or not card.rows.has(eid):
|
||||||
m.current["done"] = true
|
continue
|
||||||
m.current["fast"] = true
|
card.mark_rerolled(eid)
|
||||||
m.refresh_live()
|
await m.get_tree().create_timer(0.45).timeout
|
||||||
m.tray.render()
|
if my != _token or not is_instance_valid(card):
|
||||||
|
return
|
||||||
|
card.rows_ui.restate(eid)
|
||||||
## 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")
|
|
||||||
|
|
||||||
|
|
||||||
func _pulse(key: String, my: int) -> void:
|
func _pulse(key: String, my: int) -> void:
|
||||||
|
|
@ -357,25 +331,15 @@ func _seed_session() -> void:
|
||||||
_seed.seed_session()
|
_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:
|
func _light_steps(steps: Array) -> void:
|
||||||
var stack: Array = []
|
_show._light_steps(steps)
|
||||||
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
|
|
||||||
|
|
||||||
|
|
||||||
# ----- Copy -----
|
# ----- Copy -----
|
||||||
|
|
|
||||||
83
ui/main_rolling_show.gd
Normal file
83
ui/main_rolling_show.gd
Normal file
|
|
@ -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
|
||||||
1
ui/main_rolling_show.gd.uid
Normal file
1
ui/main_rolling_show.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
uid://cbf6n7ep8h1hk
|
||||||
|
|
@ -334,5 +334,9 @@ func sparkle(eid: String) -> void:
|
||||||
list_ui.sparkle(eid)
|
list_ui.sparkle(eid)
|
||||||
|
|
||||||
|
|
||||||
|
func mark_rerolled(eid: String) -> void:
|
||||||
|
list_ui.mark_rerolled(eid)
|
||||||
|
|
||||||
|
|
||||||
func hidden_has_pipes() -> bool:
|
func hidden_has_pipes() -> bool:
|
||||||
return list_ui.hidden_has_pipes()
|
return list_ui.hidden_has_pipes()
|
||||||
|
|
|
||||||
|
|
@ -85,6 +85,25 @@ func sparkle(eid: String) -> void:
|
||||||
Sparkles.burst(card.get_parent(), Rect2(card.position + at, row.size))
|
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:
|
func hidden_has_pipes() -> bool:
|
||||||
for e in card.table.entries:
|
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()):
|
if not card.rows.has(e.id) and (not e.pipes.is_empty() or not card.main.ref_targets_for(e).is_empty()):
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue