A13: Gamepad and accessibility
Gamepad: PadInput reads pad events in one fixed layout (sticks move and look, triggers aim and fire, bumpers step slots and build pieces, Start pauses), fed through ClientInput alongside the keys and mouse. Menus take South to choose and East or Start to go back. The tutorial names pad buttons once the pad is used. Aim assist (option, on by default, pad only): friction across an opponent in plain sight near the look, and a pull of at most 9 deg/s while aiming. Client look only; never through cover. Accessibility (new Access tab): colour-vision sets for the signal colours (red-green, blue-yellow), checked by simulated colour vision in test_palette; interface size 90-130%, with the HUD hotbar refitting at the larger sizes; captions for key sounds with direction; reduce motion (calmer aim zoom and hurt flash). Tests for the pad, aim assist, captions, palettes, settings, the menus driven from a pad, and a pad playing through a real offline session. make access-captures renders the new screens and options. Closes #53 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,93 @@
|
||||
extends TestCase
|
||||
|
||||
## A13: aim assist slows the stick across an opponent in sight and, while aiming,
|
||||
## eases towards them; never through cover, never for the mouse, and only when on.
|
||||
|
||||
const EYE: Vector3 = Vector3(100.0, 10.0, 100.0)
|
||||
|
||||
|
||||
## An opponent `metres` ahead (yaw 0 looks along +z), `degrees` to the left.
|
||||
static func ahead(metres: float, degrees: float) -> Vector3:
|
||||
var angle: float = deg_to_rad(degrees)
|
||||
return EYE + Vector3(sin(angle), 0.0, cos(angle)) * metres
|
||||
|
||||
|
||||
func test_only_opponents_near_the_look_and_in_range_count() -> void:
|
||||
var targets: Array[Vector3] = [ahead(30.0, 20.0), ahead(30.0, 3.0), ahead(200.0, 0.5)]
|
||||
var found: Dictionary = AimAssist.nearest(EYE, 0.0, 0.0, targets)
|
||||
assert_false(found.is_empty())
|
||||
assert_eq(found["point"], targets[1], "the one 3 degrees off, not the far or wide ones")
|
||||
var none: Array[Vector3] = [ahead(30.0, 20.0)]
|
||||
assert_true(AimAssist.nearest(EYE, 0.0, 0.0, none).is_empty())
|
||||
|
||||
|
||||
func test_cover_hides_an_opponent() -> void:
|
||||
var targets: Array[Vector3] = [ahead(30.0, 2.0)]
|
||||
var walled: Callable = func(_from: Vector3, _to: Vector3) -> bool: return false
|
||||
assert_true(AimAssist.nearest(EYE, 0.0, 0.0, targets, walled).is_empty())
|
||||
|
||||
|
||||
func test_friction_is_strongest_at_the_centre() -> void:
|
||||
assert_eq(AimAssist.friction({}), 1.0)
|
||||
var centre: float = AimAssist.friction(AimAssist.nearest(EYE, 0.0, 0.0, [ahead(30.0, 0.0)] as Array[Vector3]))
|
||||
var edge: float = AimAssist.friction(AimAssist.nearest(EYE, 0.0, 0.0, [ahead(30.0, 5.0)] as Array[Vector3]))
|
||||
assert_near(centre, AimAssist.FRICTION, 0.01)
|
||||
assert_true(edge > centre and edge < 1.0)
|
||||
|
||||
|
||||
func test_pull_turns_towards_and_never_past() -> void:
|
||||
var target: Vector3 = ahead(30.0, 2.0)
|
||||
var found: Dictionary = AimAssist.nearest(EYE, 0.0, 0.0, [target] as Array[Vector3])
|
||||
var step: Vector2 = AimAssist.pull(EYE, 0.0, 0.0, found, 0.1)
|
||||
assert_true(step.x > 0.0, "turns left, towards it")
|
||||
assert_true(step.x <= AimAssist.PULL_RADIANS_PER_SECOND * 0.1 + 0.0001, "no faster than the limit")
|
||||
var yaw: float = 0.0
|
||||
for _frame: int in 200:
|
||||
found = AimAssist.nearest(EYE, yaw, 0.0, [target] as Array[Vector3])
|
||||
yaw = AimAssist.pull(EYE, yaw, 0.0, found, 0.05).x
|
||||
assert_true(yaw <= deg_to_rad(2.0) + 0.0001, "never past the opponent: %f" % rad_to_deg(yaw))
|
||||
|
||||
|
||||
func test_through_client_input_only_for_the_pad_and_only_when_on() -> void:
|
||||
var targets: Array[Vector3] = [ahead(30.0, 3.0)]
|
||||
# The pad, aiming and moving the stick a little: the look is drawn left.
|
||||
var input: ClientInput = _aiming_pad(targets)
|
||||
input.handle(TestPad.axis(JOY_AXIS_RIGHT_Y, 0.4), false)
|
||||
for _frame: int in 30:
|
||||
input.poll(1.0 / 60.0)
|
||||
var assisted: float = angle_difference(0.0, input.yaw)
|
||||
assert_true(assisted > 0.002, "pulled towards the opponent: %f" % assisted)
|
||||
# The same with assist off: no sideways pull at all.
|
||||
input = _aiming_pad(targets)
|
||||
input.settings.aim_assist = false
|
||||
input.handle(TestPad.axis(JOY_AXIS_RIGHT_Y, 0.4), false)
|
||||
for _frame: int in 30:
|
||||
input.poll(1.0 / 60.0)
|
||||
assert_near(angle_difference(0.0, input.yaw), 0.0, 0.00001, "off means off")
|
||||
# The mouse with the pad set aside: no pull either.
|
||||
input = _aiming_pad(targets)
|
||||
var key: InputEventKey = InputEventKey.new()
|
||||
key.physical_keycode = KEY_W
|
||||
key.pressed = true
|
||||
input.handle(key, true)
|
||||
var motion: InputEventMouseMotion = InputEventMouseMotion.new()
|
||||
motion.relative = Vector2(0.0, -4.0)
|
||||
input.handle(motion, true)
|
||||
input.poll(1.0 / 60.0)
|
||||
assert_near(angle_difference(0.0, input.yaw), 0.0, 0.00001, "never for the mouse")
|
||||
|
||||
|
||||
func _aiming_pad(targets: Array[Vector3]) -> ClientInput:
|
||||
var input: ClientInput = ClientInput.new()
|
||||
input.eye = EYE
|
||||
input.targets = targets
|
||||
input.handle(TestPad.axis(JOY_AXIS_TRIGGER_LEFT, 1.0), false)
|
||||
return input
|
||||
|
||||
|
||||
class TestPad:
|
||||
static func axis(which: JoyAxis, value: float) -> InputEventJoypadMotion:
|
||||
var event: InputEventJoypadMotion = InputEventJoypadMotion.new()
|
||||
event.axis = which
|
||||
event.axis_value = value
|
||||
return event
|
||||
Reference in New Issue
Block a user