extends RefCounted ## Headless tests for the key/button remap helper. const InputBindings := preload("res://src/core/input_bindings.gd") func test_descriptor_from_events() -> bool: var key := InputEventKey.new() key.physical_keycode = KEY_Z var a := TestUtils.check_eq(InputBindings.descriptor_from_event(key), {"type": "key", "code": int(KEY_Z)}, "keys store a code") var button := InputEventJoypadButton.new() button.button_index = JOY_BUTTON_Y var b := TestUtils.check_eq(InputBindings.descriptor_from_event(button), {"type": "joy", "button": int(JOY_BUTTON_Y)}, "pad buttons store an index") var c := TestUtils.check( InputBindings.descriptor_from_event(InputEventMouseButton.new()).is_empty(), "mouse buttons are not remappable") return a and b and c func test_apply_rebinds_and_keeps_mouse_events() -> bool: var old := InputBindings.current_descriptor("inspect") var remap := {"inspect": {"type": "key", "code": int(KEY_Z)}} InputBindings.apply(remap) var rebound := InputBindings.current_descriptor("inspect") var a := TestUtils.check_eq(rebound, {"type": "key", "code": int(KEY_Z)}, "inspect now uses the new key") var action_menu_mouse := 0 for event in InputMap.action_get_events("action_menu"): if event is InputEventMouseButton: action_menu_mouse += 1 var b := TestUtils.check(action_menu_mouse > 0, "remapping leaves mouse events alone") # Restore the original binding for later tests. if not old.is_empty(): InputBindings.apply({"inspect": old}) return a and b func test_apply_accepts_pad_buttons() -> bool: var remap := {"wand": {"type": "joy", "button": int(JOY_BUTTON_RIGHT_SHOULDER)}} InputBindings.apply(remap) var a := TestUtils.check_eq(InputBindings.current_descriptor("wand"), {"type": "joy", "button": int(JOY_BUTTON_RIGHT_SHOULDER)}, "actions can be rebound to a pad button") InputBindings.apply({"wand": {"type": "key", "code": int(KEY_C)}}) return a func test_labels_are_human_readable() -> bool: var a := TestUtils.check(InputBindings.label_for( {"type": "key", "code": int(KEY_W)}) == "W", "key label") var b := TestUtils.check(InputBindings.label_for( {"type": "joy", "button": 3}) == "Pad 3", "pad label") var c := TestUtils.check_eq(InputBindings.label_for({}), "", "empty label") return a and b and c