TableTower/tests/test_fast_roll.gd
RobinFiredrake a7fb931bb4 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>
2026-11-14 14:25:21 -06:00

96 lines
4.3 KiB
GDScript

extends TestBase
## Fast roll (Shift-click): the whole result shows at once, with no animation.
## Run: godot --headless --path . -s res://tests/test_fast_roll.gd -- --sample
## (--sample keeps the app from reading or writing saved collections.)
func _init() -> void:
if not await start_main():
return
main.rng.seed = 7
# A fast roll finishes in the same frame it starts.
for i in 20:
main.start_roll("wilderness", true)
var all: Array = main.current["all"]
_check(main.current.get("done", false), "fast roll is done immediately")
_check(main.current["steps"].size() == all.size(), "fast roll shows every step at once")
_check(main.board.pipes.pulse_key == "", "fast roll sends no bead down the threads")
var lit_steps := 0
for s: Dictionary in all:
if s.has("entry_id") and not s.get("stop", false):
lit_steps += 1
_check(main.is_entry_lit(str(s["table_id"]), str(s["entry_id"])), "every result on the path is lit")
_check(main.lit_entries.size() == lit_steps, "only the path's results are lit")
# Chains from Wilderness Travel are a single line, so n results have n - 1 pipes.
_check(main.lit_pipes.size() == maxi(0, lit_steps - 1),
"each link in the chain lights its thread (%d threads, %d results)" % [main.lit_pipes.size(), lit_steps])
for c in main.cards.values():
_check(not (c as TableCard)._rolling, "no card is left tumbling")
# A normal roll still animates: it isn't finished in the same frame.
main.start_roll("wilderness")
_check(not main.current.get("done", false), "a normal roll still animates")
# A fast roll started mid-animation takes over cleanly.
main.start_roll("wilderness", true)
_check(main.current.get("done", false), "a fast roll interrupts an animating one")
for i in 90:
await process_frame
_check(main.current.get("done", false) and main.current.get("fast", false), "the interrupted roll doesn't overwrite the fast result")
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()
var texts: Array[String] = await BatchRoll.run(main, "names", 3)
_eq(texts.size(), 3, "a batch rolls the asked number of times")
_eq(main.history.size(), mini(before + 4, Main.HISTORY_SIZE), "each batch roll joins Earlier (after the roll on screen)")
_eq(str(main.history[0].get("batch", "")), "3 of 3", "the newest is the batch's last roll")
for node in main.get_children():
if node is ModalCard:
(node as ModalCard).close()
## Deck mode: an animated roll fades the drawn result only once it lights;
## a fast roll fades it at once.
func _test_deck_waits() -> void:
var t := main.data.get_table("wilderness")
t.card_mode = true
main.reshuffle_table(t.id)
main.layout._board_changed()
await _frames()
var total := main.cards_left(t.id).y
main.start_roll(t.id)
var eid := ""
for st: Dictionary in main.current["all"]:
if st.get("table_id") == t.id and st.has("entry_id"):
eid = st["entry_id"]
var card := main.card_for(t.id)
_check(eid != "" and card.rows[eid].modulate.a == 1.0, "mid-animation the drawn result isn't faded yet")
_check(main.cards_left(t.id).x == total, "mid-animation the count hasn't dropped")
var until := Time.get_ticks_msec() + 15000
while not main.current.get("done", false) and Time.get_ticks_msec() < until:
await process_frame
card = main.card_for(t.id)
var gone := (main.decks[t.id] as DeckState).remaining(t, t.find_entry(eid)) <= 0
_check(main.current.get("done", false), "the animated roll finished")
_check(card.rows[eid].modulate.a < 1.0 if gone else true, "after the animation the result fades")
_check(main.cards_left(t.id).x == total - 1, "after the animation the count drops")
main.start_roll(t.id, true)
_check(main.cards_left(t.id).x == total - 2, "a fast roll drops the count at once")
t.card_mode = false