fix(client): address PR #141 review — parse-order, tween guard, test fixes

- Fix autoload parse-order violations: sim_bridge.gd, input_mapper.gd,
  audio_manager.gd now use load() for class_name types instead of
  direct references (LocalBridge, ServerProcess, Constants)
- Collapse redundant tween validity guard in dialogue_box.gd to
  is_instance_valid(panel) only
- Add clarifying comments to fog test resize assertions (8-tile
  padding trigger, 32x32 fixture assumption)
- Fix test_examine_display_sprint18 case 2: GameState.has() →
  "field" in GameState (Node vs Dictionary API)
- Fix test_game_state_sprint20: rename before_each → before_test
  (GdUnit4 lifecycle hook)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-02 22:50:17 +02:00
co-authored by Claude Opus 4.6
parent e002f811f0
commit 702fed5922
7 changed files with 21 additions and 14 deletions
+2 -1
View File
@@ -231,7 +231,8 @@ func play_sound_event(event_type: String, world_tile_pos: Vector2) -> void:
var asset_key: String = SOUND_EVENT_ASSETS.get(event_type, "")
if asset_key.is_empty():
return
play_at(asset_key, world_tile_pos * Constants.TILE_SIZE)
var C := load("res://scripts/constants.gd")
play_at(asset_key, world_tile_pos * C.TILE_SIZE)
# --- Playback: spatial (D-018 close-range) ---
+5 -4
View File
@@ -184,10 +184,11 @@ func _update_facing_from_mouse() -> void:
if vp == null:
return
var canvas_xf := vp.get_canvas_transform()
var player_world_px := GameState.player_position * Constants.TILE_SIZE
var player_screen := canvas_xf * player_world_px
var mouse_screen := vp.get_mouse_position()
var delta := mouse_screen - player_screen
var C := load("res://scripts/constants.gd")
var player_world_px: Vector2 = GameState.player_position * C.TILE_SIZE
var player_screen: Vector2 = canvas_xf * player_world_px
var mouse_screen: Vector2 = vp.get_mouse_position()
var delta: Vector2 = mouse_screen - player_screen
# Only update if mouse is meaningfully distant from player (avoid jitter at center)
if delta.length_squared() > 4.0:
facing_angle = delta.angle()
+6 -4
View File
@@ -27,8 +27,8 @@ var _last_snapshot: Variant = null # Most recent decoded snapshot (consumed by
var _outbound_buffer: Array[Dictionary] = [] # Raw inputs awaiting batch encode + transport
# Transport layer (non-test mode)
var _bridge: LocalBridge = null
var _server: ServerProcess = null
var _bridge = null # LocalBridge
var _server = null # ServerProcess
var _connect_retries: int = 0
var _retry_timer: float = 0.0
var _handshake_start_usec: int = 0
@@ -126,7 +126,8 @@ func connect_to_sim() -> void:
# Spawn server subprocess
if not server_path.is_empty():
_server = ServerProcess.new()
var SP := load("res://scripts/protocol/server_process.gd")
_server = SP.new()
# Server reads first positional arg as bind address (e.g. "127.0.0.1:9876").
# D-085 (#258): pass --game-id <id> so server logs use the same session identifier.
var args := ["127.0.0.1:" + str(server_port)]
@@ -159,7 +160,8 @@ func disconnect_from_sim() -> void:
# Attempt TCP connection. Called from _process() during CONNECTING state.
func _try_connect() -> void:
_bridge = LocalBridge.new()
var LB := load("res://scripts/protocol/local_bridge.gd")
_bridge = LB.new()
var err := _bridge.connect_to_server("127.0.0.1", server_port)
if err != OK:
push_warning(
@@ -52,7 +52,7 @@ func after_test() -> void:
# ---------------------------------------------------------------------------
func test_gamestate_examine_result_field_exists() -> void:
assert_bool(GameState.has("current_examine_result")).override_failure_message(
assert_bool("current_examine_result" in GameState).override_failure_message(
"GameState must have 'current_examine_result' field (#174)"
).is_true()
+5 -2
View File
@@ -25,6 +25,7 @@ func _reset_fog_state(fog_state: Node) -> void:
GameState.boundary_positions.clear()
GameState.visible_tiles.clear()
GameState.visibility_sectors.clear()
# 32x32 is an arbitrary test fixture size — not a production assumption.
fog_state._resize(Rect2i(0, 0, 32, 32))
@@ -220,7 +221,8 @@ func test_exploration_data_preserved_across_resize() -> void:
GameState.visible_positions = {Vector2i(3, 3): true}
fog_state.update_from_state()
# Force a resize by moving far away
# Move far enough to trigger a resize: _grow_bounds_from_positions adds 8-tile padding,
# so (25,25) expands the bounds beyond the 32x32 fixture set in _reset_fog_state.
GameState.visible_positions = {Vector2i(25, 25): true}
fog_state.update_from_state()
@@ -250,7 +252,8 @@ func test_newly_added_area_starts_unexplored_after_resize() -> void:
GameState.visible_positions = {Vector2i(2, 2): true}
fog_state.update_from_state()
# Move far away to trigger bounds growth
# Move far enough to trigger a resize: _grow_bounds_from_positions adds 8-tile padding,
# so (30,30) expands the bounds beyond the 32x32 fixture set in _reset_fog_state.
GameState.visible_positions = {Vector2i(30, 30): true}
fog_state.update_from_state()
+1 -1
View File
@@ -12,7 +12,7 @@ class_name TestGameStateSprint20
extends GdUnitTestSuite
func before_each() -> void:
func before_test() -> void:
GameState.stationary_ticks = 0
SnapshotHandler._prev_player_position = Vector2(-1e9, -1e9)
GameState.current_zone_id = ""
+1 -1
View File
@@ -498,7 +498,7 @@ func _start_confrontation_beat(response_id: String, text: String) -> void:
if _active_tween and _active_tween.is_valid():
_active_tween.kill()
_active_tween = create_tween()
if _active_tween and _active_tween.is_valid() and is_instance_valid(panel):
if is_instance_valid(panel):
_active_tween.tween_property(panel, "modulate:a", CONFRONTATION_DIM_ALPHA, 0.2)
confrontation_monologue.emit(