feat(client): sync protocol to v8 — dialogue_response + Interact encoding
Bump PROTOCOL_VERSION from 7 to 8 to match server. Three changes:
1. Add dialogue_response field decoding (DialogueResponseEvent with
line_id, text, speaker_entity_id) from server #305/D-028.
2. Fix Interact encoding: server changed PlayerAction::Interact from
unit variant to struct variant with {target_entity_id, verb}.
Extract _encode_action() helper to handle this consistently.
3. Update all test assertions that checked version=7 or expected
Interact as a bare string.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -195,15 +195,19 @@ func test_prompt_hidden_initially() -> void:
|
||||
|
||||
# -- Input encoding: Interact --
|
||||
|
||||
func test_interact_encodes_as_unit_variant() -> void:
|
||||
func test_interact_encodes_as_struct_variant() -> void:
|
||||
# Interact is always a struct variant: {"Interact": {"target_entity_id": null, "verb": null}}
|
||||
var inputs: Array = [{"tick": 100, "action_name": "Interact"}]
|
||||
var bytes := Protocol.encode_player_inputs(inputs)
|
||||
var raw = Messagepack.decode(bytes)
|
||||
assert_that(raw.status == null).is_true()
|
||||
assert_that(raw.value[0]["action"]).is_equal("Interact")
|
||||
assert_that(raw.value[0]["action"] is Dictionary).is_true()
|
||||
assert_that(raw.value[0]["action"].has("Interact")).is_true()
|
||||
var interact_data: Dictionary = raw.value[0]["action"]["Interact"]
|
||||
assert_that(interact_data.has("target_entity_id")).is_true()
|
||||
assert_that(interact_data.has("verb")).is_true()
|
||||
|
||||
func test_interact_with_data_encodes_as_data_variant() -> void:
|
||||
# Future: once server accepts Interact(InteractData)
|
||||
var inputs: Array = [{
|
||||
"tick": 100,
|
||||
"action_name": "Interact",
|
||||
|
||||
@@ -142,7 +142,9 @@ func test_framed_protocol_batch_input_roundtrip() -> void:
|
||||
assert_that(raw.value is Array).is_true()
|
||||
assert_that(raw.value.size()).is_equal(2)
|
||||
assert_that(raw.value[0]["action"]).is_equal("MoveNorth")
|
||||
assert_that(raw.value[1]["action"]).is_equal("Interact")
|
||||
# Interact is a struct variant: {"Interact": {"target_entity_id": null, "verb": null}}
|
||||
assert_that(raw.value[1]["action"] is Dictionary).is_true()
|
||||
assert_that(raw.value[1]["action"].has("Interact")).is_true()
|
||||
|
||||
|
||||
# -- Diagonal movement wire mapping --------------------------------------------
|
||||
|
||||
@@ -244,7 +244,9 @@ func test_encode_player_inputs_multiple() -> void:
|
||||
assert_that(raw.status).is_null()
|
||||
assert_that(raw.value.size()).is_equal(3)
|
||||
assert_that(raw.value[0]["action"]).is_equal("MoveNorth")
|
||||
assert_that(raw.value[1]["action"]).is_equal("Interact")
|
||||
# Interact is a struct variant: {"Interact": {"target_entity_id": null, "verb": null}}
|
||||
assert_that(raw.value[1]["action"] is Dictionary).is_true()
|
||||
assert_that(raw.value[1]["action"].has("Interact")).is_true()
|
||||
assert_that(raw.value[2]["action"]).is_equal("MoveSouthwest")
|
||||
|
||||
|
||||
@@ -358,7 +360,9 @@ func test_decode_batch_input_fixture() -> void:
|
||||
assert_that(raw.value[0]["tick"]).is_equal(0)
|
||||
assert_that(raw.value[0]["action"]).is_equal("MoveNorth")
|
||||
assert_that(raw.value[1]["tick"]).is_equal(0)
|
||||
assert_that(raw.value[1]["action"]).is_equal("Interact")
|
||||
# Interact is a struct variant: {"Interact": {"target_entity_id": null, "verb": null}}
|
||||
assert_that(raw.value[1]["action"] is Dictionary).is_true()
|
||||
assert_that(raw.value[1]["action"].has("Interact")).is_true()
|
||||
|
||||
|
||||
# -- Diagonal movement fixtures (D-030 Layer 1 cross-language) -----------------
|
||||
|
||||
@@ -26,17 +26,17 @@ func _load_fixture(name: String) -> PackedByteArray:
|
||||
|
||||
# -- Protocol version upgrade -------------------------------------------------
|
||||
|
||||
func test_protocol_version_is_7() -> void:
|
||||
assert_that(Protocol.PROTOCOL_VERSION).is_equal(7)
|
||||
func test_protocol_version_is_8() -> void:
|
||||
assert_that(Protocol.PROTOCOL_VERSION).is_equal(8)
|
||||
|
||||
|
||||
func test_fixtures_at_protocol_version_7() -> void:
|
||||
# All regenerated fixtures should be at v7
|
||||
func test_fixtures_at_protocol_version_8() -> void:
|
||||
# All regenerated fixtures should be at v8
|
||||
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(7)
|
||||
assert_that(snapshot.version).is_equal(8)
|
||||
|
||||
|
||||
func test_rejects_version_6() -> void:
|
||||
@@ -282,10 +282,10 @@ func test_sim_bridge_test_snapshot_has_player_inventory() -> void:
|
||||
assert_that(snap.player_inventory is Array).is_true()
|
||||
|
||||
|
||||
func test_sim_bridge_test_snapshot_version_7() -> void:
|
||||
func test_sim_bridge_test_snapshot_version_8() -> void:
|
||||
SimBridge.reset_test_state()
|
||||
var snap = SimBridge._test_snapshot()
|
||||
assert_that(snap.version).is_equal(7)
|
||||
assert_that(snap.version).is_equal(8)
|
||||
|
||||
|
||||
# -- Fixture: v6 snapshots include new fields ----------------------------------
|
||||
|
||||
Reference in New Issue
Block a user