extends SceneTree # Headless gameplay test: run with # godot --headless -s res://tests/test_icon_button.gd # Verifies IconButton correctly turns a touch-down + touch-up into its # `pressed` signal, which the Map button is wired to open the world map - # and that opening the map hides the Map button itself (avoiding it # overlapping the Close button, which occupies the same corner). # # Calls _gui_input directly rather than routing a synthetic touch through # the viewport's screen-position hit-testing, since headless mode's # placeholder window makes exact on-screen coordinates unreliable to # target (see test_world_map_ui.gd's pan test for the same issue) - this # is a more targeted unit test of the button's own press logic anyway. var main_scene: Node var world_map: Control var map_button: IconButton var press_count: int = 0 func _initialize() -> void: var packed: PackedScene = load("res://Main.tscn") main_scene = packed.instantiate() root.add_child(main_scene) world_map = main_scene.get_node("UI/WorldMap") map_button = main_scene.get_node("UI/MapButton") map_button.pressed.connect(_on_pressed) func _on_pressed() -> void: press_count += 1 func _process(_delta: float) -> bool: var down: InputEventScreenTouch = InputEventScreenTouch.new() down.pressed = true map_button._gui_input(down) var up: InputEventScreenTouch = InputEventScreenTouch.new() up.pressed = false map_button._gui_input(up) var press_fired: bool = press_count == 1 var map_opened: bool = world_map.visible var map_button_hidden: bool = not map_button.visible print("press_fired=%s map_opened=%s map_button_hidden=%s" % [press_fired, map_opened, map_button_hidden]) if press_fired and map_opened and map_button_hidden: print("TEST_ICON_BUTTON: PASS") quit(0) else: print("TEST_ICON_BUTTON: FAIL") quit(1) return true