51 lines
1.4 KiB
GDScript
51 lines
1.4 KiB
GDScript
class_name MapChangeInteract extends Node3D
|
|
|
|
|
|
@export var mapResource:PackedScene
|
|
@export var destinationPointNodeName:String
|
|
var interactableArea:InteractableArea
|
|
var shapeChild:CollisionShape3D
|
|
|
|
func _enter_tree() -> void:
|
|
interactableArea = $InteractableArea
|
|
|
|
if !mapResource:
|
|
push_error("MapChangeInteract must have a mapResource set.")
|
|
return
|
|
|
|
# Needs to be exactly one child.
|
|
if get_child_count() != 2:
|
|
push_error("MapChangeInteract must have exactly one child InteractableArea node.")
|
|
return
|
|
|
|
var child = get_child(1)
|
|
if not (child is CollisionShape3D):
|
|
push_error("MapChangeInteract's child must be an CollisionShape3D node.")
|
|
|
|
shapeChild = child
|
|
remove_child(shapeChild)
|
|
interactableArea.add_child(shapeChild)
|
|
|
|
interactableArea.interactEvent.connect(onInteract)
|
|
interactableArea.interactable.connect(onInteractable)
|
|
interactableArea.notInteractable.connect(onNotInteractable)
|
|
|
|
func _exit_tree() -> void:
|
|
interactableArea.interactEvent.disconnect(onInteract)
|
|
interactableArea.interactable.disconnect(onInteractable)
|
|
interactableArea.notInteractable.disconnect(onNotInteractable)
|
|
|
|
interactableArea.remove_child(shapeChild)
|
|
add_child(shapeChild)
|
|
|
|
func onInteract(_ent:Player) -> void:
|
|
OVERWORLD.mapChange(mapResource, destinationPointNodeName)
|
|
|
|
func onInteractable(_ent:Player) -> void:
|
|
print("Able to leave map")
|
|
pass
|
|
|
|
func onNotInteractable(_ent:Player) -> void:
|
|
print("Not able to leave map")
|
|
pass
|