fix: eliminates the need to run two batches of ESC commands for loading games by introducing an extra ESC command; also corrects situations where transitions that are mixed and matched don't work together; and additional cleanup
This commit is contained in:
committed by
Julian Murgia
parent
114ef2fc55
commit
503d6134dd
@@ -0,0 +1,43 @@
|
||||
# `set_active_if_exists object active`
|
||||
#
|
||||
# Changes the "active" state of the object in the current room.
|
||||
# Inactive objects are invisible in the room.
|
||||
#
|
||||
# **Parameters**
|
||||
#
|
||||
# - *object* Global ID of the object
|
||||
# - *active* Whether `object` should be active. `active` can be `true` or `false`.
|
||||
#
|
||||
# @ESC
|
||||
extends ESCBaseCommand
|
||||
class_name SetActiveIfExistsCommand
|
||||
|
||||
|
||||
# Return the descriptor of the arguments of this command
|
||||
func configure() -> ESCCommandArgumentDescriptor:
|
||||
return ESCCommandArgumentDescriptor.new(
|
||||
2,
|
||||
[TYPE_STRING, TYPE_BOOL],
|
||||
[null, null]
|
||||
)
|
||||
|
||||
|
||||
# Validate whether the given arguments match the command descriptor
|
||||
func validate(arguments: Array):
|
||||
if not escoria.object_manager.has(arguments[0]):
|
||||
escoria.logger.report_errors(
|
||||
"set_active: invalid object",
|
||||
[
|
||||
"Object with global id %s not found" % arguments[0]
|
||||
]
|
||||
)
|
||||
return false
|
||||
return .validate(arguments)
|
||||
|
||||
|
||||
# Run the command
|
||||
func run(command_params: Array) -> int:
|
||||
if escoria.object_manager.has(command_params[0]):
|
||||
escoria.object_manager.get_object(command_params[0]).active = \
|
||||
command_params[1]
|
||||
return ESCExecution.RC_OK
|
||||
@@ -56,6 +56,7 @@ func run(command_params: Array) -> int:
|
||||
|
||||
if transition_id == ESCTransitionPlayer.TRANSITION_ID_INSTANT:
|
||||
escoria.logger.debug("Performing instant transition.")
|
||||
escoria.main.scene_transition.reset_shader_cutoff()
|
||||
return ESCExecution.RC_OK
|
||||
|
||||
escoria.logger.debug("Starting transition #%s [%s, %s]"
|
||||
|
||||
@@ -268,140 +268,123 @@ func init_room(room: ESCRoom) -> void:
|
||||
# #### Parameters
|
||||
#
|
||||
# - room: The ESCRoom to be initialized for use.
|
||||
#
|
||||
# *Returns* ESCExecution.RC_OK when completed or the function's state in the
|
||||
# case a coroutine is yielding.
|
||||
func _perform_script_events(room: ESCRoom) -> int:
|
||||
# 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:
|
||||
escoria.main.set_scene_finish(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 \
|
||||
and not room.is_run_directly \
|
||||
and not room.exited_previous_room:
|
||||
var script_transition_out = escoria.esc_compiler.compile([
|
||||
"%s%s" % [ESCEvent.PREFIX, escoria.event_manager.EVENT_TRANSITION_OUT],
|
||||
"%s %s out" %
|
||||
[
|
||||
_transition.get_command_name(),
|
||||
escoria.project_settings_manager.get_setting(
|
||||
escoria.project_settings_manager.DEFAULT_TRANSITION
|
||||
)
|
||||
],
|
||||
"%s 0.1" % _wait.get_command_name()
|
||||
])
|
||||
escoria.event_manager.queue_event(
|
||||
script_transition_out.events[escoria.event_manager.EVENT_TRANSITION_OUT]
|
||||
)
|
||||
|
||||
# Unpause the game if it was
|
||||
escoria.set_game_paused(false)
|
||||
|
||||
# Wait for transition_out event to be done
|
||||
var rc = yield(escoria.event_manager, "event_finished")
|
||||
while rc[1] != escoria.event_manager.EVENT_TRANSITION_OUT:
|
||||
rc = yield(escoria.event_manager, "event_finished")
|
||||
if rc[0] != ESCExecution.RC_OK:
|
||||
return rc[0]
|
||||
|
||||
# Hide main and pause menus
|
||||
escoria.game_scene.hide_main_menu()
|
||||
escoria.game_scene.unpause_game()
|
||||
|
||||
var setup_event_added: bool = false
|
||||
# Run the setup event, if there is one.
|
||||
setup_event_added = _run_script_event(escoria.event_manager.EVENT_SETUP, room)
|
||||
|
||||
if setup_event_added:
|
||||
# Wait for setup event to be done
|
||||
var rc = yield(escoria.event_manager, "event_finished")
|
||||
while rc[1] != escoria.event_manager.EVENT_SETUP:
|
||||
rc = yield(escoria.event_manager, "event_finished")
|
||||
if rc[0] != ESCExecution.RC_OK:
|
||||
return rc[0]
|
||||
|
||||
escoria.main.set_scene_finish()
|
||||
|
||||
# We know the scene has been loaded. Make its global ID available for
|
||||
# use by ESC script.
|
||||
escoria.globals_manager.set_global(
|
||||
escoria.room_manager.GLOBAL_CURRENT_SCENE,
|
||||
room.global_id,
|
||||
true
|
||||
func _perform_script_events(room: ESCRoom) -> void:
|
||||
if room.enabled_automatic_transitions \
|
||||
and not room.is_run_directly \
|
||||
and not room.exited_previous_room:
|
||||
var script_transition_out = escoria.esc_compiler.compile([
|
||||
"%s%s" % [ESCEvent.PREFIX, escoria.event_manager.EVENT_TRANSITION_OUT],
|
||||
"%s %s out" %
|
||||
[
|
||||
_transition.get_command_name(),
|
||||
escoria.project_settings_manager.get_setting(
|
||||
escoria.project_settings_manager.DEFAULT_TRANSITION
|
||||
)
|
||||
],
|
||||
"%s 0.1" % _wait.get_command_name()
|
||||
])
|
||||
escoria.event_manager.queue_event(
|
||||
script_transition_out.events[escoria.event_manager.EVENT_TRANSITION_OUT]
|
||||
)
|
||||
|
||||
# Clear queued resources
|
||||
escoria.resource_cache.clear()
|
||||
# Unpause the game if it was
|
||||
escoria.set_game_paused(false)
|
||||
|
||||
escoria.inputs_manager.hotspot_focused = ""
|
||||
# Wait for transition_out event to be done
|
||||
var rc = yield(escoria.event_manager, "event_finished")
|
||||
while rc[1] != escoria.event_manager.EVENT_TRANSITION_OUT:
|
||||
rc = yield(escoria.event_manager, "event_finished")
|
||||
if rc[0] != ESCExecution.RC_OK:
|
||||
return rc[0]
|
||||
|
||||
if room.enabled_automatic_transitions \
|
||||
or (
|
||||
not room.enabled_automatic_transitions \
|
||||
and escoria.globals_manager.get_global( \
|
||||
escoria.room_manager.GLOBAL_FORCE_LAST_SCENE_NULL)
|
||||
):
|
||||
var script_transition_in = escoria.esc_compiler.compile([
|
||||
"%s%s" % [ESCEvent.PREFIX, escoria.event_manager.EVENT_TRANSITION_IN],
|
||||
"%s %s in" %
|
||||
[
|
||||
_transition.get_command_name(),
|
||||
escoria.project_settings_manager.get_setting(
|
||||
escoria.project_settings_manager.DEFAULT_TRANSITION
|
||||
)
|
||||
],
|
||||
"%s 0.1" % _wait.get_command_name()
|
||||
])
|
||||
escoria.event_manager.queue_event(
|
||||
script_transition_in.events[escoria.event_manager.EVENT_TRANSITION_IN]
|
||||
)
|
||||
# Hide main and pause menus
|
||||
escoria.game_scene.hide_main_menu()
|
||||
escoria.game_scene.unpause_game()
|
||||
|
||||
var setup_event_added: bool = false
|
||||
# Run the setup event, if there is one.
|
||||
setup_event_added = _run_script_event(escoria.event_manager.EVENT_SETUP, room)
|
||||
|
||||
if setup_event_added:
|
||||
# Wait for setup event to be done
|
||||
var rc = yield(escoria.event_manager, "event_finished")
|
||||
while rc[1] != escoria.event_manager.EVENT_SETUP:
|
||||
rc = yield(escoria.event_manager, "event_finished")
|
||||
if rc[0] != ESCExecution.RC_OK:
|
||||
return rc[0]
|
||||
|
||||
var ready_event_added: bool = false
|
||||
# Run the ready event, if there is one.
|
||||
ready_event_added = _run_script_event(escoria.event_manager.EVENT_READY, room)
|
||||
escoria.main.set_scene_finish()
|
||||
|
||||
if ready_event_added:
|
||||
# Wait for ready event to be done
|
||||
var rc = yield(escoria.event_manager, "event_finished")
|
||||
while rc[1] != escoria.event_manager.EVENT_READY:
|
||||
rc = yield(escoria.event_manager, "event_finished")
|
||||
if rc[0] != ESCExecution.RC_OK:
|
||||
return rc[0]
|
||||
# We know the scene has been loaded. Make its global ID available for
|
||||
# use by ESC script.
|
||||
escoria.globals_manager.set_global(
|
||||
escoria.room_manager.GLOBAL_CURRENT_SCENE,
|
||||
room.global_id,
|
||||
true
|
||||
)
|
||||
|
||||
# Now that :ready is finished, if FORCE_LAST_SCENE_NULL was true, reset it
|
||||
# to false
|
||||
if escoria.globals_manager.get_global( \
|
||||
escoria.room_manager.GLOBAL_FORCE_LAST_SCENE_NULL):
|
||||
# Clear queued resources
|
||||
escoria.resource_cache.clear()
|
||||
|
||||
escoria.globals_manager.set_global(
|
||||
escoria.room_manager.GLOBAL_FORCE_LAST_SCENE_NULL,
|
||||
false,
|
||||
true
|
||||
)
|
||||
escoria.globals_manager.set_global(
|
||||
escoria.room_manager.GLOBAL_LAST_SCENE,
|
||||
escoria.main.current_scene.global_id \
|
||||
if escoria.main.current_scene != null else "",
|
||||
true
|
||||
)
|
||||
escoria.inputs_manager.hotspot_focused = ""
|
||||
|
||||
if room.enabled_automatic_transitions \
|
||||
or (
|
||||
not room.enabled_automatic_transitions \
|
||||
and escoria.globals_manager.get_global( \
|
||||
escoria.room_manager.GLOBAL_FORCE_LAST_SCENE_NULL)
|
||||
):
|
||||
var script_transition_in = escoria.esc_compiler.compile([
|
||||
"%s%s" % [ESCEvent.PREFIX, escoria.event_manager.EVENT_TRANSITION_IN],
|
||||
"%s %s in" %
|
||||
[
|
||||
_transition.get_command_name(),
|
||||
escoria.project_settings_manager.get_setting(
|
||||
escoria.project_settings_manager.DEFAULT_TRANSITION
|
||||
)
|
||||
],
|
||||
"%s 0.1" % _wait.get_command_name()
|
||||
])
|
||||
escoria.event_manager.queue_event(
|
||||
script_transition_in.events[escoria.event_manager.EVENT_TRANSITION_IN]
|
||||
)
|
||||
|
||||
var ready_event_added: bool = false
|
||||
# Run the ready event, if there is one.
|
||||
ready_event_added = _run_script_event(escoria.event_manager.EVENT_READY, room)
|
||||
|
||||
if ready_event_added:
|
||||
# Wait for ready event to be done
|
||||
var rc = yield(escoria.event_manager, "event_finished")
|
||||
while rc[1] != escoria.event_manager.EVENT_READY:
|
||||
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( \
|
||||
escoria.room_manager.GLOBAL_FORCE_LAST_SCENE_NULL):
|
||||
|
||||
# Make the room's global ID available for use in ESC script.
|
||||
escoria.globals_manager.set_global(
|
||||
escoria.room_manager.GLOBAL_CURRENT_SCENE,
|
||||
escoria.room_manager.GLOBAL_FORCE_LAST_SCENE_NULL,
|
||||
false,
|
||||
true
|
||||
)
|
||||
escoria.globals_manager.set_global(
|
||||
escoria.room_manager.GLOBAL_LAST_SCENE,
|
||||
escoria.main.current_scene.global_id \
|
||||
if escoria.main.current_scene != null else "",
|
||||
true
|
||||
)
|
||||
|
||||
return ESCExecution.RC_OK
|
||||
|
||||
# Make the room's global ID available for use in ESC script.
|
||||
escoria.globals_manager.set_global(
|
||||
escoria.room_manager.GLOBAL_CURRENT_SCENE,
|
||||
escoria.main.current_scene.global_id \
|
||||
if escoria.main.current_scene != null else "",
|
||||
true
|
||||
)
|
||||
|
||||
|
||||
# Runs the script event from the script attached, if any.
|
||||
|
||||
@@ -57,6 +57,9 @@ signal mouse_right_clicked_item(global_id)
|
||||
signal arrived(walk_context)
|
||||
|
||||
|
||||
const GROUP_ITEM_CAN_COLLIDE = "item_can_collide"
|
||||
|
||||
|
||||
# The global ID of this item
|
||||
export(String) var global_id
|
||||
|
||||
@@ -170,6 +173,10 @@ func _ready():
|
||||
self.pause_mode = Node.PAUSE_MODE_STOP
|
||||
|
||||
_detect_children()
|
||||
|
||||
# We add ourselves to this group so we can easily get a reference to all
|
||||
# items in a scene tree.
|
||||
add_to_group(GROUP_ITEM_CAN_COLLIDE)
|
||||
|
||||
if not self.is_connected("mouse_entered", self, "_on_mouse_entered"):
|
||||
connect("mouse_entered", self, "_on_mouse_entered")
|
||||
|
||||
@@ -29,6 +29,7 @@ var _transition: TransitionCommand
|
||||
var _hide_menu: HideMenuCommand
|
||||
var _change_scene: ChangeSceneCommand
|
||||
var _set_active: SetActiveCommand
|
||||
var _set_active_if_exists: SetActiveIfExistsCommand
|
||||
var _set_interactive: SetInteractiveCommand
|
||||
var _teleport_pos: TeleportPosCommand
|
||||
var _set_angle: SetAngleCommand
|
||||
@@ -49,6 +50,7 @@ func _init():
|
||||
_hide_menu = HideMenuCommand.new()
|
||||
_change_scene = ChangeSceneCommand.new()
|
||||
_set_active = SetActiveCommand.new()
|
||||
_set_active_if_exists = SetActiveIfExistsCommand.new()
|
||||
_set_interactive = SetInteractiveCommand.new()
|
||||
_teleport_pos = TeleportPosCommand.new()
|
||||
_set_angle = SetAngleCommand.new()
|
||||
@@ -291,20 +293,6 @@ func load_game(id: int):
|
||||
)
|
||||
)
|
||||
|
||||
load_event.statements = load_statements
|
||||
|
||||
escoria.set_game_paused(false)
|
||||
escoria.event_manager.queue_event(load_event)
|
||||
|
||||
# Wait for the scene to be loaded so we have access to objects, etc.
|
||||
var rc = yield(escoria.event_manager, "event_finished")
|
||||
while rc[1] != escoria.event_manager.EVENT_LOAD:
|
||||
rc = yield(escoria.event_manager, "event_finished")
|
||||
|
||||
# We then carry on with other "load"-related commands.
|
||||
escoria.set_game_paused(true)
|
||||
load_statements = []
|
||||
|
||||
## GLOBALS
|
||||
for k in save_game.globals.keys():
|
||||
var global_value = save_game.globals[k]
|
||||
@@ -324,11 +312,10 @@ func load_game(id: int):
|
||||
|
||||
## OBJECTS
|
||||
for object_global_id in save_game.objects.keys():
|
||||
if escoria.object_manager.has(object_global_id) and \
|
||||
save_game.objects[object_global_id].has("active"):
|
||||
if save_game.objects[object_global_id].has("active"):
|
||||
load_statements.append(ESCCommand.new("%s %s %s" \
|
||||
% [
|
||||
_set_active.get_command_name(),
|
||||
_set_active_if_exists.get_command_name(),
|
||||
object_global_id,
|
||||
save_game.objects[object_global_id]["active"]
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user