TableTower/tests/test_ui_threads.gd
RobinFiredrake df03168382 Thread inspector: roll with other dice, roll again on some results
- InspectorThreadRolls (new helper): "Roll it with [ ] instead" for a card
  with numbered ranges (placeholder: the card's own dice), and a collapsible
  "Roll again if it comes up: …" tick list of the card's results (scrolls
  past 7 rows; open state kept across rebuilds).
- Inspector.set_pipe_dice / set_pipe_reroll delegators; edits go through
  Inspector.wrote like the other thread options, so undo covers them.
- Help: two short subsections in the Threads topic.
- tests/test_ui_threads.gd.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-10 21:18:49 -06:00

82 lines
3.3 KiB
GDScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

extends TestBase
## The thread inspector's "Roll it with … instead" field and "Roll again if
## it comes up" list: shown for a card with numbered ranges, edits land on the
## result, undo puts them back.
## Run: godot --headless --path . -s res://tests/test_ui_threads.gd -- --sample
func _init() -> void:
if not await start_main():
return
await _test_ranged_target()
await _test_plain_target()
finish()
func _parts(to: String) -> Dictionary:
return main.inspector.pipe_parts.get(to, {})
func _road() -> TableEntry:
return main.data.get_table("road").entries[3]
func _test_ranged_target() -> void:
print("Ranged target")
main.set_mode(Main.Mode.BUILD)
var e := _road()
e.add_pipe("wilderness")
main.mark_dirty()
main.undo_redo._commit_edits()
main.inspecting.select_pipe(Roller.pipe_key("road", e.id, "wilderness"))
await _frames(3)
var p := _parts("wilderness")
_check(p.has("dice"), "a ranged card gets the Roll it with field")
var dice := p.get("dice") as LineEdit
_eq(dice.placeholder_text, "1d100", "its placeholder is the card's own dice")
var toggle := p.get("reroll_toggle") as Button
_check(toggle != null and toggle.text.contains("never"), "the roll-again list starts closed, saying never: %s" % (toggle.text if toggle else ""))
var boxes: Dictionary = p.get("reroll", {})
var w := main.data.get_table("wilderness")
_eq(boxes.size(), w.entries.size(), "one tick box per result")
var last := w.entries[w.entries.size() - 1]
_check((boxes[last.id] as CheckBox).text.begins_with("96–00"), "a box shows the number and the text: %s" % (boxes[last.id] as CheckBox).text)
dice.text = "3d10+"
dice.text_changed.emit("3d10+")
_eq(e.dice_for("wilderness"), "", "dice that can't be rolled aren't kept")
dice.text = "3d10+70"
dice.text_changed.emit("3d10+70")
_eq(e.dice_for("wilderness"), "3d10+70", "the dice land on the thread")
main.undo_redo._commit_edits()
toggle.pressed.emit()
_check((boxes[last.id] as CheckBox).is_visible_in_tree(), "the list opens")
(boxes[last.id] as CheckBox).button_pressed = true
_eq(e.reroll_for("wilderness"), [last.id] as Array[String], "ticking adds the result")
_check(toggle.text.contains("96–00"), "the heading names it: %s" % toggle.text)
main.undo_redo._commit_edits()
# Quick edits to one card merge into one undo step (EditHistory.COALESCE_SECS).
main.undo_redo.undo()
await _frames(2)
e = _road()
_check(e.reroll_for("wilderness").is_empty(), "undo takes the tick back")
_eq(e.dice_for("wilderness"), "", "and the dice")
main.undo_redo.redo()
await _frames(2)
e = _road()
_eq(e.dice_for("wilderness"), "3d10+70", "redo brings the dice back")
_eq(e.reroll_for("wilderness"), [last.id] as Array[String], "and the tick")
var boxes2: Dictionary = _parts("wilderness").get("reroll", {})
_check(boxes2.has(last.id) and (boxes2[last.id] as CheckBox).button_pressed, "the inspector shows the tick again")
_check(DescribeCards.pipe(e, "wilderness", main.data).contains("again on 96–00"), "the thread's label says so")
func _test_plain_target() -> void:
print("Card without ranges")
var e := main.data.get_table("wilderness").entries[0]
main.inspecting.select_pipe(Roller.pipe_key("wilderness", e.id, "road"))
await _frames(3)
var p := _parts("road")
_check(not p.has("dice"), "no Roll it with field for a card without ranges")
_check(p.has("reroll"), "but the roll-again list is there")