Warnings: facing indicator tests use Godot-normalized rotation range (-PI, PI] instead of raw addition (SW/W/NW in test_rendering, West in test_client_p3). Suggestions: cache font in world_radial _draw(), fix docstring on deactivate_insert() trigger, document tile-coordinate system on _eval_player_near (D-066), add public reset_facing_state() to InputMapper (D-030 testability). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
120 lines
4.7 KiB
GDScript
120 lines
4.7 KiB
GDScript
## D-054 facing and movement tests — _angle_to_octant, _snap_to_octant_dir,
|
|
## _wasd_to_world_dir coverage. All functions are static or use only facing_angle.
|
|
##
|
|
## Spec ref: D-054 (mouse-relative facing), Sprint 10 Completion Proof.
|
|
class_name TestInputMapperFacing
|
|
extends GdUnitTestSuite
|
|
|
|
|
|
# -- _angle_to_octant ----------------------------------------------------------
|
|
|
|
func test_angle_to_octant_east() -> void:
|
|
assert_str(InputMapper._angle_to_octant(0.0)).is_equal("East")
|
|
|
|
func test_angle_to_octant_north() -> void:
|
|
assert_str(InputMapper._angle_to_octant(-PI / 2.0)).is_equal("North")
|
|
|
|
func test_angle_to_octant_south() -> void:
|
|
assert_str(InputMapper._angle_to_octant(PI / 2.0)).is_equal("South")
|
|
|
|
func test_angle_to_octant_west() -> void:
|
|
assert_str(InputMapper._angle_to_octant(PI)).is_equal("West")
|
|
|
|
func test_angle_to_octant_northeast() -> void:
|
|
assert_str(InputMapper._angle_to_octant(-PI / 4.0)).is_equal("Northeast")
|
|
|
|
func test_angle_to_octant_southeast() -> void:
|
|
assert_str(InputMapper._angle_to_octant(PI / 4.0)).is_equal("Southeast")
|
|
|
|
func test_angle_to_octant_southwest() -> void:
|
|
assert_str(InputMapper._angle_to_octant(3.0 * PI / 4.0)).is_equal("Southwest")
|
|
|
|
func test_angle_to_octant_northwest() -> void:
|
|
assert_str(InputMapper._angle_to_octant(-3.0 * PI / 4.0)).is_equal("Northwest")
|
|
|
|
|
|
# -- _snap_to_octant_dir -------------------------------------------------------
|
|
|
|
func test_snap_east() -> void:
|
|
assert_object(InputMapper._snap_to_octant_dir(Vector2(1.0, 0.0))).is_equal(Vector2i(1, 0))
|
|
|
|
func test_snap_north() -> void:
|
|
assert_object(InputMapper._snap_to_octant_dir(Vector2(0.0, -1.0))).is_equal(Vector2i(0, -1))
|
|
|
|
func test_snap_south() -> void:
|
|
assert_object(InputMapper._snap_to_octant_dir(Vector2(0.0, 1.0))).is_equal(Vector2i(0, 1))
|
|
|
|
func test_snap_west() -> void:
|
|
assert_object(InputMapper._snap_to_octant_dir(Vector2(-1.0, 0.0))).is_equal(Vector2i(-1, 0))
|
|
|
|
func test_snap_northeast() -> void:
|
|
assert_object(InputMapper._snap_to_octant_dir(Vector2(0.7, -0.7))).is_equal(Vector2i(1, -1))
|
|
|
|
func test_snap_southwest() -> void:
|
|
assert_object(InputMapper._snap_to_octant_dir(Vector2(-0.7, 0.7))).is_equal(Vector2i(-1, 1))
|
|
|
|
func test_snap_zero_returns_zero() -> void:
|
|
assert_object(InputMapper._snap_to_octant_dir(Vector2.ZERO)).is_equal(Vector2i.ZERO)
|
|
|
|
func test_snap_tiny_returns_zero() -> void:
|
|
assert_object(InputMapper._snap_to_octant_dir(Vector2(0.001, 0.0))).is_equal(Vector2i.ZERO)
|
|
|
|
func test_snap_diagonal_bias() -> void:
|
|
# Slightly more east than north — should snap to northeast
|
|
assert_object(InputMapper._snap_to_octant_dir(Vector2(0.8, -0.6))).is_equal(Vector2i(1, -1))
|
|
|
|
|
|
# -- _wasd_to_world_dir --------------------------------------------------------
|
|
|
|
func test_wasd_forward_facing_east() -> void:
|
|
# W pressed, facing east → move east
|
|
InputMapper.facing_angle = 0.0 # East
|
|
var result := InputMapper._wasd_to_world_dir(Vector2i(0, -1))
|
|
assert_object(result).is_equal(Vector2i(1, 0))
|
|
|
|
func test_wasd_forward_facing_north() -> void:
|
|
# W pressed, facing north → move north
|
|
InputMapper.facing_angle = -PI / 2.0 # North
|
|
var result := InputMapper._wasd_to_world_dir(Vector2i(0, -1))
|
|
assert_object(result).is_equal(Vector2i(0, -1))
|
|
|
|
func test_wasd_backward_facing_north() -> void:
|
|
# S pressed, facing north → move south
|
|
InputMapper.facing_angle = -PI / 2.0 # North
|
|
var result := InputMapper._wasd_to_world_dir(Vector2i(0, 1))
|
|
assert_object(result).is_equal(Vector2i(0, 1))
|
|
|
|
func test_wasd_strafe_right_facing_north() -> void:
|
|
# D pressed, facing north → move east
|
|
InputMapper.facing_angle = -PI / 2.0 # North
|
|
var result := InputMapper._wasd_to_world_dir(Vector2i(1, 0))
|
|
assert_object(result).is_equal(Vector2i(1, 0))
|
|
|
|
func test_wasd_strafe_left_facing_north() -> void:
|
|
# A pressed, facing north → move west
|
|
InputMapper.facing_angle = -PI / 2.0 # North
|
|
var result := InputMapper._wasd_to_world_dir(Vector2i(-1, 0))
|
|
assert_object(result).is_equal(Vector2i(-1, 0))
|
|
|
|
func test_wasd_forward_facing_south() -> void:
|
|
# W pressed, facing south → move south
|
|
InputMapper.facing_angle = PI / 2.0 # South
|
|
var result := InputMapper._wasd_to_world_dir(Vector2i(0, -1))
|
|
assert_object(result).is_equal(Vector2i(0, 1))
|
|
|
|
func test_wasd_diagonal_forward_right_facing_east() -> void:
|
|
# W+D pressed, facing east → move southeast
|
|
InputMapper.facing_angle = 0.0 # East
|
|
var result := InputMapper._wasd_to_world_dir(Vector2i(1, -1))
|
|
assert_object(result).is_equal(Vector2i(1, 1))
|
|
|
|
func test_wasd_strafe_right_facing_west() -> void:
|
|
# D pressed, facing west → move north
|
|
InputMapper.facing_angle = PI # West
|
|
var result := InputMapper._wasd_to_world_dir(Vector2i(1, 0))
|
|
assert_object(result).is_equal(Vector2i(0, -1))
|
|
|
|
|
|
func after_test() -> void:
|
|
InputMapper.reset_facing_state()
|