diff --git a/addons/escoria-core/game/core-scripts/esc/esc_room_manager.gd b/addons/escoria-core/game/core-scripts/esc/esc_room_manager.gd index c8a7af44..d51da3f8 100644 --- a/addons/escoria-core/game/core-scripts/esc/esc_room_manager.gd +++ b/addons/escoria-core/game/core-scripts/esc/esc_room_manager.gd @@ -269,6 +269,10 @@ func init_room(room: ESCRoom) -> void: # # - room: The ESCRoom to be initialized for use. func _perform_script_events(room: ESCRoom) -> void: + # Used to track whether any yields have been executed before the call to + # set_scene_finish. + var yielded: bool = false + if room.enabled_automatic_transitions \ and not room.is_run_directly \ and not room.exited_previous_room: @@ -296,6 +300,8 @@ func _perform_script_events(room: ESCRoom) -> void: rc = yield(escoria.event_manager, "event_finished") if rc[0] != ESCExecution.RC_OK: return rc[0] + + yielded = true # Hide main and pause menus escoria.game_scene.hide_main_menu() @@ -313,6 +319,11 @@ func _perform_script_events(room: ESCRoom) -> void: if rc[0] != ESCExecution.RC_OK: return rc[0] + yielded = true + + if not yielded: + escoria.main.finish_current_scene_init(room) + escoria.main.set_scene_finish() # We know the scene has been loaded. Make its global ID available for @@ -360,7 +371,7 @@ func _perform_script_events(room: ESCRoom) -> void: rc = yield(escoria.event_manager, "event_finished") if rc[0] != ESCExecution.RC_OK: return rc[0] - + # Now that :ready is finished, if FORCE_LAST_SCENE_NULL was true, reset it # to false if escoria.globals_manager.get_global( \ diff --git a/addons/escoria-core/game/main.gd b/addons/escoria-core/game/main.gd index cdf3c6d8..7018ba08 100644 --- a/addons/escoria-core/game/main.gd +++ b/addons/escoria-core/game/main.gd @@ -54,12 +54,30 @@ func set_scene(p_scene: Node) -> void: escoria.object_manager.set_current_room(p_scene) add_child(p_scene) + # In cases where the room being created doesn't return because of a + # coroutine, finish_current_scene_init() will already have been called + # and so we don't want to risk repeating ourselves. + if p_scene == current_scene: + return + # This actually moves the scene closest to the root node, but will # still be drawn behind the next node, which should be the previous # room. move_child(p_scene, 0) current_scene = p_scene + + check_game_scene_methods() + + set_camera_limits() + + +# Only called by the room manager in the case where it hasn't executed a +# coroutine prior to calling set_scene_finish(). +func finish_current_scene_init(p_scene: Node) -> void: + move_child(p_scene, 0) + + current_scene = p_scene check_game_scene_methods() diff --git a/addons/escoria-core/game/scenes/camera_player/esc_camera.gd b/addons/escoria-core/game/scenes/camera_player/esc_camera.gd index b1bcdb87..d13cd70e 100644 --- a/addons/escoria-core/game/scenes/camera_player/esc_camera.gd +++ b/addons/escoria-core/game/scenes/camera_player/esc_camera.gd @@ -26,6 +26,7 @@ func _ready(): escoria.object_manager.CAMERA, self ), + null, true )