Made map loading work
This commit is contained in:
@@ -1,17 +1,18 @@
|
||||
class_name OverworldScene extends Node
|
||||
|
||||
@export var map:Node3D = null
|
||||
|
||||
func _enter_tree() -> void:
|
||||
OVERWORLD.mapChanged.connect(onMapChanged)
|
||||
|
||||
func _ready() -> void:
|
||||
onMapChanged(OVERWORLD.newMap, OVERWORLD.playerDestinationNodeName)
|
||||
pass
|
||||
|
||||
func _exit_tree() -> void:
|
||||
OVERWORLD.mapChanged.disconnect(onMapChanged)
|
||||
|
||||
func onMapChanged(newMap:PackedScene, playerDestinationNodeName:String) -> void:
|
||||
print("New map time.")
|
||||
var map = $Map
|
||||
print("New map time.", newMap)
|
||||
for childScene in map.get_children():
|
||||
map.remove_child(childScene)
|
||||
|
||||
@@ -22,12 +23,12 @@ func onMapChanged(newMap:PackedScene, playerDestinationNodeName:String) -> void:
|
||||
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
|
||||
if playerDestinationNodeName:
|
||||
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
|
||||
|
@@ -2,7 +2,8 @@
|
||||
|
||||
[ext_resource type="Script" uid="uid://dpvccegdmn7s6" path="res://meta/OverworldScene.gd" id="1_fa54r"]
|
||||
|
||||
[node name="OverworldScene" type="Node3D"]
|
||||
[node name="OverworldScene" type="Node3D" node_paths=PackedStringArray("map")]
|
||||
script = ExtResource("1_fa54r")
|
||||
map = NodePath("Map")
|
||||
|
||||
[node name="Map" type="Node3D" parent="."]
|
||||
|
@@ -30,4 +30,4 @@ func onSceneChange(newScene:SceneSingleton.SceneType) -> void:
|
||||
pass
|
||||
|
||||
_:
|
||||
pass
|
||||
pass
|
||||
|
@@ -10,8 +10,6 @@ overworld = NodePath("OverworldScene")
|
||||
initial = NodePath("InitialScene")
|
||||
metadata/_custom_type_script = "uid://ml70iui7qpo4"
|
||||
|
||||
[node name="InitialScene" parent="." instance=ExtResource("2_hkmoa")]
|
||||
visible = false
|
||||
|
||||
[node name="OverworldScene" parent="." instance=ExtResource("2_o1wvd")]
|
||||
visible = false
|
||||
|
||||
[node name="InitialScene" parent="." instance=ExtResource("2_hkmoa")]
|
||||
|
Reference in New Issue
Block a user