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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user