refactor: unify interactable components
This commit is contained in:
@@ -1,8 +1,6 @@
|
||||
class_name ScenePortal
|
||||
extends Area2D
|
||||
|
||||
const InteractionAnchorUtil = preload("res://_Core/utils/InteractionAnchor.gd")
|
||||
|
||||
# ============================================================================
|
||||
# ScenePortal.gd - 场景入口传送组件
|
||||
# ============================================================================
|
||||
@@ -16,27 +14,20 @@ const InteractionAnchorUtil = preload("res://_Core/utils/InteractionAnchor.gd")
|
||||
@export var interactionDistance: float = 160.0
|
||||
|
||||
func _ready() -> void:
|
||||
add_to_group("whaletown_interactable")
|
||||
var label: String = interactionTitle.strip_edges()
|
||||
if label.is_empty():
|
||||
label = "进入 %s" % targetSceneName
|
||||
var interactable: InteractableComponent = InteractableComponent.new()
|
||||
interactable.interaction_id = "portal:%s" % str(get_path())
|
||||
interactable.interaction_title = label
|
||||
interactable.interaction_priority = 20
|
||||
interactable.interaction_distance = interactionDistance
|
||||
interactable.activation_method = &"_change_scene"
|
||||
add_child(interactable)
|
||||
|
||||
func _on_body_entered(body: Node2D) -> void:
|
||||
return
|
||||
|
||||
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 []
|
||||
var label := interactionTitle.strip_edges()
|
||||
if label.is_empty():
|
||||
label = "进入 %s" % targetSceneName
|
||||
return [{
|
||||
"id": "portal:%s" % get_instance_id(),
|
||||
"title": label,
|
||||
"distance": distance,
|
||||
"priority": 20,
|
||||
"callback": Callable(self, "_change_scene"),
|
||||
}]
|
||||
|
||||
func _change_scene() -> void:
|
||||
if targetSceneName.is_empty():
|
||||
push_warning("ScenePortal: targetSceneName is empty.")
|
||||
|
||||
Reference in New Issue
Block a user