extends Node # Updated each frame from ObserverSnapshot data (Protocol format: {tick, entities, tiles}). # Entities use Protocol decoded format: {entity_id, x, y, z, kind: {variant, data}}. # Tiles use format: [{x, y, z, type}]. var current_snapshot: Dictionary = {} var current_tick: int = 0 var player_position: Vector2 = Vector2.ZERO var visible_entities: Array = [] var visible_tiles: Array = [] var visible_positions: Dictionary = {} # Vector2i -> true, for fast fog lookups # Player entity ID — the first entity is assumed to be the player (will be # refined when the server assigns explicit player entity IDs). var player_entity_id: int = 1 func apply_snapshot(snapshot: Dictionary) -> void: current_snapshot = snapshot if snapshot.has("tick"): current_tick = snapshot.tick if snapshot.has("entities"): visible_entities = snapshot.entities # Derive player position from the player entity var found_player := false for entity in visible_entities: if entity.has("entity_id") and entity.entity_id == player_entity_id: player_position = Vector2(entity.x, entity.y) found_player = true break if not found_player and visible_entities.size() > 0: push_warning("GameState: player entity_id %d not found in %d entities" % [ player_entity_id, visible_entities.size()]) if snapshot.has("tiles"): visible_tiles = snapshot.tiles if snapshot.has("visible_positions"): visible_positions.clear() for pos in snapshot.visible_positions: visible_positions[Vector2i(pos.x, pos.y)] = true