From f2991c30c7e641a061f1bccf6c062349b6b1f069 Mon Sep 17 00:00:00 2001 From: Julian Murgia Date: Thu, 29 Jul 2021 14:22:42 +0200 Subject: [PATCH] Added sound management in savegames and load games. (#337) Fixes #300 Fix crash on loading game when the saved position was a float while teleport_pos command needs integers. Fix pause menu missing in simplemouse-ui, causing a crash when calling pause menu. Co-authored-by: StraToN --- .../game/core-scripts/esc/types/esc_object.gd | 4 ++++ .../core-scripts/save_data/esc_save_manager.gd | 15 +++++++++++---- .../escoria-core/game/scenes/sound/bg_sound.gd | 4 ++++ .../game/scenes/sound/bg_sound.tscn | 2 ++ addons/escoria-ui-simplemouse/game.gd | 17 +++++++++++++++++ addons/escoria-ui-simplemouse/game.tscn | 6 +++++- docs/esc.md | 1 + game/translations/game.en.translation | Bin 549 -> 386 bytes game/translations/game.fr.translation | Bin 588 -> 406 bytes game/ui/commons/pause_menu/pause_menu.gd | 4 ++++ 10 files changed, 48 insertions(+), 5 deletions(-) diff --git a/addons/escoria-core/game/core-scripts/esc/types/esc_object.gd b/addons/escoria-core/game/core-scripts/esc/types/esc_object.gd index 45081947..dbfe1cb2 100644 --- a/addons/escoria-core/game/core-scripts/esc/types/esc_object.gd +++ b/addons/escoria-core/game/core-scripts/esc/types/esc_object.gd @@ -87,4 +87,8 @@ func get_save_data() -> Dictionary: save_data["last_deg"] = wrapi(self.node._movable._get_angle() + 1, 0, 360) save_data["last_dir"] = self.node._movable.last_dir + if (self.global_id == "bg_music" or self.global_id == "bg_sound") \ + and self.node.get("state"): + save_data["state"] = self.node.get("state") + return save_data diff --git a/addons/escoria-core/game/core-scripts/save_data/esc_save_manager.gd b/addons/escoria-core/game/core-scripts/save_data/esc_save_manager.gd index a0a20407..cb4977bf 100644 --- a/addons/escoria-core/game/core-scripts/save_data/esc_save_manager.gd +++ b/addons/escoria-core/game/core-scripts/save_data/esc_save_manager.gd @@ -151,15 +151,22 @@ func load_game(id: int): if save_game.objects[object_global_id].has("global_transform"): load_statements.append(ESCCommand.new("teleport_pos %s %s %s" \ % [object_global_id, - save_game.objects[object_global_id] \ - ["global_transform"].origin.x, - save_game.objects[object_global_id] \ - ["global_transform"].origin.y]) + int(save_game.objects[object_global_id] \ + ["global_transform"].origin.x), + int(save_game.objects[object_global_id] \ + ["global_transform"].origin.y)] + ) ) load_statements.append(ESCCommand.new("set_angle %s %s" \ % [object_global_id, save_game.objects[object_global_id]["last_deg"]]) ) + + if object_global_id == "bg_music" or object_global_id == "bg_sound": + load_statements.append(ESCCommand.new("set_sound_state %s %s true" \ + % [object_global_id, + save_game.objects[object_global_id]["state"]]) + ) load_event.statements = load_statements escoria.event_manager.queue_event(load_event) diff --git a/addons/escoria-core/game/scenes/sound/bg_sound.gd b/addons/escoria-core/game/scenes/sound/bg_sound.gd index eb0d07ef..c827a5a1 100644 --- a/addons/escoria-core/game/scenes/sound/bg_sound.gd +++ b/addons/escoria-core/game/scenes/sound/bg_sound.gd @@ -51,3 +51,7 @@ func _ready(): ESCObject.new(global_id, self), true ) + +# Set state to default when finished playing. +func _on_sound_finished(): + state = "default" diff --git a/addons/escoria-core/game/scenes/sound/bg_sound.tscn b/addons/escoria-core/game/scenes/sound/bg_sound.tscn index 69c4e820..fcde5b60 100644 --- a/addons/escoria-core/game/scenes/sound/bg_sound.tscn +++ b/addons/escoria-core/game/scenes/sound/bg_sound.tscn @@ -15,3 +15,5 @@ __meta__ = { [node name="AudioStreamPlayer" type="AudioStreamPlayer" parent="."] bus = "SFX" + +[connection signal="finished" from="AudioStreamPlayer" to="." method="_on_sound_finished"] diff --git a/addons/escoria-ui-simplemouse/game.gd b/addons/escoria-ui-simplemouse/game.gd index c2bd5a75..6bd31711 100644 --- a/addons/escoria-ui-simplemouse/game.gd +++ b/addons/escoria-ui-simplemouse/game.gd @@ -123,15 +123,32 @@ func open_inventory(): func close_inventory(): $ui/inventory_layer/inventory_ui/inventory_button.close_inventory() + func mousewheel_action(direction: int): $ui/verbs_layer/verbs_menu.iterate_actions_cursor(direction) + func hide_ui(): $ui/inventory_layer/inventory_ui.hide() + func show_ui(): $ui/inventory_layer/inventory_ui.show() + func _on_event_done(event_name: String): escoria.action_manager.clear_current_action() $ui/verbs_layer/verbs_menu.clear_tool_texture() + + +func pause_game(): + if $ui/pause_menu.visible: + $ui/pause_menu.hide() + escoria.main.current_scene.game.get_node("camera").current = true + escoria.main.current_scene.game.show_ui() + escoria.main.current_scene.show() + else: + $ui/pause_menu.show() + escoria.main.current_scene.game.get_node("camera").current = false + escoria.main.current_scene.game.hide_ui() + escoria.main.current_scene.hide() diff --git a/addons/escoria-ui-simplemouse/game.tscn b/addons/escoria-ui-simplemouse/game.tscn index fac12de7..52b8e1ba 100644 --- a/addons/escoria-ui-simplemouse/game.tscn +++ b/addons/escoria-ui-simplemouse/game.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=8 format=2] +[gd_scene load_steps=9 format=2] [ext_resource path="res://addons/escoria-ui-simplemouse/inventory/inventory_ui.tscn" type="PackedScene" id=1] [ext_resource path="res://addons/escoria-core/game/scenes/dialogs/dialog_player.tscn" type="PackedScene" id=2] @@ -7,6 +7,7 @@ [ext_resource path="res://addons/escoria-ui-simplemouse/game.gd" type="Script" id=5] [ext_resource path="res://addons/escoria-ui-simplemouse/tooltip/target_tooltip.tscn" type="PackedScene" id=6] [ext_resource path="res://game/ui/commons/room_select.tscn" type="PackedScene" id=7] +[ext_resource path="res://game/ui/commons/pause_menu/pause_menu.tscn" type="PackedScene" id=8] [node name="game" type="Node2D"] script = ExtResource( 5 ) @@ -51,4 +52,7 @@ margin_top = 751.323 margin_right = 138.51 margin_bottom = 791.324 +[node name="pause_menu" parent="ui" instance=ExtResource( 8 )] +visible = false + [node name="camera" parent="." instance=ExtResource( 3 )] diff --git a/docs/esc.md b/docs/esc.md index 0b1ca775..9b870c3a 100644 --- a/docs/esc.md +++ b/docs/esc.md @@ -407,6 +407,7 @@ Makes the `player` walk to the position `x`/`y`. + ## Dialogs Dialogs are specified by writing `?` with optional parameters, followed by a list of dialog options starting with `-`. Use `!` to end the dialog. diff --git a/game/translations/game.en.translation b/game/translations/game.en.translation index 16037dc631a57be4b47f7759fb4bc9663a65f070..189a5056f824f1f7a63722d1e8ebaac99812ee24 100644 GIT binary patch literal 386 zcmV-|0e${bQ$s@n000005C8x}0ssJN0RR9fwJ-f(LjeT~00vS+JRs#dYYNEF0g%9x z05EF;f`Cyb1wfWf&_1wh&m_b^E7^$OcEUI+C+7oC3)tVG!$SQtu1P8*ORhBp-iVu zbFSUr`#ll=!cRh$W&nrZM3yE1f&YRm&6f{Znl23ooAW%+U-JhXn`)Z{h3xQd2SS5E zMKqGq?jOwA$soyQCj&|Zge}?ytxzfv5N$iDI45ZHalar%DO8c!AjxK?74J@11R)?m z0%IVw4$VN9y)x(Lf0d7^PYVMYT?1R7l=o;f!2+SYk&W$qKN(C*IznuQU~v}4B9+BG gvk&{x!rh{sY8Aj#4)s>#mm^EbJLNarHd0eVL%D;csQ>@~ literal 549 zcmbV~%}T>S6oqfCt+iG`6n{WyiuGqvtl~zB2t_Ieik7q@UBzh_+LAPpObS9DK=2s^ zS3ZKcbMITI3*G1|OgvK~xai6YALrgPbMH*T72qKHF(nMGbZW}?&ZnJXL?bUpWX z-@i45&L!Y;;q`rsn~rBO#|%7ESls0_^LNcT@VjpNr%hOX_cDM<6a#56oKz|ncPOJQ#K><}KV%$eAOS)IgpyI7 zfhu1E3qZ|Myu9BGcA+^?h&<)L!iSIsHo+KB{u}%TbP=eY57ZiT4y*umUKZFu>J%o7 zO1WBX-e={;sJ>vjJ*!un Yd8t2ppBGi9XV6-JpgfFET5+vWBd>5~18oS#W8s4E-4~gS9tqUU}SAwx__(=*d05bqL z02tTT|IO=*h6Ar*1@R~5&r(pdUj;8r#P$9+_^){=wlcLir1!+a)FR_Q!S)~X2YcbF z02~gwDiF@0`l72)2;$+tmN{A%#H+A%GtPAbgr)uqyxJ7a9}82~|M~hqb6i(6AKl{V z&<`Q`IF&jK(#S()cHSsP=7s(b@}GlXN3vY`uYelKQswgBGm>RW#DCF9ma_sbVDB9j zp2_uZHow6?(1hmrUeCghE5Z0Ebl ze%d6NxwVZG8+jo^0I&};hxD`br9*Wea&7|s4XbIdNIG@LHu+-x#VNfcoRBL!&-PiOdM!)7#t zveC0nnI9Q)6ZgHg(;T&N%WI$cFo|Md8ibQJip6zOrG@zOof9~aA7wJq6OW{ojjRBH zl%{~p)yU66=Ybq88NT0Ll%SH$$dmpnd`LJi51jzge}ivB<%|{ZfjS%2OHjEl1FnJC zSMGNbevmxY%asGITEBX@A#tAn5`|LS5hTj08pH-q+Dl)t`xDRGmqBcmL^YEO)Y{-y ruV_a#P4?wPM@fr9BDI)b9x9*cc~m+TB^tFBc8zvz{oX*N<3IWapSytt diff --git a/game/ui/commons/pause_menu/pause_menu.gd b/game/ui/commons/pause_menu/pause_menu.gd index 6e40c440..9bf7256c 100644 --- a/game/ui/commons/pause_menu/pause_menu.gd +++ b/game/ui/commons/pause_menu/pause_menu.gd @@ -1,6 +1,10 @@ extends Control +func _ready(): + hide() + + func _on_continue_pressed(): escoria.main.current_scene.game.pause_game()