class_name WorkZoneBuildingArea extends Area2D # ============================================================================ # WorkZoneBuildingArea.gd - 打工区建筑交互入口 # ============================================================================ # 为打工区建筑提供统一交互数据,玩家面对入口按交互键时由 PlayerController 调用。 # ============================================================================ const INTERACTION_COLLISION_LAYER: int = 2 @export var buildingId: String = "" @export var buildingTitle: String = "" @export var buildingRole: String = "" @export var interactionDistance: float = 150.0 func _ready() -> void: collision_layer = INTERACTION_COLLISION_LAYER collision_mask = 0 var interactable: InteractableComponent = InteractableComponent.new() interactable.interaction_distance = interactionDistance add_child(interactable) func is_interaction_active(_component: InteractableComponent) -> bool: return not buildingId.strip_edges().is_empty() func build_interaction_actions(_component: InteractableComponent, _player: Node2D) -> Array[InteractionAction]: var actions: Array[InteractionAction] = [] var title: String = buildingTitle if not buildingTitle.is_empty() else "设施" actions.append(InteractionAction.create("building:%s" % buildingId, "使用 %s" % title, 30, Callable(self, "interact"))) return actions func interact() -> void: var payload := { "buildingId": buildingId, "title": buildingTitle, "role": buildingRole, "nodePath": get_path(), } var eventSystem := get_node_or_null("/root/EventSystem") if eventSystem != null: eventSystem.call("emit_event", EventNames.OBJECT_INTERACTED, payload) print("WorkZone building interacted: %s - %s" % [buildingTitle, buildingRole])