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() 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") 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")