Skip to content

Commit

Permalink
fix: makes the loading process more consistent by using all ESC comma…
Browse files Browse the repository at this point in the history
…nds; also fixes issue caused by loaded save games not executing :setup or :ready, thereby preventing proper room switching in this case
  • Loading branch information
BHSDuncan authored and StraToN committed Apr 8, 2022
1 parent ecb7bfb commit 84c84d3
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 22 deletions.
38 changes: 24 additions & 14 deletions addons/escoria-core/game/core-scripts/esc/esc_room_manager.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down Expand Up @@ -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 (
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand Down Expand Up @@ -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" %
Expand All @@ -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 \
Expand Down
2 changes: 2 additions & 0 deletions addons/escoria-core/game/scenes/inventory/inventory_ui.gd
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ func add_new_item_by_id(item_id: String) -> void:
item_id,
ResourceLoader.load(inventory_file).instance()
),
null,
true
)
else:
Expand All @@ -79,6 +80,7 @@ func add_new_item_by_id(item_id: String) -> void:
item_id,
inventory_item_button
),
null,
true
)

Expand Down

0 comments on commit 84c84d3

Please sign in to comment.