43 lines
2.3 KiB
GDScript
43 lines
2.3 KiB
GDScript
extends SceneTree
|
|
|
|
const TEST_PATH := "user://controls-test.cfg"
|
|
var failures := 0
|
|
|
|
func check(condition: bool, description: String) -> void:
|
|
if not condition:
|
|
failures += 1
|
|
push_error(description)
|
|
|
|
func _initialize() -> void:
|
|
ControlBindings.defaults()
|
|
check(ControlBindings.assign("reload", 1, {"kind": "mouse", "code": MOUSE_BUTTON_XBUTTON2}), "Alternative mouse button")
|
|
check(InputMap.action_get_events("reload").size() == 2, "Two bindings active")
|
|
check(not ControlBindings.assign("reload", 0, {"kind": "key", "code": KEY_W}), "Conflict rejected")
|
|
check(ControlBindings.assign("reload", 0, {"kind": "key", "code": KEY_W}, true), "Conflict swap")
|
|
check(ControlBindings.bindings.forward[0].code == KEY_R, "Swap preserves displaced action")
|
|
check(not ControlBindings.assign("pause", 0, {}), "Last menu key protected")
|
|
check(not ControlBindings.assign("aim", 0, {"kind": "mouse", "code": MOUSE_BUTTON_WHEEL_UP}), "Held wheel rejected")
|
|
check(ControlBindings.assign("switch", 0, {"kind": "mouse", "code": MOUSE_BUTTON_WHEEL_UP}), "Wheel weapon switch")
|
|
check(not ControlBindings.assign("switch", 0, {"kind": "key", "code": KEY_R}, true), "Swap cannot transfer wheel to movement")
|
|
check(ControlBindings.save(TEST_PATH) == OK, "Save bindings")
|
|
ControlBindings.defaults()
|
|
ControlBindings.setup(TEST_PATH)
|
|
check(ControlBindings.bindings.reload[1].code == MOUSE_BUTTON_XBUTTON2, "Reload saved mouse button")
|
|
ControlBindings.setup(TEST_PATH)
|
|
check(InputMap.action_get_events("reload").size() == 2, "Restore does not accumulate events")
|
|
var event := InputEventKey.new()
|
|
event.physical_keycode = KEY_W
|
|
event.pressed = true
|
|
check(event.is_action("reload") and not event.is_action("forward"), "Actual remapped event resolves")
|
|
var config := ConfigFile.new()
|
|
config.set_value("bindings", "pause", [{}, {}])
|
|
config.set_value("bindings", "aim", [{"kind": "mouse", "code": MOUSE_BUTTON_WHEEL_UP}, {}])
|
|
config.save(TEST_PATH)
|
|
ControlBindings.setup(TEST_PATH)
|
|
check(not ControlBindings.bindings.pause[0].is_empty(), "Corrupt config retains menu")
|
|
check(ControlBindings.bindings.aim[0].code == MOUSE_BUTTON_RIGHT, "Corrupt held wheel falls back")
|
|
DirAccess.remove_absolute(ProjectSettings.globalize_path(TEST_PATH))
|
|
ControlBindings.defaults()
|
|
print("CONTROLS: ", failures, " failures")
|
|
quit(0 if failures == 0 else 1)
|