TableTower/tests/test_ui_threads.gd
RobinFiredrake 1735ed09fd Card threads, Morgan's welcome, and typing/scroll/wheel papercuts
- Card threads: a port on each card's bottom edge. Plain runs after any
  result (once the result's own threads finish); Otherwise runs only when
  no thread of the result ran. Saved as card_threads (LOGIC.md 3g).
- Typing on long cards no longer rebuilds the inspector or the card per
  key (~175 ms -> ~7 ms). Timing tool: tests/perf_typing.gd.
- "+ Add result" scrolls to the new row and focuses it.
- Mouse wheel zooms; Shift+wheel pans sideways; scrolling lists keep it.
- "SPREAD" caption over the switcher; Morgan's first-run welcome.
- docs/MECHANICS.md: checklist of table mechanics for planning.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-16 10:41:13 -06:00

143 lines
5.8 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()
await _test_ports_under_cards()
await _test_card_thread_port()
finish()
## A card dragged over another hides the lower card's thread nodes it covers.
func _test_ports_under_cards() -> void:
var low := main.card_for("road")
var top := main.card_for("monsters")
top.position = low.position + Vector2(-20, 0)
top.get_parent().move_child(top, -1)
await _frames()
var ports := main.board.ports
ports._note_stack()
_check(ports._covered(low.inlet_point(), low.get_index()), "the covered card's inlet is hidden")
_check(not ports._covered(top.inlet_point(), top.get_index()), "the top card's inlet still shows")
low.get_parent().move_child(low, -1)
await _frames()
ports._note_stack()
_check(not ports._covered(low.inlet_point(), low.get_index()), "raised again, its inlet shows")
## Build mode: each card has a port on its bottom edge; a thread laid from it
## is a card thread, drawn from there, listed on the card and undoable.
func _test_card_thread_port() -> void:
main.set_mode(Main.Mode.BUILD)
await _frames(10)
var road := main.data.get_table("road")
var card := main.card_for("road")
main.board.set_zoom(1.0)
main.board.ports.queue_redraw()
await _frames(3)
var grabs: Array = main.board.ports._grab.filter(func(g: Dictionary) -> bool:
return g["tid"] == "road" and g["eid"] == RollTable.OUTLET_ID)
var bottom := card.position + Vector2(card.size.x / 2.0, card.size.y)
_check(grabs.size() == 1 and (grabs[0]["pos"] as Vector2).is_equal_approx(bottom), "a card-thread port on the card's bottom edge")
var target := main.card_for("monsters")
main.start_link("road", RollTable.OUTLET_ID)
main.editing._card_under_mouse_override = target
main.finish_link()
main.editing._card_under_mouse_override = null
_check(road.outlet.pipes.has("monsters"), "the drag made a card thread")
await _frames(3)
var key := Roller.pipe_key("road", RollTable.OUTLET_ID, "monsters")
_check(main.board.pipes._paths.has(key), "it is drawn")
main.inspector.select({"kind": "card", "tid": "road"})
await _frames(2)
_check(_find_text(main.inspector, "After any result → "), "the card section lists it")
main.undo_redo.undo()
await _frames(2)
_check(main.data.get_table("road").outlet.pipes.is_empty(), "undo takes it away")
main.set_mode(Main.Mode.PLAY)
await _frames()
func _find_text(n: Node, prefix: String) -> bool:
if n is Button and (n as Button).text.begins_with(prefix):
return true
for c in n.get_children():
if _find_text(c, prefix):
return true
return false
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")