diff --git a/client/scripts/rendering/entity_renderer.gd b/client/scripts/rendering/entity_renderer.gd index 21e40b559..97d288461 100644 --- a/client/scripts/rendering/entity_renderer.gd +++ b/client/scripts/rendering/entity_renderer.gd @@ -1,11 +1,14 @@ extends Node2D # Entity renderer — manages entity sprites under the Entities node -# Creates/updates/removes Sprite2D children based on entity data +# Creates/updates/removes ColorRect children based on entity data +# Entity format (from Protocol): {entity_id, x, y, z, kind: {variant, data}} const TILE_SIZE: int = 32 +const ENTITY_SIZE: int = 24 +const ENTITY_OFFSET: float = (TILE_SIZE - ENTITY_SIZE) / 2.0 # center within tile -var entity_nodes: Dictionary = {} # id -> Node2D mapping +var entity_nodes: Dictionary = {} # entity_id -> Node2D mapping func _ready() -> void: print("EntityRenderer: Initialized") @@ -16,10 +19,10 @@ func update_entities(entities: Array) -> void: # Create or update entities for entity_data in entities: - if not entity_data.has("id"): + if not entity_data.has("entity_id"): continue - var entity_id = entity_data.id + var entity_id = entity_data.entity_id active_ids.append(entity_id) # Create entity node if it doesn't exist @@ -41,14 +44,18 @@ func update_entities(entities: Array) -> void: func _create_entity_node(entity_id: int, entity_data: Dictionary) -> void: var entity_node = ColorRect.new() entity_node.name = "Entity_" + str(entity_id) - entity_node.size = Vector2(32, 32) - entity_node.pivot_offset = Vector2(16, 16) + entity_node.size = Vector2(ENTITY_SIZE, ENTITY_SIZE) + entity_node.pivot_offset = Vector2(ENTITY_SIZE / 2.0, ENTITY_SIZE / 2.0) - # Color based on type - if entity_data.get("type") == "npc": - entity_node.color = Color(0.3, 0.6, 0.9) # Blue for NPCs - else: - entity_node.color = Color(0.8, 0.8, 0.8) # Gray for unknown + # Color based on entity kind (from Protocol decoded format) + var kind_variant: String = entity_data.get("kind", {}).get("variant", "") + match kind_variant: + "Npc": + entity_node.color = Color(0.3, 0.6, 0.9) # Blue for NPCs + "Player": + entity_node.color = Color(0.88, 0.91, 1.0) # Light blue for player + _: + entity_node.color = Color(0.8, 0.8, 0.8) # Gray for unknown add_child(entity_node) entity_nodes[entity_id] = entity_node @@ -62,13 +69,12 @@ func _update_entity_node(entity_id: int, entity_data: Dictionary) -> void: var entity_node = entity_nodes[entity_id] - # Update position - if entity_data.has("position"): - var pos = entity_data.position - if pos is Array and pos.size() >= 2: - entity_node.position = Vector2(pos[0] * TILE_SIZE, pos[1] * TILE_SIZE) - else: - push_warning("EntityRenderer: malformed position for entity %s" % entity_id) + # Update position from x, y fields (Protocol format), centered within tile + if entity_data.has("x") and entity_data.has("y"): + entity_node.position = Vector2( + entity_data.x * TILE_SIZE + ENTITY_OFFSET, + entity_data.y * TILE_SIZE + ENTITY_OFFSET + ) # Remove an entity node func _remove_entity_node(entity_id: int) -> void: