Below 45% zoom a CardShield covers each card and collapsed group: the name shows as a tooltip, dragging moves it, right-click opens its menu, and in Play a click rolls it. Zoom back in and the card's own controls return. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
75 lines
3 KiB
GDScript
75 lines
3 KiB
GDScript
extends SceneTree
|
|
## Resizable cards: the grip's corner hit area, a dragged width and list
|
|
## height (the list scrolls), saving them, and double-click back to automatic.
|
|
## Run: godot --headless --path . -s res://tests/test_card_size.gd -- --sample
|
|
|
|
var _failures := 0
|
|
var main: Main
|
|
|
|
|
|
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
|
|
main = load("res://ui/main.tscn").instantiate()
|
|
root.add_child(main)
|
|
await _frames(5)
|
|
await _test_resize()
|
|
await _test_compact()
|
|
print("%s: %d failure(s)" % ["PASS" if _failures == 0 else "FAIL", _failures])
|
|
quit(1 if _failures else 0)
|
|
|
|
|
|
func _test_resize() -> void:
|
|
var t := main.data.get_table("road")
|
|
var card := main.card_for("road")
|
|
var grip := card.grip
|
|
_check(grip != null and grip.get_index() == card.get_child_count() - 2 and card.shield.get_index() == card.get_child_count() - 1, "the grip, then the shield, are the card's last children")
|
|
_check(grip._has_point(grip.size - Vector2(4, 4)) and not grip._has_point(Vector2(4, 4)), "only the corner takes the mouse")
|
|
var auto_w := card.size.x
|
|
card.set_user_size(380.0, 120.0)
|
|
await _frames()
|
|
_check(is_equal_approx(card.size.x, 380.0 + card.extra_width()), "the card takes the dragged width")
|
|
_check(card.list_scroll != null and is_equal_approx(card.list_scroll.size.y, 120.0), "a set height makes the results scroll")
|
|
_check(card.grip.get_index() == card.get_child_count() - 2, "the grip stays on top after a rebuild")
|
|
var d := t.to_dict()
|
|
_check(d.get("w") == 380 and d.get("list_h") == 120, "the size is saved")
|
|
var back := RollTable.from_dict(d)
|
|
_check(back.width == 380.0 and back.list_height == 120.0, "and loaded")
|
|
card.set_user_size(0.0, 0.0)
|
|
await _frames()
|
|
_check(is_equal_approx(card.size.x, auto_w) and card.list_scroll == null, "back to automatic")
|
|
|
|
|
|
## Zoomed out, cards take only drag, right-click and (in Play) a click to roll.
|
|
func _test_compact() -> void:
|
|
main.board.set_zoom(0.3)
|
|
await _frames()
|
|
var card := main.card_for("road")
|
|
_check(main.board.compact and card.shield.visible, "zoomed out, the shield covers the card")
|
|
_check(card.shield.tooltip_text.begins_with("Road Encounter") and card.shield.tooltip_text.contains("Click to roll"), "its name is a tooltip: " + card.shield.tooltip_text)
|
|
var click := InputEventMouseButton.new()
|
|
click.button_index = MOUSE_BUTTON_LEFT
|
|
click.pressed = true
|
|
click.global_position = Vector2(10, 10)
|
|
card.shield._gui_input(click)
|
|
var up := click.duplicate() as InputEventMouseButton
|
|
up.pressed = false
|
|
card.shield._gui_input(up)
|
|
await _frames(3)
|
|
_check(main.current.get("table_id", "") == "road" or str(main.current).contains("road"), "a click rolls it in Play")
|
|
main.board.set_zoom(1.0)
|
|
await _frames()
|
|
_check(not main.board.compact and not card.shield.visible, "zoomed in, the shield is gone")
|
|
|
|
|
|
func _frames(n: int = 2) -> void:
|
|
for i in n:
|
|
await process_frame
|
|
|
|
|
|
func _check(ok: bool, what: String) -> void:
|
|
if not ok:
|
|
_failures += 1
|
|
print("FAIL ", what)
|