diff --git a/.tmp b/.tmp new file mode 100644 index 00000000..cf241921 --- /dev/null +++ b/.tmp @@ -0,0 +1,9 @@ +:look +say player "It's a bottle." +stop + +:pickup +inventory_add r9_bottle true +set_active r9_bottle_left false +set_active r9_bottle_middle false +set_active r9_bottle_right false diff --git a/addons/escoria-core/editor/plugin_escoria.gd b/addons/escoria-core/editor/plugin_escoria.gd index f315eab4..989deeb1 100644 --- a/addons/escoria-core/editor/plugin_escoria.gd +++ b/addons/escoria-core/editor/plugin_escoria.gd @@ -132,8 +132,30 @@ func set_escoria_main_settings(): ProjectSettings.add_property_info(force_quit_property_info) ProjectSettings.set_setting("application/run/main_scene", "res://addons/escoria-core/game/main_scene.tscn") - - + + if !ProjectSettings.has_setting("escoria/main/text_lang"): + ProjectSettings.set_setting("escoria/main/text_lang", TranslationServer.get_locale()) + var text_lang_property_info = { + "name": "escoria/main/text_lang", + "type": TYPE_STRING, + "hint": PROPERTY_HINT_NONE + } + ProjectSettings.add_property_info(text_lang_property_info) + + if !ProjectSettings.has_setting("escoria/main/voice_lang"): + ProjectSettings.set_setting("escoria/main/voice_lang", TranslationServer.get_locale()) + var voice_lang_property_info = { + "name": "escoria/main/voice_lang", + "type": TYPE_STRING, + "hint": PROPERTY_HINT_NONE + } + ProjectSettings.add_property_info(voice_lang_property_info) + + + + + + func set_escoria_debug_settings(): if !ProjectSettings.has_setting("escoria/debug/terminate_on_warnings"): @@ -160,26 +182,46 @@ func set_escoria_internal_settings(): func set_escoria_sound_settings(): + if !ProjectSettings.has_setting("escoria/sound/master_volume"): + ProjectSettings.set_setting("escoria/sound/master_volume", 1) + var master_data_property_info = { + "name": "escoria/sound/master_volume", + "type": TYPE_INT, + "hint": PROPERTY_HINT_RANGE, + "hint_string": "0,1" + } + ProjectSettings.add_property_info(master_data_property_info) + if !ProjectSettings.has_setting("escoria/sound/music_volume"): - ProjectSettings.set_setting("escoria/sound/music_volume", 5) + ProjectSettings.set_setting("escoria/sound/music_volume", 1) var music_data_property_info = { "name": "escoria/sound/music_volume", "type": TYPE_INT, "hint": PROPERTY_HINT_RANGE, - "hint_string": "0,15" + "hint_string": "0,1" } ProjectSettings.add_property_info(music_data_property_info) - if !ProjectSettings.has_setting("escoria/sound/sound_volume"): - ProjectSettings.set_setting("escoria/sound/sound_volume", 8) + if !ProjectSettings.has_setting("escoria/sound/sfx_volume"): + ProjectSettings.set_setting("escoria/sound/sfx_volume", 1) var sound_data_property_info = { - "name": "escoria/sound/sound_volume", + "name": "escoria/sound/sfx_volume", "type": TYPE_INT, "hint": PROPERTY_HINT_RANGE, - "hint_string": "0,15" + "hint_string": "0,1" } ProjectSettings.add_property_info(sound_data_property_info) + if !ProjectSettings.has_setting("escoria/sound/speech_volume"): + ProjectSettings.set_setting("escoria/sound/speech_volume", 1) + var speech_data_property_info = { + "name": "escoria/sound/speech_volume", + "type": TYPE_INT, + "hint": PROPERTY_HINT_RANGE, + "hint_string": "0,1" + } + ProjectSettings.add_property_info(speech_data_property_info) + # Defines platform-specific parameters. Those are the ones that must be re-set for each platform export. diff --git a/addons/escoria-core/game/core-scripts/esc/esc_runner.gd b/addons/escoria-core/game/core-scripts/esc/esc_runner.gd index 7d27f2a0..8830e47d 100644 --- a/addons/escoria-core/game/core-scripts/esc/esc_runner.gd +++ b/addons/escoria-core/game/core-scripts/esc/esc_runner.gd @@ -81,19 +81,22 @@ func _ready(): get_tree().set_auto_accept_quit(ProjectSettings.get('escoria/main/force_quit')) randomize() - save_data.load_settings([self, "settings_loaded"]) + save_data.check_settings() + var settings = save_data.load_settings(null) + escoria.settings = parse_json(settings) + escoria._on_settings_loaded(escoria.settings) printt("Calling resource cache start") resource_cache.start() - if !ProjectSettings.get_setting("escoria/platform/skip_cache"): - scenes_cache_list.push_back(ProjectSettings.get_setting("escoria/main/curtain")) - scenes_cache_list.push_back(ProjectSettings.get_setting("escoria/main/hud")) - - printt("Cache list ", [scenes_cache_list]) - for s in scenes_cache_list: - if s != null: - resource_cache.queue_resource(s, false, true) +# if !ProjectSettings.get_setting("escoria/platform/skip_cache"): +# scenes_cache_list.push_back(ProjectSettings.get_setting("escoria/main/curtain")) +# scenes_cache_list.push_back(ProjectSettings.get_setting("escoria/main/hud")) +# +# printt("Cache list ", [scenes_cache_list]) +# for s in scenes_cache_list: +# if s != null: +# resource_cache.queue_resource(s, false, true) set_process(true) func _process(delta : float): @@ -736,7 +739,9 @@ func object_exit_scene(name : String): func check_obj(name, cmd): var obj = escoria.esc_runner.get_object(name) if obj == null: - escoria.logger.report_errors("", ["Global id "+name+" not found for " + cmd]) + escoria.logger.report_errors("esc_runner.gd:check_obj()", + ["Global id "+name+" not found for " + cmd]) return false return true + diff --git a/addons/escoria-core/game/core-scripts/resources/esc_script_resource.gd b/addons/escoria-core/game/core-scripts/resources/esc_script_resource.gd new file mode 100644 index 00000000..1406e9b2 --- /dev/null +++ b/addons/escoria-core/game/core-scripts/resources/esc_script_resource.gd @@ -0,0 +1,8 @@ +extends Script +class_name ESCScript + +func get_class(): + return "ESCScript" + +func _init(): + pass diff --git a/addons/escoria-core/game/core-scripts/save_data/save_data.gd b/addons/escoria-core/game/core-scripts/save_data/save_data.gd index 31629cd7..bdebe8dd 100644 --- a/addons/escoria-core/game/core-scripts/save_data/save_data.gd +++ b/addons/escoria-core/game/core-scripts/save_data/save_data.gd @@ -10,8 +10,8 @@ var settings func save_settings(p_data, p_callback): var f = File.new() - f.open("user://settings.bin", File.WRITE) - f.store_var(p_data) + f.open("user://settings.json", File.WRITE) + f.store_string(to_json(p_data)) f.close() if typeof(p_callback) != typeof(null): @@ -19,21 +19,37 @@ func save_settings(p_data, p_callback): return OK + +func check_settings(): + var f = File.new() + var error = f.open("user://settings.json", File.READ) + if !f.is_open() and error != OK: + match error: + ERR_FILE_NOT_FOUND: + f.close() + save_settings(escoria.settings_default, null) + + func load_settings(p_callback): var f = File.new() - f.open("user://settings.bin", File.READ) - if !f.is_open(): + var error = f.open("user://settings.json", File.READ) + if !f.is_open() and error != OK: + escoria.logger.report_warnings("save_data.gd:load_settings()", + ["Failed opening settings file user://settings.json.", + "File.open() returned " + error]) + if typeof(p_callback) != typeof(null): p_callback[0].call_deferred(p_callback[1], null) return FAILED - settings = f.get_var() + settings = f.get_as_text() f.close() if typeof(p_callback) != typeof(null): p_callback[0].call_deferred(p_callback[1], settings) - return OK + return settings + func _get_fname(p_slot): @@ -118,6 +134,7 @@ func load_slot(p_slot, p_callback): return OK + func load_autosave(p_callback): if p_callback == null: return FAILED diff --git a/addons/escoria-core/game/escoria.gd b/addons/escoria-core/game/escoria.gd index b40b71da..ba17d78b 100644 --- a/addons/escoria-core/game/escoria.gd +++ b/addons/escoria-core/game/escoria.gd @@ -29,6 +29,35 @@ onready var current_state = GAME_STATE.DEFAULT onready var game_size = get_viewport().size +# These are settings that the player can affect and save/load later +var settings : Dictionary +# These are default settings +var settings_default : Dictionary = { + # Text language + "text_lang": ProjectSettings.get_setting("escoria/main/text_lang"), + # Voice language + "voice_lang": ProjectSettings.get_setting("escoria/main/voice_lang"), + # Speech enabled + "speech_enabled": ProjectSettings.get_setting("escoria/sound/speech_enabled"), + # Master volume (max is 1.0) + "master_volume": ProjectSettings.get_setting("escoria/sound/master_volume"), + # Music volume (max is 1.0) + "music_volume": ProjectSettings.get_setting("escoria/sound/music_volume"), + # Sound effects volume (max is 1.0) + "sfx_volume": ProjectSettings.get_setting("escoria/sound/sfx_volume"), + # Voice volume (for speech only, max is 1.0) + "voice_volume": ProjectSettings.get_setting("escoria/sound/speech_volume"), + # Set fullscreen + "fullscreen": false, + # Allow dialog skipping + "skip_dialog": true, + # XXX: What is this? `achievements.gd` looks like iOS-only + "rate_shown": false, +} + + +func _init(): + logger = load("res://addons/escoria-core/game/core-scripts/log/logging.gd").new() ################################################################################## @@ -269,3 +298,24 @@ func ev_left_click_on_item(obj, event, default_action = false): # else: ## escoria.fallback("") # pass + +func _on_settings_loaded(p_settings : Dictionary): + escoria.logger.info("******* settings loaded", p_settings) + if p_settings != null: + settings = p_settings + else: + settings = {} + + for k in settings_default: + if !(k in settings): + settings[k] = settings_default[k] + + # TODO Apply globally +# AudioServer.set_fx_global_volume_scale(settings.sfx_volume) + AudioServer.set_bus_volume_db(AudioServer.get_bus_index("Master"), linear2db(settings.master_volume)) + AudioServer.set_bus_volume_db(AudioServer.get_bus_index("SFX"), linear2db(settings.sfx_volume)) + AudioServer.set_bus_volume_db(AudioServer.get_bus_index("Music"), linear2db(settings.music_volume)) + TranslationServer.set_locale(settings.text_lang) +# music_volume_changed() + + diff --git a/addons/escoria-core/game/escoria.tscn b/addons/escoria-core/game/escoria.tscn index 906d3798..13307273 100644 --- a/addons/escoria-core/game/escoria.tscn +++ b/addons/escoria-core/game/escoria.tscn @@ -10,9 +10,6 @@ [node name="escoria" type="Node"] script = ExtResource( 3 ) -[node name="inputs_manager" type="Node" parent="."] -script = ExtResource( 5 ) - [node name="esc_compiler" type="Node" parent="."] script = ExtResource( 6 ) @@ -22,6 +19,9 @@ script = ExtResource( 1 ) [node name="esc_level_runner" type="Node" parent="esc_runner"] script = ExtResource( 4 ) +[node name="inputs_manager" type="Node" parent="."] +script = ExtResource( 5 ) + [node name="main" parent="." instance=ExtResource( 2 )] [editable path="main"] diff --git a/addons/escoria-core/game/scenes/sound/bg_music.tscn b/addons/escoria-core/game/scenes/sound/bg_music.tscn index 38aaf480..aa496f80 100644 --- a/addons/escoria-core/game/scenes/sound/bg_music.tscn +++ b/addons/escoria-core/game/scenes/sound/bg_music.tscn @@ -14,3 +14,4 @@ __meta__ = { } [node name="AudioStreamPlayer" type="AudioStreamPlayer" parent="."] +bus = "Music" diff --git a/addons/escoria-core/game/scenes/sound/bg_sound.tscn b/addons/escoria-core/game/scenes/sound/bg_sound.tscn index 3f2214b2..69c4e820 100644 --- a/addons/escoria-core/game/scenes/sound/bg_sound.tscn +++ b/addons/escoria-core/game/scenes/sound/bg_sound.tscn @@ -14,3 +14,4 @@ __meta__ = { } [node name="AudioStreamPlayer" type="AudioStreamPlayer" parent="."] +bus = "SFX" diff --git a/default_bus_layout.tres b/default_bus_layout.tres new file mode 100644 index 00000000..2bd8efbd --- /dev/null +++ b/default_bus_layout.tres @@ -0,0 +1,21 @@ +[gd_resource type="AudioBusLayout" format=2] + +[resource] +bus/1/name = "SFX" +bus/1/solo = false +bus/1/mute = false +bus/1/bypass_fx = false +bus/1/volume_db = 0.0 +bus/1/send = "Master" +bus/2/name = "Music" +bus/2/solo = false +bus/2/mute = false +bus/2/bypass_fx = false +bus/2/volume_db = 0.0 +bus/2/send = "Master" +bus/3/name = "Dialogs" +bus/3/solo = false +bus/3/mute = false +bus/3/bypass_fx = false +bus/3/volume_db = 0.0 +bus/3/send = "Master" diff --git a/game/rooms/room1/esc/wall_item_popupdialog.esc b/game/rooms/room1/esc/wall_item_popupdialog.esc index 36bcbde0..f7f77e7e 100755 --- a/game/rooms/room1/esc/wall_item_popupdialog.esc +++ b/game/rooms/room1/esc/wall_item_popupdialog.esc @@ -1,6 +1,6 @@ :look > [! dialog_popup_advance] - say player ROOM1_look_wall_item_1"I don't know what that stuff is." dialog_box_inset + say player ROOM1_look_wall_item_1:"I don't know what that stuff is." dialog_box_inset set_global dialog_popup_advance 1 stop > [eq dialog_popup_advance 1] diff --git a/game/rooms/room9/esc/stand.esc b/game/rooms/room9/esc/stand.esc index d0fd0583..1547cb32 100755 --- a/game/rooms/room9/esc/stand.esc +++ b/game/rooms/room9/esc/stand.esc @@ -1,4 +1,6 @@ :use r9_bottle +inventory_remove r9_bottle set_state r9_stand set_bottle set_state r9_r_exit r_door_open + diff --git a/game/translations/main_menu.csv b/game/translations/main_menu.csv index de05ab5b..7ac5cfb1 100644 --- a/game/translations/main_menu.csv +++ b/game/translations/main_menu.csv @@ -5,3 +5,6 @@ OPTIONS,Options,Options QUIT,Quit,Quitter OPTIONS_BACK,Back,Retour OPTIONS_LANGUAGE,Language,Langue +GENERAL_VOLUME,General,Général +MUSIC_VOLUME,Music,Musique +SOUND_VOLUME,Sound effects,Effets sonores diff --git a/game/translations/main_menu.en.translation b/game/translations/main_menu.en.translation index c1485e99..cc3f949b 100644 Binary files a/game/translations/main_menu.en.translation and b/game/translations/main_menu.en.translation differ diff --git a/game/translations/main_menu.fr.translation b/game/translations/main_menu.fr.translation index 658f077f..3bd74e8a 100644 Binary files a/game/translations/main_menu.fr.translation and b/game/translations/main_menu.fr.translation differ diff --git a/game/ui/commons/main_menu/options.gd b/game/ui/commons/main_menu/options.gd index b5fe5c25..5429b89b 100644 --- a/game/ui/commons/main_menu/options.gd +++ b/game/ui/commons/main_menu/options.gd @@ -1,7 +1,12 @@ extends Control func _ready(): - var locale = TranslationServer.get_locale() + initialize_options(escoria.settings) + +func initialize_options(p_settings): + $options/general_volume.value = p_settings["master_volume"] + $options/sound_volume.value = p_settings["sfx_volume"] + $options/music_volume.value = p_settings["music_volume"] func greyout_other_languages(except_lang : String) -> void: pass @@ -9,3 +14,22 @@ func greyout_other_languages(except_lang : String) -> void: func _on_language_input(event : InputEvent, language : String): if event.is_pressed(): TranslationServer.set_locale(language) + escoria.settings["text_lang"] = language + escoria.esc_runner.save_data.save_settings(escoria.settings, null) + + +func _on_sound_volume_changed(value): + escoria.settings["sfx_volume"] = value + escoria.esc_runner.save_data.save_settings(escoria.settings, null) + escoria._on_settings_loaded(escoria.settings) + +func _on_music_volume_changed(value): + escoria.settings["music_volume"] = value + escoria.esc_runner.save_data.save_settings(escoria.settings, null) + escoria._on_settings_loaded(escoria.settings) + + +func _on_general_volume_changed(value): + escoria.settings["master_volume"] = value + escoria.esc_runner.save_data.save_settings(escoria.settings, null) + escoria._on_settings_loaded(escoria.settings) diff --git a/game/ui/commons/main_menu/options.tscn b/game/ui/commons/main_menu/options.tscn index b6cd2221..8af50489 100644 --- a/game/ui/commons/main_menu/options.tscn +++ b/game/ui/commons/main_menu/options.tscn @@ -24,52 +24,109 @@ __meta__ = { "_edit_use_anchors_": false } -[node name="options_grid" type="GridContainer" parent="."] -anchor_left = 0.217 -anchor_top = 0.427 -anchor_right = 0.803 -anchor_bottom = 0.574 -margin_left = 0.23999 -margin_top = -0.300018 -margin_right = 17.1599 -margin_bottom = 0.400024 -custom_constants/hseparation = 167 +[node name="options" type="GridContainer" parent="."] +anchor_left = 0.5 +anchor_top = 0.5 +anchor_right = 0.5 +anchor_bottom = 0.5 +margin_left = -275.5 +margin_top = -75.0 +margin_right = 275.5 +margin_bottom = 75.0 +custom_constants/hseparation = 40 columns = 2 __meta__ = { "_edit_use_anchors_": false } -[node name="options_language" type="Label" parent="options_grid"] -margin_top = 56.0 +[node name="label" type="Label" parent="options"] +margin_top = 27.0 margin_right = 220.0 -margin_bottom = 77.0 +margin_bottom = 48.0 custom_fonts/font = ExtResource( 1 ) text = "OPTIONS_LANGUAGE" -[node name="flags" type="HBoxContainer" parent="options_grid"] -margin_left = 387.0 -margin_right = 767.0 -margin_bottom = 133.0 +[node name="flags" type="HBoxContainer" parent="options"] +margin_left = 260.0 +margin_right = 553.0 +margin_bottom = 75.0 size_flags_vertical = 3 custom_constants/separation = 30 alignment = 1 -[node name="fr_FR" type="TextureRect" parent="options_grid/flags"] -margin_right = 150.0 -margin_bottom = 133.0 +[node name="fr" type="TextureRect" parent="options/flags"] +margin_right = 113.0 +margin_bottom = 75.0 texture = ExtResource( 3 ) __meta__ = { "_edit_use_anchors_": false } -[node name="en_EN" type="TextureRect" parent="options_grid/flags"] -margin_left = 180.0 -margin_right = 380.0 -margin_bottom = 133.0 +[node name="en" type="TextureRect" parent="options/flags"] +margin_left = 143.0 +margin_right = 293.0 +margin_bottom = 75.0 texture = ExtResource( 2 ) __meta__ = { "_edit_use_anchors_": false } -[connection signal="gui_input" from="options_grid/flags/fr_FR" to="." method="_on_language_input" binds= [ "fr_FR" ]] -[connection signal="gui_input" from="options_grid/flags/en_EN" to="." method="_on_language_input" binds= [ "en_EN" ]] +[node name="label2" type="Label" parent="options"] +margin_top = 79.0 +margin_right = 220.0 +margin_bottom = 100.0 +custom_fonts/font = ExtResource( 1 ) +text = "GENERAL_VOLUME" + +[node name="general_volume" type="HSlider" parent="options"] +margin_left = 260.0 +margin_top = 79.0 +margin_right = 553.0 +margin_bottom = 95.0 +size_flags_horizontal = 3 +min_value = 0.001 +max_value = 1.0 +step = 0.001 +value = 0.001 + +[node name="label3" type="Label" parent="options"] +margin_top = 104.0 +margin_right = 220.0 +margin_bottom = 125.0 +custom_fonts/font = ExtResource( 1 ) +text = "SOUND_VOLUME" + +[node name="sound_volume" type="HSlider" parent="options"] +margin_left = 260.0 +margin_top = 104.0 +margin_right = 553.0 +margin_bottom = 120.0 +size_flags_horizontal = 3 +min_value = 0.001 +max_value = 1.0 +step = 0.001 +value = 0.001 + +[node name="label4" type="Label" parent="options"] +margin_top = 129.0 +margin_right = 220.0 +margin_bottom = 150.0 +custom_fonts/font = ExtResource( 1 ) +text = "MUSIC_VOLUME" + +[node name="music_volume" type="HSlider" parent="options"] +margin_left = 260.0 +margin_top = 129.0 +margin_right = 553.0 +margin_bottom = 145.0 +size_flags_horizontal = 3 +min_value = 0.001 +max_value = 1.0 +step = 0.001 +value = 0.001 + +[connection signal="gui_input" from="options/flags/fr" to="." method="_on_language_input" binds= [ "fr" ]] +[connection signal="gui_input" from="options/flags/en" to="." method="_on_language_input" binds= [ "en" ]] +[connection signal="value_changed" from="options/general_volume" to="." method="_on_general_volume_changed"] +[connection signal="value_changed" from="options/sound_volume" to="." method="_on_sound_volume_changed"] +[connection signal="value_changed" from="options/music_volume" to="." method="_on_music_volume_changed"] diff --git a/game/ui/ui_mouse_icons/inventory/inventory_ui.tscn b/game/ui/ui_mouse_icons/inventory/inventory_ui.tscn index 360b2a4e..23f6f755 100644 --- a/game/ui/ui_mouse_icons/inventory/inventory_ui.tscn +++ b/game/ui/ui_mouse_icons/inventory/inventory_ui.tscn @@ -98,7 +98,7 @@ script = ExtResource( 1 ) __meta__ = { "_edit_use_anchors_": false } -items_container = NodePath("inventory_button/panel/MarginContainer/ScrollContainer/container") +inventory_ui_container = NodePath("inventory_button/panel/MarginContainer/ScrollContainer/container") [node name="ESCORIA_ALL_ITEMS" parent="." instance=ExtResource( 7 )] position = Vector2( 269.391, 275.003 ) diff --git a/project.godot b/project.godot index 117be014..5ce7e2df 100644 --- a/project.godot +++ b/project.godot @@ -64,6 +64,11 @@ _global_script_classes=[ { "language": "GDScript", "path": "res://addons/escoria-core/game/core-scripts/escroom.gd" }, { +"base": "Script", +"class": "ESCScript", +"language": "GDScript", +"path": "res://addons/escoria-core/game/core-scripts/resources/esc_script_resource.gd" +}, { "base": "Navigation2D", "class": "ESCTerrain", "language": "GDScript", @@ -91,6 +96,7 @@ _global_script_class_icons={ "ESCItem": "", "ESCPlayer": "", "ESCRoom": "", +"ESCScript": "", "ESCTerrain": "", "ESCTooltip": "", "Movable": "" @@ -138,10 +144,14 @@ ui/dialogs_folder="res://game/ui/commons/dialogs" ui/default_dialog_scene="res://game/ui/commons/dialogs/dialog_label.tscn" ui/main_menu_scene="res://game/ui/commons/main_menu/main_menu.tscn" ui/pause_menu_scene="res://game/ui/commons/pause_menu/pause_menu.tscn" -ui/game_scene="res://game/ui/ui_9verbs/game.tscn" +ui/game_scene="res://game/ui/ui_mouse_icons/game.tscn" internals/save_data="" -sound/music_volume=5 -sound/sound_volume=8 +main/text_lang="fr_FR" +main/voice_lang="fr_FR" +sound/music_volume=1 +sound/sfx_volume=1 +sound/speech_volume=1 +sound/master_volume=1 [input] @@ -159,7 +169,7 @@ switch_action_verb={ [locale] -translations=PoolStringArray( "res://game/translations/game.csv", "res://game/translations/main_menu.csv", "res://game/translations/game.en.translation", "res://game/translations/game.fr.translation", "res://game/translations/main_menu.en.translation", "res://game/translations/main_menu.fr.translation" ) +translations=PoolStringArray( "res://game/translations/game.en.translation", "res://game/translations/game.fr.translation", "res://game/translations/main_menu.en.translation", "res://game/translations/main_menu.fr.translation" ) [rendering]