Ensure player is set at start location if there is one (#435)

This is done even if there is no ESC script attached to the room.
First default position will then be the start ESCLocation if there is one.
Else, fallback to origin (0,0).
This commit is contained in:
Julian Murgia authored and GitHub committed 2021-11-12 22:57:44 +01:00
1 parent e9fc3a030e
commit bbe885edc2
9 files changed
+192 -19

No files matched your search

@@ -124,7 +124,9 @@ func save_game(p_savegame: ESCSaveGame) -> void:
func get_start_location() -> ESCLocation:
for object in objects.values():
if object.node is ESCLocation and object.node.is_start_location:
if is_instance_valid(object.node) \
and object.node is ESCLocation \
and object.node.is_start_location:
return object
escoria.logger.report_warnings(
"esc_object_manager.gd:get_start_location()",
@@ -82,9 +82,6 @@ func _ready():
add_child(game)
move_child(game, 0)
if escoria.main.current_scene == null:
escoria.main.set_scene(self)
if player_scene:
player = player_scene.instance()
add_child(player)
@@ -113,22 +110,21 @@ func _ready():
else:
is_run_directly = true
# Manage player location at room start
if player != null \
and escoria.object_manager.get_start_location() != null:
player.teleport(escoria.object_manager.get_start_location().node)
perform_script_events()
# Performs the ESC script events "setup" and "ready", in this order, if they are
# present. Also manages automatic transitions.
func perform_script_events():
if esc_script and escoria.event_manager._running_event == null \
or (escoria.event_manager._running_event != null \
and escoria.event_manager._running_event.name != "load"):
# Manage player location at room start
if (escoria.globals_manager.get_global("ESC_LAST_SCENE") == null \
or escoria.globals_manager \
.get_global("ESC_LAST_SCENE").empty()) \
and player != null \
and escoria.object_manager.get_start_location() != null:
player.teleport(escoria.object_manager.get_start_location().node)
# If the room was loaded from change_scene and automatic transitions
# are not disabled, do the transition out now
if enabled_automatic_transitions \
@@ -145,7 +141,6 @@ func perform_script_events():
script_transition_out.events['transition_out']
)
# Run the setup event
_run_script_event("setup")
@@ -194,6 +189,7 @@ func perform_script_events():
true
)
# Runs the script event from the script attached, if any.
#
# #### Parameters
+5 -4
View File
@@ -40,10 +40,11 @@ func set_scene(p_scene: Node) -> void:
if current_scene != null:
clear_scene()
if not p_scene.is_inside_tree() or not p_scene in get_children():
add_child(p_scene)
elif p_scene in get_children():
move_child(p_scene, 0)
if p_scene.is_inside_tree() and not p_scene.get_parent() != self:
p_scene.get_parent().remove_child(p_scene)
add_child(p_scene)
move_child(p_scene, 0)
current_scene = p_scene
check_game_scene_methods()