Add fast roll: Shift-click a die to skip the animation

Holding Shift while clicking a table's die (or "Roll again") skips the
flicker and the beads and shows the whole result at once: every result
and pipe on the path lit, long lists scrolled to their result, and the
full chain in the tray without the chip fade-in. A fast roll started
mid-animation takes over cleanly. The Play hint and roll tooltips
mention Shift-click, and --fast pairs with --roll for screenshots.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
RobinFiredrake 2026-11-08 12:53:39 -06:00
parent 667ee1d9f0
commit 2a79640c9d
6 changed files with 97 additions and 10 deletions

View file

@ -16,8 +16,9 @@ godot --path .
## Using it
- **Play mode** is for the game table. Click a die to roll. The results flicker, one lands,
and a bead runs down any pipe into the next table. The tray at the bottom shows the whole
chain and the last few rolls.
and a bead runs down any pipe into the next table. Hold **Shift** while clicking to fast
roll: no animation, just the result. The tray at the bottom shows the whole chain and the
last few rolls.
- **Build mode** is for setting up tables. Edit names, results, weights and details in place,
add or delete results and tables, and drag a card by its header. Drag from a result's ●
onto another table to lay a pipe. Click a pipe to set how many times it rolls, save its
@ -55,14 +56,14 @@ docs/ design document
## Tests
```sh
for t in tests/test_*.gd; do godot --headless --path . -s "res://$t"; done
for t in tests/test_*.gd; do godot --headless --path . -s "res://$t" -- --sample; done
```
## Screenshots from the command line
```sh
tools/test_window.sh -- --screenshot=/tmp/board.png [--build] [--expand-all] [--collapse-all] \
[--roll=wilderness] [--shot-delay=0.75]
[--roll=wilderness] [--fast] [--shot-delay=0.75]
```
This uses the sample board and doesn't save anything. `tools/test_window.sh` runs the game

61
tests/test_fast_roll.gd Normal file
View file

@ -0,0 +1,61 @@
extends SceneTree
## 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.)
var _failures := 0
func _init() -> void:
if not OS.get_cmdline_user_args().has("--sample"):
print("Run with -- --sample so the test can't touch saved data.")
quit(2)
return
var main: Main = load("res://ui/main.tscn").instantiate()
root.add_child(main)
for i in 5:
await process_frame
if main._saving_enabled:
print("Saving is enabled; refusing to roll.")
quit(2)
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 pipes")
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 pipe (%d pipes, %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")
print("%s: %d failure(s)" % ["PASS" if _failures == 0 else "FAIL", _failures])
quit(1 if _failures else 0)
func _check(ok: bool, what: String) -> void:
if not ok:
_failures += 1
print(" ✗ ", what)

View file

@ -0,0 +1 @@
uid://c6ewfdklnuf1r

View file

@ -8,7 +8,7 @@ enum Mode { PLAY, BUILD }
const HISTORY_SIZE := 6
const SAVE_DELAY := 0.6
const HINTS := {
Mode.PLAY: "Click a die to roll. Results flow down the pipes.",
Mode.PLAY: "Click a die to roll. Shift-click skips straight to the result.",
Mode.BUILD: "Type to edit. Drag from a ● to another table to lay a pipe. Click a pipe for its options.",
}
@ -530,10 +530,14 @@ func _card_under_mouse() -> TableCard:
# ---------- Rolling ----------
func start_roll(tid: String) -> void:
## Rolls a table and plays the result down its pipes. A fast roll (Shift held
## while clicking, or `fast`) skips the flicker and the beads and shows the
## whole result at once.
func start_roll(tid: String, fast: bool = false) -> void:
var t := data.get_table(tid)
if t == null:
return
fast = fast or Input.is_key_pressed(KEY_SHIFT)
_archive_current()
_token += 1
var my := _token
@ -552,6 +556,9 @@ func start_roll(tid: String) -> void:
current = {"collection": data.id, "root": tid, "root_name": t.name, "time": Time.get_unix_time_from_system(),
"steps": [], "all": Roller.flatten(tree, []), "done": false, "chain_vars": ctx.chain_vars.duplicate()}
_store_roll(ctx)
if fast:
_finish_fast_roll()
return
tray.render()
await _play_node(tree, my)
if my == _token:
@ -600,6 +607,22 @@ func _play_node(n: Dictionary, my: int, depth: int = 0) -> void:
await _play_node(c, my, depth + 1)
## 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 = current["all"]
_light_steps(all)
_refresh_lit()
for s: Dictionary in all:
var card := card_for(str(s.get("table_id", "")))
if card and s.has("entry_id"):
card.reveal(str(s["entry_id"]))
current["steps"] = all
current["done"] = true
current["fast"] = true
tray.render()
func _pulse(key: String, my: int) -> void:
var length := board.pipes.path_length(key)
if length <= 0.0 or my != _token:
@ -674,7 +697,7 @@ func _seed_session() -> void:
# ---------- Command line (used for screenshots and checks) ----------
# godot --path . -- --screenshot=/tmp/shot.png [--build] [--expand-all] [--collapse-all]
# [--roll=<table id>] [--shot-delay=<seconds>]
# [--roll=<table id>] [--fast] [--shot-delay=<seconds>]
# [--board=<collection.json>] (with --sample/--screenshot only: show that board instead)
# [--tray=variables] [--hover=<x>,<y>] [--details=<table id>] [--pipe=<pipe key>] [--edit-details=<table id>]
@ -698,7 +721,7 @@ func _run_cli(args: PackedStringArray) -> void:
_run_shell_cli(args)
var roll := _arg_value(args, "--roll")
if roll != "":
start_roll(roll)
start_roll(roll, args.has("--fast"))
_run_cli_extras(args)
var shot := _arg_value(args, "--screenshot")
if shot == "":

View file

@ -49,6 +49,7 @@ func setup(p_main: Main) -> void:
_title.size_flags_vertical = SIZE_SHRINK_CENTER
head.add_child(_title)
_again = Style.bar_button("Roll again")
_again.tooltip_text = "Shift-click to skip the animation"
_again.pressed.connect(func() -> void:
if not main.current.is_empty():
main.start_roll(main.current["root"])
@ -172,7 +173,7 @@ func render() -> void:
_flow.add_child(_link(step.get("inline", false)))
var chip := _chip(step, done and i == steps.size() - 1)
_flow.add_child(chip)
if i >= fresh_from:
if i >= fresh_from and not current.get("fast", false):
chip.modulate.a = 0.3
create_tween().tween_property(chip, "modulate:a", 1.0, 0.25)

View file

@ -264,7 +264,7 @@ func _make_header(build: bool, ranged: bool) -> Control:
var die := table.die_size()
var roll := Button.new()
roll.text = "d%d" % die
roll.tooltip_text = "Roll d%d on %s" % [die, table.name]
roll.tooltip_text = "Roll d%d on %s\nShift-click to skip the animation" % [die, table.name]
roll.size_flags_vertical = SIZE_SHRINK_CENTER
roll.add_theme_font_override("font", Style.display(true))
roll.add_theme_font_size_override("font_size", 17)