extends TestBase ## 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 func _init() -> void: if not await start_main(): return await _test_resize() await _test_compact() await _test_play_drag_selects() await _test_show_less() finish() 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") _check(not grip._has_point(grip.size + Vector2(5, 5)) and not grip._has_point(grip.size + Vector2(300, -4)) and not grip._has_point(Vector2(grip.size.x - 4, grip.size.y + 200)), "nothing outside the card is the resize corner") 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") ## In Play, a left-drag on empty space draws a selection box; it doesn't pan. func _test_play_drag_selects() -> void: main.set_mode(Main.Mode.PLAY) main.clear_selection() main.board.set_zoom(0.5) await _frames() var card := main.card_for("road") var r := card.get_global_rect() var from := r.position - Vector2(20, 20) - main.board.global_position var to := r.position + Vector2(40, 40) - main.board.global_position var before := main.board.world.position var press := InputEventMouseButton.new() press.button_index = MOUSE_BUTTON_LEFT press.pressed = true press.position = from main.board._gui_input(press) var move := InputEventMouseMotion.new() move.position = to move.relative = to - from main.board._gui_input(move) var up := press.duplicate() as InputEventMouseButton up.pressed = false up.position = to main.board._gui_input(up) await _frames() _check(main.board.world.position == before, "a left-drag doesn't pan") _check(main.selection.has("road"), "it selects what the box touches") main.clear_selection() ## A long card opened with "show all" has "▲ Show less" to fold it up again. func _test_show_less() -> void: var t := main.data.get_table("trinkets") if not t.collapsed: main.toggle_collapse("trinkets") await _frames(2) main.toggle_collapse("trinkets") await _frames(2) var less: Array = [] for node in main.card_for("trinkets").find_children("*", "Button", true, false): if node.has_meta("show_less"): less.append(node) _check(not t.collapsed and less.size() == 1, "an opened long card shows Show less") if less.size() == 1: (less[0] as Button).pressed.emit() await _frames(2) _check(t.collapsed, "Show less collapses it again")