From b710def99d72c578cd85eef72b5492c17d3f4648 Mon Sep 17 00:00:00 2001 From: Dennis Ploeger Date: Tue, 28 Sep 2021 10:08:03 +0200 Subject: [PATCH] fix: Fixes for when the player scene isn't used in a room. (#404) Co-authored-by: Dennis Ploeger --- .../game/core-scripts/esc_controller.gd | 187 +++++++++--------- game/rooms/room12/esc/right_exit.esc | 4 +- game/rooms/room12/esc/room12.esc | 2 + game/rooms/room13/background.tscn | 30 +++ game/rooms/room13/esc/hint.esc | 2 + game/rooms/room13/esc/left_exit.esc | 5 + game/rooms/room13/esc/right_exit.esc | 3 + game/rooms/room13/esc/room13.esc | 5 + game/rooms/room13/r_door.tscn | 25 +++ game/rooms/room13/room13.tscn | 109 ++++++++++ game/rooms/room13/walkable_area.tscn | 18 ++ 11 files changed, 294 insertions(+), 96 deletions(-) create mode 100644 game/rooms/room13/background.tscn create mode 100644 game/rooms/room13/esc/hint.esc create mode 100644 game/rooms/room13/esc/left_exit.esc create mode 100644 game/rooms/room13/esc/right_exit.esc create mode 100644 game/rooms/room13/esc/room13.esc create mode 100644 game/rooms/room13/r_door.tscn create mode 100644 game/rooms/room13/room13.tscn create mode 100644 game/rooms/room13/walkable_area.tscn diff --git a/addons/escoria-core/game/core-scripts/esc_controller.gd b/addons/escoria-core/game/core-scripts/esc_controller.gd index 31de0127..30070228 100644 --- a/addons/escoria-core/game/core-scripts/esc_controller.gd +++ b/addons/escoria-core/game/core-scripts/esc_controller.gd @@ -105,112 +105,111 @@ func perform_inputevent_on_object( # (because object is inactive for example) var dont_interact = false - var destination_position: Vector2 = escoria.main.current_scene.player.\ - global_position - - # If clicked object not in inventory, player walks towards it - if not obj.node is ESCPlayer and \ - not escoria.inventory_manager.inventory_has(obj.global_id) and \ - (not has_current_action or not event_flags & ESCEvent.FLAG_TK): - var context = _walk_towards_object( - obj, - event.position, - event.doubleclick - ) - if context is GDScriptFunctionState: - context = yield(_walk_towards_object( + if escoria.main.current_scene.player: + var destination_position: Vector2 = escoria.main.current_scene.player.\ + global_position + + # If clicked object not in inventory, player walks towards it + if not obj.node is ESCPlayer and \ + not escoria.inventory_manager.inventory_has(obj.global_id) and \ + (not has_current_action or not event_flags & ESCEvent.FLAG_TK): + var context = _walk_towards_object( obj, event.position, event.doubleclick - ), "completed") - destination_position = context.target_position - dont_interact = context.dont_interact_on_arrival + ) + if context is GDScriptFunctionState: + context = yield(_walk_towards_object( + obj, + event.position, + event.doubleclick + ), "completed") + destination_position = context.target_position + dont_interact = context.dont_interact_on_arrival + + var player_global_pos = escoria.main.current_scene.player.global_position + var clicked_position = event.position + + if not player_global_pos == destination_position: + dont_interact = true # If no interaction should happen after player has arrived, leave # immediately. if dont_interact: return - var player_global_pos = escoria.main.current_scene.player.global_position - var clicked_position = event.position + # If NO_TT flag is active, hide tooltip and connect for + # event finished to show it back + if event_flags & ESCEvent.FLAG_NO_TT \ + and not escoria.event_manager.is_connected( + "event_finished", + self, + "_on_no_tooltip_event_finished" + ): + escoria.main.current_scene.game.tooltip_node.hide() + escoria.event_manager.connect( + "event_finished", + self, + "_on_no_tooltip_event_finished" + ) - # If player has arrived at the position he was supposed to reach - # so he can interact - if player_global_pos == destination_position: - - # If NO_TT flag is active, hide tooltip and connect for - # event finished to show it back - if event_flags & ESCEvent.FLAG_NO_TT \ - and not escoria.event_manager.is_connected( - "event_finished", - self, - "_on_no_tooltip_event_finished" - ): - escoria.main.current_scene.game.tooltip_node.hide() - escoria.event_manager.connect( - "event_finished", - self, - "_on_no_tooltip_event_finished" + if event_flags & ESCEvent.FLAG_NO_HUD and \ + not escoria.event_manager.is_connected( + "event_finished", + self, + "_on_no_hud_event_finished" + ): + escoria.main.current_scene.game.hide_ui() + escoria.event_manager.connect( + "event_finished", + self, + "_on_no_hud_event_finished" + ) + + if event_flags & ESCEvent.FLAG_NO_SAVE and \ + not escoria.event_manager.is_connected( + "event_finished", + self, + "_on_no_save_event_finished" + ): + escoria.save_manager.save_enabled = false + escoria.event_manager.connect( + "event_finished", + self, + "_on_no_save_event_finished" + ) + pass + + # Manage exits + if obj.node.is_exit and escoria.action_manager.current_action \ + in ["", "walk"]: + escoria.action_manager.activate("exit_scene", obj) + else: + # Manage movements towards object before activating it + if escoria.action_manager.current_action in ["", "walk"] and \ + not escoria.inventory_manager.inventory_has(obj.global_id): + escoria.action_manager.activate("arrived", obj) + # Manage action on object + elif not escoria.action_manager.current_action in ["", "walk"]: + # Check if clicked item awaits a combination + var need_combine = _check_item_needs_combine( + obj, + default_action ) - - if event_flags & ESCEvent.FLAG_NO_HUD and \ - not escoria.event_manager.is_connected( - "event_finished", - self, - "_on_no_hud_event_finished" - ): - escoria.main.current_scene.game.hide_ui() - escoria.event_manager.connect( - "event_finished", - self, - "_on_no_hud_event_finished" - ) - - if event_flags & ESCEvent.FLAG_NO_SAVE and \ - not escoria.event_manager.is_connected( - "event_finished", - self, - "_on_no_save_event_finished" - ): - escoria.save_manager.save_enabled = false - escoria.event_manager.connect( - "event_finished", - self, - "_on_no_save_event_finished" - ) - pass - - - # Manage exits - if obj.node.is_exit and escoria.action_manager.current_action \ - in ["", "walk"]: - escoria.action_manager.activate("exit_scene", obj) - else: - # Manage movements towards object before activating it - if escoria.action_manager.current_action in ["", "walk"] and \ - not escoria.inventory_manager.inventory_has(obj.global_id): - escoria.action_manager.activate("arrived", obj) - # Manage action on object - elif not escoria.action_manager.current_action in ["", "walk"]: - # Check if clicked item awaits a combination - var need_combine = _check_item_needs_combine( - obj, - default_action + + # If apply_interact, perform combine between items + if need_combine: + escoria.action_manager.activate( + escoria.action_manager.current_action, + escoria.action_manager.current_tool, + obj + ) + + else: + escoria.action_manager.activate( + escoria.action_manager.current_action, + obj ) - - # If apply_interact, perform combine between items - if need_combine: - escoria.action_manager.activate( - escoria.action_manager.current_action, - escoria.action_manager.current_tool, - obj - ) - - else: - escoria.action_manager.activate( - escoria.action_manager.current_action, - obj - ) # Checks if object requires a combination with another, according to # currently selected action verb (or check with default action of the item). diff --git a/game/rooms/room12/esc/right_exit.esc b/game/rooms/room12/esc/right_exit.esc index 082fda66..a74e22ad 100644 --- a/game/rooms/room12/esc/right_exit.esc +++ b/game/rooms/room12/esc/right_exit.esc @@ -1,3 +1,3 @@ :exit_scene -#set_sound_state bg_sound res://game/sfx/sounds/doorOpen_2.ogg false -#change_scene "res://game/rooms/room13/room13.tscn" +set_sound_state _sound res://game/sfx/sounds/doorOpen_2.ogg false +change_scene "res://game/rooms/room13/room13.tscn" diff --git a/game/rooms/room12/esc/room12.esc b/game/rooms/room12/esc/room12.esc index 79f502f4..7b583fee 100644 --- a/game/rooms/room12/esc/room12.esc +++ b/game/rooms/room12/esc/room12.esc @@ -19,3 +19,5 @@ :ready transition fade_white in +wait 2 +transition fade_white out diff --git a/game/rooms/room13/background.tscn b/game/rooms/room13/background.tscn new file mode 100644 index 00000000..fa42fc10 --- /dev/null +++ b/game/rooms/room13/background.tscn @@ -0,0 +1,30 @@ +[gd_scene load_steps=2 format=2] + +[ext_resource path="res://addons/escoria-core/game/core-scripts/esc_background.gd" type="Script" id=1] + +[node name="background" type="TextureRect"] +margin_right = 1289.0 +margin_bottom = 555.0 +mouse_filter = 2 +script = ExtResource( 1 ) +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="l_platform" type="Line2D" parent="."] +position = Vector2( 2, -266 ) +points = PoolVector2Array( -2.96298, 712.01, 129.973, 614.429, 1167.5, 612.894, 1274.59, 669.705, 1273.25, 812.694, 2.36697, 811.043, 2.36697, 713.389 ) + +[node name="l_door" type="Line2D" parent="."] +position = Vector2( 0, -266 ) +points = PoolVector2Array( 6.61201, 704.409, 6.61203, 389.558, 87.755, 339.775, 87.5463, 649.784 ) +__meta__ = { +"_editor_description_": "" +} + +[node name="r_door" type="Line2D" parent="."] +position = Vector2( 0, -267.828 ) +points = PoolVector2Array( 1175.07, 620.086, 1171.24, 311.267, 1274.8, 356.87, 1278.31, 672.412, 1188.64, 624.843 ) +__meta__ = { +"_editor_description_": "" +} diff --git a/game/rooms/room13/esc/hint.esc b/game/rooms/room13/esc/hint.esc new file mode 100644 index 00000000..fe66bf12 --- /dev/null +++ b/game/rooms/room13/esc/hint.esc @@ -0,0 +1,2 @@ +:look + say player "I can just click the exits apparently." diff --git a/game/rooms/room13/esc/left_exit.esc b/game/rooms/room13/esc/left_exit.esc new file mode 100644 index 00000000..280d8810 --- /dev/null +++ b/game/rooms/room13/esc/left_exit.esc @@ -0,0 +1,5 @@ +:use +set_sound_state _sound res://game/sfx/sounds/doorOpen_2.ogg false +change_scene "res://game/rooms/room12/room12.tscn" + + diff --git a/game/rooms/room13/esc/right_exit.esc b/game/rooms/room13/esc/right_exit.esc new file mode 100644 index 00000000..2e1d39f2 --- /dev/null +++ b/game/rooms/room13/esc/right_exit.esc @@ -0,0 +1,3 @@ +:exit_scene +#set_sound_state _sound res://game/sfx/sounds/doorOpen_2.ogg false +#change_scene "res://game/rooms/room14/room14.tscn" diff --git a/game/rooms/room13/esc/room13.esc b/game/rooms/room13/esc/room13.esc new file mode 100644 index 00000000..faf6fe70 --- /dev/null +++ b/game/rooms/room13/esc/room13.esc @@ -0,0 +1,5 @@ + +:setup + + +:ready diff --git a/game/rooms/room13/r_door.tscn b/game/rooms/room13/r_door.tscn new file mode 100644 index 00000000..39b4fa38 --- /dev/null +++ b/game/rooms/room13/r_door.tscn @@ -0,0 +1,25 @@ +[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 ) diff --git a/game/rooms/room13/room13.tscn b/game/rooms/room13/room13.tscn new file mode 100644 index 00000000..4dca8977 --- /dev/null +++ b/game/rooms/room13/room13.tscn @@ -0,0 +1,109 @@ +[gd_scene load_steps=11 format=2] + +[ext_resource path="res://addons/escoria-core/game/core-scripts/esc_terrain.gd" type="Script" id=1] +[ext_resource path="res://game/rooms/room12/background.tscn" type="PackedScene" id=2] +[ext_resource path="res://game/ui/commons/fonts/caslonantique.tres" type="DynamicFont" id=3] +[ext_resource path="res://game/characters/mark/mark.tscn" type="PackedScene" id=4] +[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/room12/r_door.tscn" type="PackedScene" id=8] + +[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 ) +polygons = [ PoolIntArray( 0, 1, 2, 3 ), PoolIntArray( 4, 5, 0, 3, 6, 7 ), PoolIntArray( 8, 7, 6, 9 ), PoolIntArray( 9, 6, 10, 11, 12 ) ] +outlines = [ PoolVector2Array( -6.44019, 711.297, 3.15687, 646.051, 59.2201, 628.698, 84.5821, 654.06, 129.634, 615.792, 386.666, 618.012, 864.626, 613.518, 1143.08, 613.35, 1168.92, 640.557, 1182.53, 588.863, 1269.59, 622.872, 1275.03, 799.721, -9.16094, 803.802 ) ] + +[sub_resource type="RectangleShape2D" id=2] +extents = Vector2( 289.582, 45.1143 ) + +[node name="room13" type="Node2D"] +script = ExtResource( 6 ) +__meta__ = { +"_edit_vertical_guides_": [ ] +} +global_id = "room13" +esc_script = "res://game/rooms/room13/esc/room13.esc" +camera_limits = [ Rect2( 0, 0, 1289, 555 ) ] + +[node name="background" parent="." instance=ExtResource( 2 )] + +[node name="room_label" type="Label" parent="background"] +margin_right = 92.0 +margin_bottom = 21.0 +custom_fonts/font = ExtResource( 3 ) +text = "ROOM 12 +" +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="walkable_area" type="Navigation2D" parent="."] +script = ExtResource( 1 ) + +[node name="platform" type="NavigationPolygonInstance" parent="walkable_area"] +position = Vector2( 6.73163, -264.779 ) +navpoly = SubResource( 1 ) +__meta__ = { +"_editor_description_": "" +} + +[node name="Hotspots" type="Node" parent="."] + +[node name="l_door" type="Area2D" parent="Hotspots"] +pause_mode = 1 +script = ExtResource( 7 ) +global_id = "r13_l_exit" +esc_script = "res://game/rooms/room13/esc/left_exit.esc" +is_exit = true +tooltip_name = "Left exit" +default_action = "use" +dialog_color = Color( 1, 1, 1, 1 ) +animations = null + +[node name="CollisionPolygon2D" type="CollisionPolygon2D" parent="Hotspots/l_door"] +polygon = PoolVector2Array( 0.328762, 440.897, 1.85199, 119.926, 85.9517, 74.6212, 87.1409, 377.869 ) + +[node name="Position2D" type="Position2D" parent="Hotspots/l_door"] +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 = "r13_r_exit" +esc_script = "res://game/rooms/room12/esc/right_exit.esc" +default_action = "use" + +[node name="ESCLocation" type="Position2D" parent="Hotspots/r_door"] +position = Vector2( 1231.78, 360.624 ) +script = ExtResource( 5 ) + +[node name="Hint" type="Area2D" parent="Hotspots"] +pause_mode = 1 +script = ExtResource( 7 ) +global_id = "r13_hint" +esc_script = "res://game/rooms/room13/esc/hint.esc" +tooltip_name = "A hint" +default_action = "look" +dialog_color = Color( 1, 1, 1, 1 ) +animations = null + +[node name="Label" type="Label" parent="Hotspots/Hint"] +anchor_right = 1.0 +anchor_bottom = 1.0 +margin_right = 1278.0 +margin_bottom = 355.0 +text = "Click on either doors to go on." +align = 1 +valign = 1 +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="CollisionShape2D" type="CollisionShape2D" parent="Hotspots/Hint"] +position = Vector2( 651.176, 177.775 ) +shape = SubResource( 2 ) + +[node name="mark" parent="." instance=ExtResource( 4 )] +visible = false +position = Vector2( 620.216, 504.362 ) diff --git a/game/rooms/room13/walkable_area.tscn b/game/rooms/room13/walkable_area.tscn new file mode 100644 index 00000000..2d6b73ec --- /dev/null +++ b/game/rooms/room13/walkable_area.tscn @@ -0,0 +1,18 @@ +[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_": "" +}