feat(client): upgrade protocol decoder and GameState for v2 snapshot
Server shipped ObserverSnapshot v2 with game_time, player_facing, visible_tiles (with visibility sectors), and per-entity visibility. Protocol decoder was silently ignoring these fields. Now extracts all v2 data with null defaults for backward compatibility. GameState gains game_time, player_facing, visibility_sectors vars. Derives visible_positions from visible_tiles when present (for real server mode). Test snapshot updated with v2 fields. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -271,6 +271,57 @@ func test_encode_player_inputs_empty() -> void:
|
||||
assert_that(raw.value.size()).is_equal(0)
|
||||
|
||||
|
||||
# -- v2 snapshot decoding -------------------------------------------------------
|
||||
|
||||
func test_decode_snapshot_v2_full() -> void:
|
||||
var bytes = _load_fixture("snapshot_v2_full")
|
||||
var snapshot = Protocol.decode_snapshot(bytes)
|
||||
|
||||
assert_that(snapshot).is_not_null()
|
||||
assert_that(snapshot.tick).is_equal(500)
|
||||
assert_that(snapshot.version).is_equal(2)
|
||||
|
||||
# game_time
|
||||
assert_that(snapshot.game_time).is_not_null()
|
||||
assert_that(snapshot.game_time.day).is_equal(1)
|
||||
assert_that(snapshot.game_time.time_of_day).is_equal(720)
|
||||
assert_that(snapshot.game_time.paused).is_false()
|
||||
|
||||
# player_facing (unit enum → bare string)
|
||||
assert_that(snapshot.player_facing).is_equal("Southeast")
|
||||
|
||||
# entities with visibility sector
|
||||
assert_that(snapshot.entities.size()).is_equal(1)
|
||||
assert_that(snapshot.entities[0].visibility).is_equal("Forward")
|
||||
|
||||
# visible_tiles
|
||||
assert_that(snapshot.visible_tiles.size()).is_equal(3)
|
||||
assert_that(snapshot.visible_tiles[0].x).is_equal(10)
|
||||
assert_that(snapshot.visible_tiles[0].visibility).is_equal("Forward")
|
||||
assert_that(snapshot.visible_tiles[1].visibility).is_equal("Peripheral")
|
||||
|
||||
|
||||
func test_existing_fixtures_have_v2_fields() -> void:
|
||||
# All fixtures are generated by v2 fixture_snapshot() — verify decoder extracts v2 fields
|
||||
for fixture_name in ["snapshot_one_npc", "snapshot_empty", "snapshot_player", "snapshot_multi_entity"]:
|
||||
var bytes = _load_fixture(fixture_name)
|
||||
var snapshot = Protocol.decode_snapshot(bytes)
|
||||
assert_that(snapshot).is_not_null()
|
||||
assert_that(snapshot.version).is_equal(2)
|
||||
assert_that(snapshot.player_facing).is_equal("North")
|
||||
assert_that(snapshot.game_time).is_not_null()
|
||||
|
||||
|
||||
func test_multi_entity_visibility_sectors() -> void:
|
||||
# snapshot_multi_entity has: Player=Forward, Npc=Peripheral, Object=Forward, Terrain=Forward
|
||||
var bytes = _load_fixture("snapshot_multi_entity")
|
||||
var snapshot = Protocol.decode_snapshot(bytes)
|
||||
assert_that(snapshot.entities[0].visibility).is_equal("Forward")
|
||||
assert_that(snapshot.entities[1].visibility).is_equal("Peripheral")
|
||||
assert_that(snapshot.entities[2].visibility).is_equal("Forward")
|
||||
assert_that(snapshot.entities[3].visibility).is_equal("Forward")
|
||||
|
||||
|
||||
# -- Batch input fixture (D-030 Layer 1 bidirectional symmetry) ----------------
|
||||
|
||||
func test_decode_batch_input_fixture() -> void:
|
||||
|
||||
Reference in New Issue
Block a user