fix(client): address PR #36 review — 10 items from Hoshe + Tyre
Critical: - deactivate_insert() now called when selecting non-Insert spoke, cancelling with no selection, or pressing Escape while insert is active. Fixes simulation staying paused permanently after Insert. Warnings: - Checklist conditions with empty id excluded from get_results() and get_total_count() — prevents impossible-to-complete checklists. Warns at load time when empty-id conditions are found. - _content_base now checks res://content/ first (exported builds), falls back to ../content for editor/dev mode. - 26 new tests for D-054 functions: _angle_to_octant (8 octants), _snap_to_octant_dir (9 cases incl. zero/tiny), _wasd_to_world_dir (8 facing/movement combos). New test file: test_input_mapper_facing.gd. Suggestions: - Cached get_theme_default_font() in checklist overlay _ready(). - Documented InputMapper → GameState coupling as intentional. - Documented YAML parser # truncation limitation. - _insert_active reset on Escape dismiss (Tyre #3). - SimBridge test mode SetFacing reads action_data.facing instead of InputMapper global (Tyre #4). - Removed dead _facing_to_rotation() from entity_renderer.gd (Tyre #5). - Fixed 2 failing facing indicator tests to use InputMapper.facing_angle instead of GameState.player_facing. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -253,27 +253,29 @@ func test_recognition_transition_progress() -> void:
|
||||
fog_entities.queue_free()
|
||||
|
||||
|
||||
func test_facing_indicator_rotation_matches_player_facing() -> void:
|
||||
# P3-T02: Facing indicator rotation matches player_facing from snapshot.
|
||||
func test_facing_indicator_rotation_matches_input_mapper_angle() -> void:
|
||||
# P3-T02: D-054 — Facing indicator uses InputMapper.facing_angle (client-side float).
|
||||
# Indicator rotation = facing_angle + PI/2 (0=North basis).
|
||||
GameState.player_entity_id = 1
|
||||
var renderer := _make_entity_renderer()
|
||||
var entity := [{"entity_id": 1, "x": 5.0, "y": 5.0, "z": 0,
|
||||
"kind": {"variant": "Player", "data": null}, "visibility": "Forward"}]
|
||||
renderer.update_entities(entity)
|
||||
var indicator = renderer.entity_nodes[1].get_node("FacingIndicator")
|
||||
# Test each cardinal + diagonal direction
|
||||
var expected := {
|
||||
"North": 0.0,
|
||||
"East": PI / 2.0,
|
||||
"South": PI,
|
||||
"West": 3.0 * PI / 2.0,
|
||||
# {facing_angle → expected indicator rotation}
|
||||
var angles := {
|
||||
-PI / 2.0: 0.0, # North
|
||||
0.0: PI / 2.0, # East
|
||||
PI / 2.0: PI, # South
|
||||
PI: 3.0 * PI / 2.0, # West
|
||||
}
|
||||
for dir in expected:
|
||||
GameState.player_facing = dir
|
||||
for angle in angles:
|
||||
InputMapper.facing_angle = angle
|
||||
renderer.update_entities(entity)
|
||||
assert_that(indicator.rotation).override_failure_message(
|
||||
"%s: expected rotation %.3f, got %.3f" % [dir, expected[dir], indicator.rotation]
|
||||
).is_equal_approx(expected[dir], 0.001)
|
||||
"angle %.3f: expected rotation %.3f, got %.3f" % [angle, angles[angle], indicator.rotation]
|
||||
).is_equal_approx(angles[angle], 0.001)
|
||||
InputMapper.facing_angle = -PI / 2.0 # Reset to default
|
||||
renderer.queue_free()
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,122 @@
|
||||
## 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:
|
||||
# Reset facing to default
|
||||
InputMapper.facing_angle = -PI / 2.0
|
||||
InputMapper.facing_octant = "North"
|
||||
InputMapper._last_sent_octant = "North"
|
||||
@@ -298,25 +298,30 @@ func test_entity_renderer_player_has_facing_indicator() -> void:
|
||||
renderer.queue_free()
|
||||
|
||||
func test_entity_renderer_facing_indicator_rotation_accuracy() -> void:
|
||||
# D-054: Facing indicator now reads InputMapper.facing_angle (float), not
|
||||
# GameState.player_facing (string). Indicator rotation = facing_angle + PI/2.
|
||||
GameState.player_entity_id = 1
|
||||
var renderer := _make_entity_renderer()
|
||||
var directions := {
|
||||
"North": 0.0,
|
||||
"Northeast": PI / 4.0,
|
||||
"East": PI / 2.0,
|
||||
"Southeast": 3.0 * PI / 4.0,
|
||||
"South": PI,
|
||||
"Southwest": 5.0 * PI / 4.0,
|
||||
"West": 3.0 * PI / 2.0,
|
||||
"Northwest": 7.0 * PI / 4.0,
|
||||
# {facing_angle → expected indicator rotation}
|
||||
# Indicator 0 = North (up). facing_angle 0 = East. So rotation = angle + PI/2.
|
||||
var angles := {
|
||||
-PI / 2.0: 0.0, # North
|
||||
-PI / 4.0: PI / 4.0, # Northeast
|
||||
0.0: PI / 2.0, # East
|
||||
PI / 4.0: 3.0 * PI / 4.0, # Southeast
|
||||
PI / 2.0: PI, # South
|
||||
3.0 * PI / 4.0: 5.0 * PI / 4.0, # Southwest
|
||||
PI: 3.0 * PI / 2.0, # West
|
||||
-3.0 * PI / 4.0: 7.0 * PI / 4.0, # Northwest (note: -PI/2 wraps)
|
||||
}
|
||||
renderer.update_entities(_test_entities_v2)
|
||||
var player_node = renderer.entity_nodes[1]
|
||||
var indicator = player_node.get_node_or_null("FacingIndicator")
|
||||
for dir_name in directions:
|
||||
GameState.player_facing = dir_name
|
||||
for angle in angles:
|
||||
InputMapper.facing_angle = angle
|
||||
renderer.update_entities(_test_entities_v2)
|
||||
assert_that(indicator.rotation).is_equal_approx(directions[dir_name], 0.001)
|
||||
assert_that(indicator.rotation).is_equal_approx(angles[angle], 0.001)
|
||||
InputMapper.facing_angle = -PI / 2.0 # Reset to default (North)
|
||||
renderer.queue_free()
|
||||
|
||||
func test_entity_renderer_npc_has_no_facing_indicator() -> void:
|
||||
|
||||
Reference in New Issue
Block a user