28 lines
844 B
GDScript
28 lines
844 B
GDScript
class_name OverworldScene extends Node
|
|
|
|
func _enter_tree() -> void:
|
|
OVERWORLD.mapChanged.connect(onMapChanged)
|
|
|
|
func _exit_tree() -> void:
|
|
OVERWORLD.mapChanged.disconnect(onMapChanged)
|
|
|
|
func onMapChanged(newMap:PackedScene, playerDestinationNodeName:String) -> void:
|
|
print("New map time.")
|
|
var map = $Map
|
|
for childScene in map.get_children():
|
|
map.remove_child(childScene)
|
|
|
|
var newMapInstance = newMap.instantiate()
|
|
map.add_child(newMapInstance)
|
|
|
|
# Find Player.
|
|
var player = newMapInstance.get_node("Player")
|
|
var destNode = newMapInstance.get_node(playerDestinationNodeName)
|
|
if player && player is Player && destNode:
|
|
player.global_position = destNode.global_position
|
|
player.global_rotation.y = destNode.global_rotation.y
|
|
elif playerDestinationNodeName:
|
|
push_error("Player, or destination node not found in new map.")
|
|
|
|
pass
|