feat(client): add interaction prompt system (#405)
Server-driven interaction prompt that displays "E - Talk" when near an interactable NPC. Decodes v4 nearby_interactions from snapshot, stores in GameState, renders via InteractionPrompt UI with fade animation. Extensible interface (get_interaction_target/get_selected_verb) for future radial verb menu (v0.2). - Protocol: decode nearby_interactions array with nested VerbOption structs, entity relationship/observation fields, tick_rate in GameTime - GameState: store/clear nearby_interactions per snapshot - SimBridge: test mode generates v4 format with structured verbs - InteractionPrompt: PanelContainer with fade in/out, polls GameState - Tests: 19 new test cases covering protocol, state, sim bridge, UI, encoding - Fixture assertions updated for v4 protocol version Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -70,6 +70,15 @@ static func decode_snapshot(bytes: PackedByteArray) -> Variant:
|
||||
tile_entry["visibility"] = vis
|
||||
visible_tiles.append(tile_entry)
|
||||
|
||||
# v4: nearby_interactions (#404/#405)
|
||||
var nearby_interactions: Array = []
|
||||
var raw_interactions: Variant = raw.get("nearby_interactions")
|
||||
if raw_interactions is Array:
|
||||
for raw_ni in raw_interactions:
|
||||
var ni = _decode_nearby_interaction(raw_ni)
|
||||
if ni != null:
|
||||
nearby_interactions.append(ni)
|
||||
|
||||
return {
|
||||
"tick": tick,
|
||||
"entities": entities,
|
||||
@@ -78,6 +87,7 @@ static func decode_snapshot(bytes: PackedByteArray) -> Variant:
|
||||
"game_time": game_time,
|
||||
"player_facing": player_facing,
|
||||
"visible_tiles": visible_tiles,
|
||||
"nearby_interactions": nearby_interactions,
|
||||
}
|
||||
|
||||
|
||||
@@ -96,6 +106,19 @@ static func _decode_entity(raw: Dictionary) -> Variant:
|
||||
if raw_vis is String:
|
||||
visibility = raw_vis
|
||||
|
||||
# v4: relationship (D-033) and observation state
|
||||
var relationship: String = "Unknown"
|
||||
var raw_rel: Variant = raw.get("relationship")
|
||||
if raw_rel is String:
|
||||
relationship = raw_rel
|
||||
|
||||
var observation: Variant = "Visible"
|
||||
var raw_obs: Variant = raw.get("observation")
|
||||
if raw_obs is String:
|
||||
observation = raw_obs
|
||||
elif raw_obs is Dictionary:
|
||||
observation = _decode_enum_variant(raw_obs)
|
||||
|
||||
return {
|
||||
"entity_id": entity_id,
|
||||
"x": float(raw["x"]),
|
||||
@@ -103,6 +126,54 @@ static func _decode_entity(raw: Dictionary) -> Variant:
|
||||
"z": int(raw["z"]),
|
||||
"kind": _decode_enum_variant(raw["kind"]),
|
||||
"visibility": visibility,
|
||||
"relationship": relationship,
|
||||
"observation": observation,
|
||||
}
|
||||
|
||||
|
||||
## Decode a NearbyInteraction from a raw msgpack map.
|
||||
## Returns {entity_id, entity_type, distance, verbs: [{kind, label, priority, available}]} or null.
|
||||
static func _decode_nearby_interaction(raw) -> Variant:
|
||||
if not raw is Dictionary:
|
||||
return null
|
||||
if not raw.has("entity_id") or not raw.has("verbs"):
|
||||
push_warning("Protocol: nearby_interaction missing required fields: %s" % str(raw.keys()))
|
||||
return null
|
||||
var verbs: Array[Dictionary] = []
|
||||
var raw_verbs: Variant = raw.get("verbs")
|
||||
if raw_verbs is Array:
|
||||
for rv in raw_verbs:
|
||||
var verb = _decode_verb_option(rv)
|
||||
if verb != null:
|
||||
verbs.append(verb)
|
||||
if verbs.is_empty():
|
||||
return null
|
||||
var entity_type: String = ""
|
||||
var raw_et: Variant = raw.get("entity_type")
|
||||
if raw_et is String:
|
||||
entity_type = raw_et
|
||||
return {
|
||||
"entity_id": int(raw["entity_id"]),
|
||||
"entity_type": entity_type,
|
||||
"distance": int(raw.get("distance", 0)),
|
||||
"verbs": verbs,
|
||||
}
|
||||
|
||||
|
||||
## Decode a VerbOption from a raw msgpack map.
|
||||
## Returns {kind, label, priority, available} or null.
|
||||
static func _decode_verb_option(raw) -> Variant:
|
||||
if not raw is Dictionary or not raw.has("label"):
|
||||
return null
|
||||
var kind: String = ""
|
||||
var raw_kind: Variant = raw.get("kind")
|
||||
if raw_kind is String:
|
||||
kind = raw_kind
|
||||
return {
|
||||
"kind": kind,
|
||||
"label": str(raw["label"]),
|
||||
"priority": int(raw.get("priority", 0)),
|
||||
"available": bool(raw.get("available", true)),
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user