fix(client): address PR #38 review — 6 warnings + 4 suggestions
Hoshe:
- COLOR_FADE_DURATION 0.7 → 0.5 to match D-033 spec ("0.5s fade")
- Gauntlet guard tests now exercise InputMapper._unhandled_input()
with synthesized InputEventKey instead of asserting a bool
- Buffer clearing tests use SimBridge pipeline instead of manual nulls
- Add mid-transition re-trigger test (rapid relationship changes)
- Add relationship field to test snapshot NPC
Tyre:
- Add _teleport_in_progress flag to defer smoothing re-enable by one
frame after teleport (prevents same-_process() re-enable race)
- Add _test_gauntlet_mode to SimBridge test snapshot
- Extract TELEPORT_DISTANCE_THRESHOLD constant, mirror in tests
- Add comments: flash preemption, modulate/color independence
- Rename "hub teleport" → "Gauntlet dev teleport" in code comments
to clarify this is not production fast-travel
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -240,6 +240,34 @@ func test_color_shift_reaches_target() -> void:
|
||||
assert_that(node.color.is_equal_approx(Constants.ENTITY_COLOR_HOSTILE)).is_true()
|
||||
renderer.queue_free()
|
||||
|
||||
func test_color_shift_mid_transition_retrigger() -> void:
|
||||
# Rapid relationship changes: Unknown → Friendly → Hostile in quick succession.
|
||||
# The second change should preempt the first tween and converge to Hostile.
|
||||
var renderer: Node2D = _make_entity_renderer()
|
||||
if not _entity_uses_relationship(renderer):
|
||||
renderer.queue_free()
|
||||
return
|
||||
if not _renderer_has_tween_support(renderer):
|
||||
renderer.queue_free()
|
||||
return
|
||||
renderer.update_entities([_make_entity(2, "Npc", "Unknown")])
|
||||
# First change: Unknown → Friendly
|
||||
renderer.update_entities([_make_entity(2, "Npc", "Friendly")])
|
||||
# Advance partway (0.1s of a 0.5s tween)
|
||||
for i in range(6):
|
||||
renderer._process(1.0 / 60.0)
|
||||
# Second change mid-tween: Friendly → Hostile (preempts first)
|
||||
renderer.update_entities([_make_entity(2, "Npc", "Hostile")])
|
||||
# Advance past full duration
|
||||
var elapsed: float = 0.0
|
||||
while elapsed < 1.0:
|
||||
renderer._process(1.0 / 60.0)
|
||||
elapsed += 1.0 / 60.0
|
||||
var node: ColorRect = renderer.entity_nodes[2] as ColorRect
|
||||
assert_that(node.color.is_equal_approx(Constants.ENTITY_COLOR_HOSTILE)).is_true()
|
||||
renderer.queue_free()
|
||||
|
||||
|
||||
func test_color_shift_same_relationship_no_tween() -> void:
|
||||
var renderer: Node2D = _make_entity_renderer()
|
||||
if not _entity_uses_relationship(renderer):
|
||||
|
||||
@@ -73,20 +73,34 @@ func test_teleport_hub_action_exists() -> void:
|
||||
|
||||
# -- InputMapper: Gauntlet mode guard -----------------------------------------
|
||||
|
||||
func test_teleport_hub_gated_by_gauntlet_mode() -> void:
|
||||
# Non-gauntlet: Home key should NOT queue TELEPORT_HUB
|
||||
func test_teleport_hub_blocked_outside_gauntlet() -> void:
|
||||
# Non-gauntlet: Home key input should NOT queue TELEPORT_HUB
|
||||
GameState.gauntlet_mode = false
|
||||
# Simulate what _unhandled_input does: check gauntlet_mode before queuing
|
||||
# (We test the guard logic, not the full input event pipeline)
|
||||
var should_queue := GameState.gauntlet_mode
|
||||
assert_that(should_queue).is_false()
|
||||
InputMapper.input_queue.clear()
|
||||
var event := InputEventKey.new()
|
||||
event.physical_keycode = KEY_HOME
|
||||
event.pressed = true
|
||||
InputMapper._unhandled_input(event)
|
||||
var has_teleport := false
|
||||
for entry in InputMapper.input_queue:
|
||||
if entry.action == InputMapper.Action.TELEPORT_HUB:
|
||||
has_teleport = true
|
||||
assert_that(has_teleport).is_false()
|
||||
|
||||
|
||||
func test_teleport_hub_allowed_in_gauntlet_mode() -> void:
|
||||
# Gauntlet mode: Home key SHOULD queue TELEPORT_HUB
|
||||
GameState.gauntlet_mode = true
|
||||
var should_queue := GameState.gauntlet_mode
|
||||
assert_that(should_queue).is_true()
|
||||
InputMapper.input_queue.clear()
|
||||
var event := InputEventKey.new()
|
||||
event.physical_keycode = KEY_HOME
|
||||
event.pressed = true
|
||||
InputMapper._unhandled_input(event)
|
||||
var has_teleport := false
|
||||
for entry in InputMapper.input_queue:
|
||||
if entry.action == InputMapper.Action.TELEPORT_HUB:
|
||||
has_teleport = true
|
||||
assert_that(has_teleport).is_true()
|
||||
|
||||
|
||||
# -- GameState: gauntlet_mode from snapshot ------------------------------------
|
||||
@@ -161,67 +175,70 @@ func test_test_mode_teleport_clears_dialogue() -> void:
|
||||
|
||||
|
||||
# -- Teleport detection -------------------------------------------------------
|
||||
# Threshold constant lives on the main scene node (TELEPORT_DISTANCE_THRESHOLD = 5.0).
|
||||
# These tests verify the distance math against that threshold.
|
||||
|
||||
const _THRESHOLD: float = 5.0 # Mirror of main.gd TELEPORT_DISTANCE_THRESHOLD
|
||||
|
||||
func test_detect_teleport_large_jump() -> void:
|
||||
# Position jump > 5 tiles should be detected as teleport
|
||||
# _detect_teleport is a method on the main scene — test the math directly
|
||||
# Position jump > threshold should be detected as teleport
|
||||
var old_pos := Vector2(10.0, 10.0)
|
||||
var new_pos := Vector2(50.0, 50.0)
|
||||
var distance := old_pos.distance_to(new_pos)
|
||||
assert_that(distance > 5.0).is_true()
|
||||
assert_that(old_pos.distance_to(new_pos) > _THRESHOLD).is_true()
|
||||
|
||||
|
||||
func test_detect_teleport_normal_movement() -> void:
|
||||
# Normal 1-tile movement should NOT be detected as teleport
|
||||
var old_pos := Vector2(10.0, 10.0)
|
||||
var new_pos := Vector2(11.0, 10.0)
|
||||
var distance := old_pos.distance_to(new_pos)
|
||||
assert_that(distance > 5.0).is_false()
|
||||
assert_that(old_pos.distance_to(new_pos) > _THRESHOLD).is_false()
|
||||
|
||||
|
||||
func test_detect_teleport_diagonal_movement() -> void:
|
||||
# Diagonal movement (1,1) — distance ~1.41, not a teleport
|
||||
var old_pos := Vector2(10.0, 10.0)
|
||||
var new_pos := Vector2(11.0, 11.0)
|
||||
var distance := old_pos.distance_to(new_pos)
|
||||
assert_that(distance > 5.0).is_false()
|
||||
assert_that(old_pos.distance_to(new_pos) > _THRESHOLD).is_false()
|
||||
|
||||
|
||||
func test_detect_teleport_boundary_exactly_five() -> void:
|
||||
# Exactly 5.0 tiles — should NOT trigger (threshold is > 5.0, not >=)
|
||||
func test_detect_teleport_boundary_exactly_threshold() -> void:
|
||||
# Exactly threshold — should NOT trigger (> not >=)
|
||||
var old_pos := Vector2(10.0, 10.0)
|
||||
var new_pos := Vector2(15.0, 10.0)
|
||||
var distance := old_pos.distance_to(new_pos)
|
||||
assert_that(distance > 5.0).is_false()
|
||||
assert_that(old_pos.distance_to(new_pos) > _THRESHOLD).is_false()
|
||||
|
||||
|
||||
func test_detect_teleport_boundary_just_over_five() -> void:
|
||||
# 5.1 tiles — should trigger
|
||||
func test_detect_teleport_boundary_just_over() -> void:
|
||||
# Just over threshold — should trigger
|
||||
var old_pos := Vector2(10.0, 10.0)
|
||||
var new_pos := Vector2(15.1, 10.0)
|
||||
var distance := old_pos.distance_to(new_pos)
|
||||
assert_that(distance > 5.0).is_true()
|
||||
assert_that(old_pos.distance_to(new_pos) > _THRESHOLD).is_true()
|
||||
|
||||
|
||||
# -- Buffer clearing on teleport -----------------------------------------------
|
||||
|
||||
func test_teleport_clears_monologue_state() -> void:
|
||||
# Teleport transition must clear current_monologue
|
||||
GameState.current_monologue = {"id": "test_mono", "text": "test", "duration_seconds": 5.0}
|
||||
# Simulate what _teleport_transition does
|
||||
GameState.current_monologue = null
|
||||
assert_that(GameState.current_monologue).is_null()
|
||||
func test_teleport_clears_dialogue_in_test_mode() -> void:
|
||||
# TeleportToHub in test mode should clear dialogue state via the pipeline
|
||||
SimBridge.reset_test_state()
|
||||
SimBridge._test_in_dialogue = true
|
||||
SimBridge._test_input_queue.append("TeleportToHub")
|
||||
var snap: Dictionary = SimBridge._test_snapshot()
|
||||
# Dialogue should be cleared by teleport
|
||||
assert_that(SimBridge._test_in_dialogue).is_false()
|
||||
assert_that(snap.current_dialogue).is_null()
|
||||
|
||||
|
||||
func test_teleport_clears_dialogue_state() -> void:
|
||||
# Teleport transition must clear current_dialogue and dialogue_active
|
||||
GameState.current_dialogue = {"npc_name": "Kael", "speech": "test", "options": []}
|
||||
GameState.dialogue_active = true
|
||||
# Simulate what _teleport_transition does
|
||||
GameState.current_dialogue = null
|
||||
GameState.dialogue_active = false
|
||||
assert_that(GameState.current_dialogue).is_null()
|
||||
assert_that(GameState.dialogue_active).is_false()
|
||||
func test_teleport_resets_position_in_test_mode() -> void:
|
||||
# TeleportToHub must reset to hub spawn and clear dialogue (integration)
|
||||
SimBridge.reset_test_state()
|
||||
SimBridge._test_player_pos = Vector2i(50, 50)
|
||||
SimBridge._test_in_dialogue = true
|
||||
SimBridge._test_input_queue.append("TeleportToHub")
|
||||
var snap: Dictionary = SimBridge._test_snapshot()
|
||||
var player: Dictionary = snap.entities[0]
|
||||
assert_that(player.x).is_equal(10.0)
|
||||
assert_that(player.y).is_equal(10.0)
|
||||
assert_that(SimBridge._test_in_dialogue).is_false()
|
||||
|
||||
|
||||
# -- Send input integration (test mode) ----------------------------------------
|
||||
@@ -248,6 +265,17 @@ func test_send_teleport_hub_queues_wire_action() -> void:
|
||||
assert_that(SimBridge._test_input_queue.has("TeleportToHub")).is_true()
|
||||
|
||||
|
||||
func test_gauntlet_mode_from_test_snapshot() -> void:
|
||||
# Verify test snapshot includes gauntlet_mode field
|
||||
SimBridge.reset_test_state()
|
||||
SimBridge._test_gauntlet_mode = true
|
||||
var snap: Dictionary = SimBridge._test_snapshot()
|
||||
assert_that(snap.gauntlet_mode).is_true()
|
||||
SimBridge._test_gauntlet_mode = false
|
||||
snap = SimBridge._test_snapshot()
|
||||
assert_that(snap.gauntlet_mode).is_false()
|
||||
|
||||
|
||||
# -- Live mode outbound encoding -----------------------------------------------
|
||||
|
||||
func test_teleport_hub_outbound_entry() -> void:
|
||||
|
||||
Reference in New Issue
Block a user