Fix auto transition when changing room without exit_scene event (#462)

Added a new fourth button in room14 to demonstrate this.
Renamed BYPASS_LAST_SCENE to FORCE_LAST_SCENE_NULL to make it a bit clearer.
Made events "finished" and "interrupted" signals connections as ONESHOT (so they are disconnected once the signal was received).

Also removed some unused files, many others remain.
And fixed some bugs here and there.
This commit is contained in:
Julian Murgia
2021-11-25 15:24:33 +01:00
committed by GitHub
parent d867407d01
commit a49e5a2690
19 changed files with 154 additions and 119 deletions

View File

@@ -60,31 +60,49 @@ func run(command_params: Array) -> int:
var exited_previous_room = false
# If auto transition is enabled, try to determine whether we just exited a
# room previously, so that we must play the auto transition out or not.
# This must happen if ESC_LAST_SCENE is set, or if we're running an
# exit_scene event. Also room selector actions require the transition.
if command_params[1] \
and escoria.event_manager.get_running_event("_front").name \
in ["exit_scene", "room_selector"]:
and (
not escoria.globals_manager.get_global("ESC_LAST_SCENE").empty()
or (
escoria.event_manager.get_running_event("_front").name \
in ["newgame", "exit_scene", "room_selector"]
and escoria.globals_manager.get_global(
"ESC_LAST_SCENE"
).empty()
)
):
exited_previous_room = true
escoria.main.scene_transition.transition(
var transition_id = escoria.main.scene_transition.transition(
"",
ESCTransitionPlayer.TRANSITION_MODE.OUT
)
escoria.logger.debug(
"Awaiting transition %s (out) to be finished." % str(transition_id)
)
yield(escoria.main.scene_transition, "transition_done")
# If BYPASS_LAST_SCENE is false, set ESC_LAST_SCENE = current room id
if escoria.main.current_scene \
and not escoria.globals_manager.get_global("BYPASS_LAST_SCENE"):
escoria.globals_manager.set_global(
"ESC_LAST_SCENE",
escoria.main.current_scene.global_id,
true
)
if escoria.globals_manager.get_global("BYPASS_LAST_SCENE"):
# Hide main and pause menus
escoria.game_scene.hide_main_menu()
escoria.game_scene.unpause_game()
# If FORCE_LAST_SCENE_NULL is true, force ESC_LAST_SCENE to empty
if escoria.globals_manager.get_global("FORCE_LAST_SCENE_NULL"):
escoria.globals_manager.set_global(
"ESC_LAST_SCENE",
null,
true
)
elif escoria.main.current_scene:
# If FORCE_LAST_SCENE_NULL is false, set ESC_LAST_SCENE = current roomid
escoria.globals_manager.set_global(
"ESC_LAST_SCENE",
escoria.main.current_scene.global_id,
true
)
if escoria.dialog_player:
escoria.dialog_player.interrupt()

View File

@@ -35,7 +35,7 @@ func validate(arguments: Array):
escoria.logger.report_errors(
"teleport: invalid second object",
[
"Object with global id %s not found" % arguments[0]
"Object with global id %s not found" % arguments[1]
]
)
return false

View File

@@ -37,6 +37,7 @@ func validate(arguments: Array):
# Run the command
func run(command_params: Array) -> int:
(escoria.object_manager.get_object(command_params[0]).node as ESCPlayer)\
.teleport_to(Vector2(int(command_params[1]), int(command_params[2])))
escoria.object_manager.get_object(command_params[0]).node.teleport_to(
Vector2(int(command_params[1]), int(command_params[2]))
)
return ESCExecution.RC_OK

View File

@@ -68,7 +68,8 @@ func _process(delta: float) -> void:
"finished",
self,
"_on_event_finished",
[channel_name]
[channel_name],
CONNECT_ONESHOT
)
if not _running_events[channel_name].is_connected(
"interrupted", self, "_on_event_finished"
@@ -77,7 +78,8 @@ func _process(delta: float) -> void:
"interrupted",
self,
"_on_event_finished",
[channel_name]
[channel_name],
CONNECT_ONESHOT
)
if channel_name == "_front":
@@ -170,8 +172,6 @@ func _on_event_finished(return_code: int, channel_name: String) -> void:
escoria.logger.debug(
"Event %s ended with return code %d" % [event.name, return_code]
)
event.disconnect("finished", self, "_on_event_finished")
event.disconnect("interrupted", self, "_on_event_finished")
if return_code == ESCExecution.RC_CANCEL:
return_code = ESCExecution.RC_OK

View File

@@ -14,8 +14,9 @@ signal global_changed(global, old_value, new_value)
# A list of reserved globals which can not be overridden
const RESERVED_GLOBALS = [
"ESC_LAST_SCENE",
"BYPASS_LAST_SCENE",
"ESC_LAST_SCENE", # Contains the global_id of previous room
"FORCE_LAST_SCENE_NULL", # If true, ESC_LAST_SCENE is not considered for
# automatic transitions
"ANIMATION_RESOURCES"
]
@@ -27,7 +28,7 @@ export(Dictionary) var _globals = {}
func _init():
set_global("ESC_LAST_SCENE", "", true)
set_global("BYPASS_LAST_SCENE", false, true)
set_global("FORCE_LAST_SCENE_NULL", false, true)
# Check if a global was registered

View File

@@ -292,12 +292,12 @@ func _set_editor_debug_mode(p_editor_debug_mode: int) -> void:
# Pauses the game. Reimplement to eventually show a specific UI.
func pause_game():
pass
escoria.set_game_paused(true)
# Unpause the game. Reimplement to eventually hide a specific UI.
func unpause_game():
pass
escoria.set_game_paused(false)
# Shows the main menu. Reimplement to show a specific UI.

View File

@@ -147,8 +147,7 @@ func perform_script_events():
":transition_out",
"transition %s out" % ProjectSettings.get_setting(
"escoria/ui/default_transition"
),
"hide_menu main"
)
])
escoria.event_manager.queue_event(
script_transition_out.events['transition_out']
@@ -160,7 +159,7 @@ func perform_script_events():
if enabled_automatic_transitions \
or (
not enabled_automatic_transitions \
and escoria.globals_manager.get_global("BYPASS_LAST_SCENE")
and escoria.globals_manager.get_global("FORCE_LAST_SCENE_NULL")
):
var script_transition_in = escoria.esc_compiler.compile([
":transition_in",
@@ -179,26 +178,27 @@ func perform_script_events():
if ready_event_added:
# Wait for ready event to be done
var rc = yield(escoria.event_manager, "event_finished")
while rc[1] != "ready":
rc = yield(escoria.event_manager, "event_finished")
if rc[0] != ESCExecution.RC_OK:
return rc[0]
# Now that :ready is finished, if BYPASS_LAST_SCENE was true, reset it
# to false and set ESC_LAST_SCENE to current scene
if escoria.globals_manager.get_global("BYPASS_LAST_SCENE"):
# Now that :ready is finished, if FORCE_LAST_SCENE_NULL was true, reset it
# to false
if escoria.globals_manager.get_global("FORCE_LAST_SCENE_NULL"):
escoria.globals_manager.set_global(
"BYPASS_LAST_SCENE",
"FORCE_LAST_SCENE_NULL",
false,
true
)
escoria.globals_manager.set_global(
"ESC_LAST_SCENE",
escoria.main.current_scene.global_id \
if escoria.main.current_scene != null else "",
true
)
escoria.globals_manager.set_global(
"ESC_LAST_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.

View File

@@ -119,4 +119,5 @@ func _on_tween_completed():
if not _was_canceled:
_tween.stop_all()
_tween.remove_all()
escoria.logger.debug("Transition %s done." % str(transition_id))
emit_signal("transition_done", transition_id)

View File

@@ -50,7 +50,11 @@ func _ready():
# Switch to the selected room
func _on_button_pressed():
escoria.globals_manager.set_global("BYPASS_LAST_SCENE", true, true)
# When next room is loaded, we don't want to consider ESC_LAST_SCENE for
# automatic transitions.
# If FORCE_LAST_SCENE_NULL is True when change_scene starts:
# - ESC_LAST_SCENE is set to empty
escoria.globals_manager.set_global("FORCE_LAST_SCENE_NULL", true, true)
var script = escoria.esc_compiler.compile([
":room_selector",
"change_scene %s" % _options_paths[_selected_id]

View File

@@ -78,7 +78,7 @@ position = Vector2( 340.052, 298.812 )
[node name="r_door" type="Area2D" parent="Hotspots"]
script = ExtResource( 8 )
global_id = "r_door"
global_id = "r12_r_exit"
tooltip_name = "Right exit"
target_scene = "res://game/rooms/room13/room13.tscn"
switch_sound = "res://game/sfx/sounds/doorOpen_2.ogg"
@@ -94,3 +94,4 @@ script = ExtResource( 5 )
position = Vector2( 542.824, 468.193 )
script = ExtResource( 5 )
global_id = "player_start"
is_start_location = true

View File

@@ -3,10 +3,11 @@
# This event demonstrates the following:
#- fade out to black
#- show the main menu (automatic transition disabled to manage those manually)
#- show the pause menu (automatic transition disabled to manage those manually)
#- wait 2 seconds
#- change scene (automatic transition disabled to managed those manually) to reload this same room
#- change scene (automatic transition disabled to manage those manually) to reload this same room
set_global transition_manual true
# Fade out to black
transition fade_black out
@@ -32,6 +33,6 @@ wait 1
# If you transition IN here instead of room's :setup event, you will show the previous room
# Change scene to same scene, disabled automatic transition
change_scene res://game/rooms/room14/room14.tscn true
change_scene res://game/rooms/room14/room14.tscn false
# Do not transition here either, as change_scene ends the execution of this script

View File

@@ -0,0 +1,28 @@
:use
# This event demonstrates the following:
#- fade out to black
#- show the pause menu (automatic transition disabled to manage those manually)
#- wait 2 seconds
#- change scene (automatic transition enabled) to reload this same room
set_global transition_manual false
# Fade out to black
transition fade_black out
wait 2
# Show main menu, automatic transition DISABLED
show_menu pause
# Showing menu
transition shards in
# Wait 2 seconds on menu
wait 2
# Change scene to same scene, enabled automatic transition
change_scene res://game/rooms/room14/room14.tscn

View File

@@ -14,8 +14,8 @@
stop
# If we're coming from the same room as this one, we manage the player's position
# AND the transition IN manually
> [eq ESC_LAST_SCENE room14]
# AND the transition IN manually if we pushed that button
> [eq ESC_LAST_SCENE room14, transition_manual]
teleport player start
# Set player look left
@@ -25,6 +25,15 @@
transition fade_black in
stop
# If we're coming from the same room as this one, we manage the player's position only
> [eq ESC_LAST_SCENE room14, !transition_manual]
teleport player start
# Set player look left
set_angle player 270
stop
:ready
queue_event worker moveworker

View File

@@ -127,21 +127,21 @@ __meta__ = {
"_edit_use_anchors_": false
}
[node name="show_main_change_scene" parent="." instance=ExtResource( 9 )]
[node name="show_pause_change_scene_manual" parent="." instance=ExtResource( 9 )]
position = Vector2( 463.318, 0 )
global_id = "button_main_change_scene"
esc_script = "res://game/rooms/room14/esc/button_main_menu_change_scene.esc"
[node name="ESCLocation" type="Position2D" parent="show_main_change_scene"]
[node name="ESCLocation" type="Position2D" parent="show_pause_change_scene_manual"]
position = Vector2( 343.887, 381.305 )
script = ExtResource( 5 )
[node name="Label" type="Label" parent="show_main_change_scene"]
[node name="Label" type="Label" parent="show_pause_change_scene_manual"]
margin_left = 277.027
margin_top = 194.0
margin_right = 428.027
margin_bottom = 259.0
text = "Show main menu with
text = "Show pause menu with
manual transition
and change_scene with
manual transition"
@@ -150,11 +150,34 @@ __meta__ = {
"_edit_use_anchors_": false
}
[node name="show_pause_change_scene_auto" parent="." instance=ExtResource( 9 )]
position = Vector2( 676.318, 0 )
global_id = "button_pause_change_scene_auto"
esc_script = "res://game/rooms/room14/esc/button_main_menu_change_scene_auto.esc"
[node name="ESCLocation" type="Position2D" parent="show_pause_change_scene_auto"]
position = Vector2( 343.887, 381.305 )
script = ExtResource( 5 )
[node name="Label" type="Label" parent="show_pause_change_scene_auto"]
margin_left = 277.027
margin_top = 194.0
margin_right = 428.027
margin_bottom = 259.0
text = "Show pause menu with
manual transition
and change_scene with
automatic transition"
align = 1
__meta__ = {
"_edit_use_anchors_": false
}
[node name="worker" parent="." instance=ExtResource( 10 )]
position = Vector2( 204.268, 376.233 )
esc_script = "res://game/rooms/room14/esc/worker.esc"
[node name="worker_target" type="Position2D" parent="."]
position = Vector2( 970.51, 374.808 )
position = Vector2( 917.51, 475.808 )
script = ExtResource( 5 )
global_id = "worker_target"

View File

@@ -1,18 +0,0 @@
[gd_scene load_steps=3 format=2]
[ext_resource path="res://addons/escoria-core/game/core-scripts/esc_terrain.gd" type="Script" id=1]
[sub_resource type="NavigationPolygon" id=1]
vertices = PoolVector2Array( 1168.92, 640.557, 1182.53, 588.863, 1269.59, 622.872, 1275.03, 799.721, 129.634, 615.792, 1143.08, 613.35, -9.16094, 803.802, 84.5821, 654.06, -6.44019, 711.297, 3.15687, 646.051, 59.2201, 628.698 )
polygons = [ PoolIntArray( 0, 1, 2, 3 ), PoolIntArray( 4, 5, 0, 3, 6, 7 ), PoolIntArray( 7, 6, 8, 9, 10 ) ]
outlines = [ PoolVector2Array( -6.44019, 711.297, 3.15687, 646.051, 59.2201, 628.698, 84.5821, 654.06, 129.634, 615.792, 1143.08, 613.35, 1168.92, 640.557, 1182.53, 588.863, 1269.59, 622.872, 1275.03, 799.721, -9.16094, 803.802 ) ]
[node name="walkable_area" type="Navigation2D"]
script = ExtResource( 1 )
[node name="platform" type="NavigationPolygonInstance" parent="."]
position = Vector2( 6.73163, -264.779 )
navpoly = SubResource( 1 )
__meta__ = {
"_editor_description_": ""
}

View File

@@ -1,25 +0,0 @@
[gd_scene load_steps=3 format=2]
[ext_resource path="res://addons/escoria-core/game/core-scripts/esc_item.gd" type="Script" id=1]
[ext_resource path="res://addons/escoria-core/game/core-scripts/esc_location.gd" type="Script" id=2]
[node name="r_door" type="Area2D"]
pause_mode = 1
script = ExtResource( 1 )
__meta__ = {
"_editor_description_": ""
}
global_id = "r1_r_exit"
esc_script = "res://game/rooms/room01/esc/right_exit.esc"
is_exit = true
tooltip_name = "Exit"
default_action = "walk"
dialog_color = Color( 1, 1, 1, 1 )
animations = null
[node name="CollisionPolygon2D" type="CollisionPolygon2D" parent="."]
polygon = PoolVector2Array( 1177.94, 348.61, 1175.95, 45.3759, 1276.06, 92.0953, 1277.95, 399.407 )
[node name="Position2D" type="Position2D" parent="."]
position = Vector2( 1225.47, 353.99 )
script = ExtResource( 2 )

View File

@@ -7,8 +7,8 @@
[ext_resource path="res://addons/escoria-core/game/core-scripts/esc_location.gd" type="Script" id=5]
[ext_resource path="res://addons/escoria-core/game/core-scripts/esc_room.gd" type="Script" id=6]
[ext_resource path="res://addons/escoria-core/game/core-scripts/esc_item.gd" type="Script" id=7]
[ext_resource path="res://game/rooms/room15/r_door.tscn" type="PackedScene" id=8]
[ext_resource path="res://game/items/escitems/button.tscn" type="PackedScene" id=9]
[ext_resource path="res://addons/escoria-core/game/core-scripts/esc_exit.gd" type="Script" id=10]
[sub_resource type="NavigationPolygon" id=1]
vertices = PoolVector2Array( 1168.92, 640.557, 1182.53, 588.863, 1269.59, 622.872, 1275.03, 799.721, 864.626, 613.518, 1143.08, 613.35, -9.16094, 803.802, 386.666, 618.012, 129.634, 615.792, 84.5821, 654.06, -6.44019, 711.297, 3.15687, 646.051, 59.2201, 628.698 )
@@ -80,9 +80,17 @@ position = Vector2( 37.4521, 392.045 )
script = ExtResource( 5 )
global_id = "r12_l_exit"
[node name="r_door" parent="Hotspots" instance=ExtResource( 8 )]
global_id = "r15_r_exit"
esc_script = ""
[node name="r_door" type="Area2D" parent="Hotspots"]
script = ExtResource( 10 )
tooltip_name = "Right exit"
switch_sound = "res://game/sfx/sounds/doorOpen_2.ogg"
[node name="CollisionPolygon2D" type="CollisionPolygon2D" parent="Hotspots/r_door"]
position = Vector2( 0, -1 )
polygon = PoolVector2Array( 1177.94, 348.61, 1175.95, 45.3759, 1276.06, 92.0953, 1277.95, 399.407 )
__meta__ = {
"_editor_description_": ""
}
[node name="ESCLocation" type="Position2D" parent="Hotspots/r_door"]
position = Vector2( 1231.78, 360.624 )

View File

@@ -1,18 +0,0 @@
[gd_scene load_steps=3 format=2]
[ext_resource path="res://addons/escoria-core/game/core-scripts/esc_terrain.gd" type="Script" id=1]
[sub_resource type="NavigationPolygon" id=1]
vertices = PoolVector2Array( 1168.92, 640.557, 1182.53, 588.863, 1269.59, 622.872, 1275.03, 799.721, 129.634, 615.792, 1143.08, 613.35, -9.16094, 803.802, 84.5821, 654.06, -6.44019, 711.297, 3.15687, 646.051, 59.2201, 628.698 )
polygons = [ PoolIntArray( 0, 1, 2, 3 ), PoolIntArray( 4, 5, 0, 3, 6, 7 ), PoolIntArray( 7, 6, 8, 9, 10 ) ]
outlines = [ PoolVector2Array( -6.44019, 711.297, 3.15687, 646.051, 59.2201, 628.698, 84.5821, 654.06, 129.634, 615.792, 1143.08, 613.35, 1168.92, 640.557, 1182.53, 588.863, 1269.59, 622.872, 1275.03, 799.721, -9.16094, 803.802 ) ]
[node name="walkable_area" type="Navigation2D"]
script = ExtResource( 1 )
[node name="platform" type="NavigationPolygonInstance" parent="."]
position = Vector2( 6.73163, -264.779 )
navpoly = SubResource( 1 )
__meta__ = {
"_editor_description_": ""
}

View File

@@ -685,7 +685,7 @@ search_in_file_extensions=PoolStringArray( "gd", "shader", "esc" )
[editor_plugins]
enabled=PoolStringArray( "res://addons/escoria-core/plugin.cfg", "res://addons/escoria-dialog-simple/plugin.cfg", "res://addons/escoria-ui-simplemouse/plugin.cfg" )
enabled=PoolStringArray( "res://addons/escoria-core/plugin.cfg", "res://addons/escoria-dialog-simple/plugin.cfg", "res://addons/escoria-ui-9verbs/plugin.cfg" )
[escoria]
@@ -694,7 +694,7 @@ main/force_quit=true
debug/terminate_on_warnings=false
debug/terminate_on_errors=true
debug/development_lang="en"
ui/tooltip_follows_mouse=true
ui/tooltip_follows_mouse=false
main/text_lang="fr_FR"
main/voice_lang="fr_FR"
sound/music_volume=1
@@ -702,7 +702,7 @@ sound/sfx_volume=1
sound/speech_volume=1
sound/master_volume=1
main/command_directories=[ "res://addons/escoria-core/game/core-scripts/esc/commands" ]
debug/log_level="TRACE"
debug/log_level="DEBUG"
platform/skip_cache=false
platform/skip_cache.mobile=true
ui/items_autoregister_path="res://game/items/inventory"
@@ -711,7 +711,7 @@ main/savegames_path="res://saves/"
main/settings_path="user://"
main/escoria_version=""
sound/speech_enabled=1
ui/game_scene="res://addons/escoria-ui-simplemouse/game.tscn"
ui/game_scene="res://addons/escoria-ui-9verbs/game.tscn"
ui/dialogs_chooser="res://addons/escoria-core/ui_library/dialogs/text_dialog_chooser.tscn"
sound/speech_folder="res://game/speech"
sound/speech_extension="ogg"
@@ -730,6 +730,7 @@ debug/log_file_path="user://"
debug/crash_message="We're sorry, but the game crashed. Please send us the following files:
%s"
ui/default_dialog_scene="res://addons/escoria-core/ui_library/dialogs/floating_dialog_player.tscn"
[input]