forked from xiangwang25/whale-town-front-v2
refactor: unify interactable components
This commit is contained in:
@@ -8,7 +8,6 @@ extends Area2D
|
||||
# ============================================================================
|
||||
|
||||
const INTERACTION_COLLISION_LAYER: int = 2
|
||||
const InteractionAnchorUtil = preload("res://_Core/utils/InteractionAnchor.gd")
|
||||
|
||||
@export var buildingId: String = ""
|
||||
@export var buildingTitle: String = ""
|
||||
@@ -18,20 +17,18 @@ const InteractionAnchorUtil = preload("res://_Core/utils/InteractionAnchor.gd")
|
||||
func _ready() -> void:
|
||||
collision_layer = INTERACTION_COLLISION_LAYER
|
||||
collision_mask = 0
|
||||
add_to_group("whaletown_interactable")
|
||||
var interactable: InteractableComponent = InteractableComponent.new()
|
||||
interactable.interaction_distance = interactionDistance
|
||||
add_child(interactable)
|
||||
|
||||
func get_interaction_actions(player: Node2D) -> Array[Dictionary]:
|
||||
var anchor_position: Vector2 = InteractionAnchorUtil.get_position(self)
|
||||
var distance: float = anchor_position.distance_to(player.global_position)
|
||||
if distance > interactionDistance:
|
||||
return []
|
||||
return [{
|
||||
"id": "building:%s" % buildingId,
|
||||
"title": "使用 %s" % (buildingTitle if not buildingTitle.is_empty() else "设施"),
|
||||
"distance": distance,
|
||||
"priority": 30,
|
||||
"callback": Callable(self, "interact"),
|
||||
}]
|
||||
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 := {
|
||||
|
||||
Reference in New Issue
Block a user