fix: makes the loading process more consistent by using all ESC commands; also fixes issue caused by loaded save games not executing :setup or :ready, thereby preventing proper room switching in this case

This commit is contained in:
Duncan Brown
2022-03-21 22:30:16 -04:00
committed by Julian Murgia
parent ecb7bfb528
commit 84c84d3a0f
3 changed files with 38 additions and 22 deletions

View File

@@ -270,14 +270,16 @@ func init_room(room: ESCRoom) -> void:
#
# - room: The ESCRoom to be initialized for use.
func _perform_script_events(room: ESCRoom):
if escoria.event_manager.is_channel_free(escoria.event_manager.CHANNEL_FRONT) \
or (
not escoria.event_manager.is_channel_free(escoria.event_manager.CHANNEL_FRONT) \
and not escoria.event_manager.get_running_event(
# If we're loading from a saved game, we don't want to run :setup or :ready
# as it could potentially alter the loaded save state; however, we still need
# to swap the scene in since it would ordinarily happen between :setup and
# :ready. Fun, huh?
if not escoria.event_manager.is_channel_free(escoria.event_manager.CHANNEL_FRONT) \
and escoria.event_manager.get_running_event(
escoria.event_manager.CHANNEL_FRONT
).name == escoria.event_manager.EVENT_LOAD
):
).name == escoria.event_manager.EVENT_LOAD:
_make_new_room_visible(room)
else:
# If the room was loaded from change_scene and automatic transitions
# are not disabled, do the transition out now
if room.enabled_automatic_transitions \
@@ -326,13 +328,7 @@ func _perform_script_events(room: ESCRoom):
# Switch the rooms (resources are freed at end of change_scene and in
# clear_scene).
if room != escoria.main.current_scene:
escoria.main.current_scene.visible = false
#escoria.main.current_scene.z_index = -100
room.visible = true
#room.z_index = 0
_make_new_room_visible(room)
if room.enabled_automatic_transitions \
or (
@@ -393,6 +389,20 @@ func _perform_script_events(room: ESCRoom):
)
# Switches the visibility of the "old" room and the "new" room.
#
# #### Parameters
#
# - room: The ESCRoom to be made visible in place of the current one.
func _make_new_room_visible(room: ESCRoom) -> void:
if is_instance_valid(escoria.main.current_scene) and room != escoria.main.current_scene:
escoria.main.current_scene.visible = false
#escoria.main.current_scene.z_index = -100
room.visible = true
#room.z_index = 0
# Runs the script event from the script attached, if any.
#
# #### Parameters

View File

@@ -32,6 +32,7 @@ var _set_active: SetActiveCommand
var _set_interactive: SetInteractiveCommand
var _teleport_pos: TeleportPosCommand
var _set_angle: SetAngleCommand
var _set_global: SetGlobalCommand
var _set_state: SetStateCommand
var _stop_snd: StopSndCommand
var _play_snd: PlaySndCommand
@@ -51,6 +52,7 @@ func _init():
_set_interactive = SetInteractiveCommand.new()
_teleport_pos = TeleportPosCommand.new()
_set_angle = SetAngleCommand.new()
_set_global = SetGlobalCommand.new()
_set_state = SetStateCommand.new()
_stop_snd = StopSndCommand.new()
_play_snd = PlaySndCommand.new()
@@ -279,14 +281,6 @@ func load_game(id: int):
ESCCommand.new("%s pause" % _hide_menu.get_command_name())
)
## GLOBALS
for k in save_game.globals.keys():
escoria.globals_manager.set_global(
k,
save_game.globals[k],
true
)
## ROOM
load_statements.append(
ESCCommand.new("%s %s false" %
@@ -297,6 +291,16 @@ func load_game(id: int):
)
)
## GLOBALS
for k in save_game.globals.keys():
ESCCommand.new("%s %s %s" %
[
_set_global.get_command_name(),
k,
save_game.globals[k]
]
)
## OBJECTS
for object_global_id in save_game.objects.keys():
if escoria.object_manager.has(object_global_id) and \

View File

@@ -54,6 +54,7 @@ func add_new_item_by_id(item_id: String) -> void:
item_id,
ResourceLoader.load(inventory_file).instance()
),
null,
true
)
else:
@@ -79,6 +80,7 @@ func add_new_item_by_id(item_id: String) -> void:
item_id,
inventory_item_button
),
null,
true
)