From 2179b803e074fa6209e3c9105cfb659fcb5babd3 Mon Sep 17 00:00:00 2001 From: Julian Murgia Date: Thu, 13 Jan 2022 11:09:06 +0100 Subject: [PATCH] Implement custom data save in settings and savegames (#484) --- addons/escoria-core/default_bus_layout.tres | 2 +- .../escoria-core/game/core-scripts/esc_game.gd | 14 ++++++++++++++ .../core-scripts/save_data/esc_save_manager.gd | 3 +++ .../game/core-scripts/save_data/esc_savegame.gd | 3 +++ .../core-scripts/save_data/esc_savesettings.gd | 3 +++ addons/escoria-core/game/escoria.gd | 2 ++ addons/escoria-core/plugin.gd | 1 + .../ui_library/menus/options/options.gd | 1 + addons/escoria-ui-9verbs/game.gd | 16 ++++++++++++++++ addons/escoria-ui-simplemouse/game.gd | 16 ++++++++++++++++ project.godot | 8 +------- 11 files changed, 61 insertions(+), 8 deletions(-) diff --git a/addons/escoria-core/default_bus_layout.tres b/addons/escoria-core/default_bus_layout.tres index 196e4fec..da0bf499 100644 --- a/addons/escoria-core/default_bus_layout.tres +++ b/addons/escoria-core/default_bus_layout.tres @@ -11,7 +11,7 @@ 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/volume_db = -60.0 bus/2/send = "Master" bus/3/name = "Speech" bus/3/solo = false diff --git a/addons/escoria-core/game/core-scripts/esc_game.gd b/addons/escoria-core/game/core-scripts/esc_game.gd index 598ff6fd..e5094336 100644 --- a/addons/escoria-core/game/core-scripts/esc_game.gd +++ b/addons/escoria-core/game/core-scripts/esc_game.gd @@ -282,6 +282,20 @@ func hide_main_menu(): pass +# Custom function that is meant to apply custom settings. Called right after +# Escoria settings file was loaded. +func apply_custom_settings(custom_settings: Dictionary): + pass + + +# Custom function automatically called when save game is created. +# +# *Returns* A Dictionary containing the custom data to be saved within the +# game file. +func get_custom_data() -> Dictionary: + return {} + + # Shows the crash popup when a crash occurs # # #### Parameters 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 bd070aa0..e64d4ca1 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 @@ -154,6 +154,8 @@ func _do_save_game(p_savename: String) -> ESCSaveGame: escoria.globals_manager.save_game(save_game) escoria.object_manager.save_game(save_game) escoria.main.save_game(save_game) + save_game.custom_data = escoria.game_scene.get_custom_data() + return save_game @@ -323,6 +325,7 @@ func save_settings(): settings_res.speech_volume = escoria.settings.speech_volume settings_res.fullscreen = escoria.settings.fullscreen settings_res.skip_dialog = escoria.settings.skip_dialog + settings_res.custom_settings = escoria.settings.custom_settings var directory: Directory = Directory.new() if not directory.dir_exists(settings_folder): diff --git a/addons/escoria-core/game/core-scripts/save_data/esc_savegame.gd b/addons/escoria-core/game/core-scripts/save_data/esc_savegame.gd index 72851485..278b5b67 100644 --- a/addons/escoria-core/game/core-scripts/save_data/esc_savegame.gd +++ b/addons/escoria-core/game/core-scripts/save_data/esc_savegame.gd @@ -27,3 +27,6 @@ export var globals: Dictionary = {} # Escoria objects exported from ESCObjectsManager export var objects: Dictionary = {} + +# Custom data +export var custom_data: Dictionary = {} diff --git a/addons/escoria-core/game/core-scripts/save_data/esc_savesettings.gd b/addons/escoria-core/game/core-scripts/save_data/esc_savesettings.gd index db7eccff..56fb3a83 100644 --- a/addons/escoria-core/game/core-scripts/save_data/esc_savesettings.gd +++ b/addons/escoria-core/game/core-scripts/save_data/esc_savesettings.gd @@ -41,3 +41,6 @@ export var fullscreen: bool = false # True if skipping dialogs is allowed export var skip_dialog: bool = true + +# Dictionary containing all user-defined settings. +export var custom_settings: Dictionary diff --git a/addons/escoria-core/game/escoria.gd b/addons/escoria-core/game/escoria.gd index 0ffad38b..06044896 100644 --- a/addons/escoria-core/game/escoria.gd +++ b/addons/escoria-core/game/escoria.gd @@ -306,6 +306,8 @@ func apply_settings(p_settings: ESCSaveSettings) -> void: linear2db(settings.speech_volume) ) TranslationServer.set_locale(settings.text_lang) + + game_scene.apply_custom_settings(settings.custom_settings) # Input function to manage specific input keys diff --git a/addons/escoria-core/plugin.gd b/addons/escoria-core/plugin.gd index 20425918..19ba966b 100644 --- a/addons/escoria-core/plugin.gd +++ b/addons/escoria-core/plugin.gd @@ -33,6 +33,7 @@ func _ready(): set_escoria_ui_settings() set_escoria_sound_settings() set_escoria_platform_settings() + ProjectSettings.save() # Prepare the settings in the Escoria UI category diff --git a/addons/escoria-core/ui_library/menus/options/options.gd b/addons/escoria-core/ui_library/menus/options/options.gd index 16055809..52b13b3d 100644 --- a/addons/escoria-core/ui_library/menus/options/options.gd +++ b/addons/escoria-core/ui_library/menus/options/options.gd @@ -112,6 +112,7 @@ func _on_speech_volume_value_changed(value: float) -> void: # Save the settings func _on_apply_pressed(): + escoria.settings.custom_settings["a_custom_setting"] = 100 escoria.save_manager.save_settings() settings_changed = false emit_signal("back_button_pressed") diff --git a/addons/escoria-ui-9verbs/game.gd b/addons/escoria-ui-9verbs/game.gd index beffaef8..209b1cb2 100644 --- a/addons/escoria-ui-9verbs/game.gd +++ b/addons/escoria-ui-9verbs/game.gd @@ -32,6 +32,8 @@ Implement methods to react to inputs. - show_main_menu() - hide_main_menu() +- apply_custom_settings() + - _on_event_done(event_name: String) """ @@ -340,3 +342,17 @@ func _on_MenuButton_pressed() -> void: func _on_action_finished() -> void: verbs_menu.unselect_actions() tooltip.clear() + + +func apply_custom_settings(custom_settings: Dictionary): + if custom_settings.has("a_custom_setting"): + escoria.logger.info( + "custom setting value loaded:", + [custom_settings["a_custom_setting"]] + ) + + +func get_custom_data() -> Dictionary: + return { + "ui_type": "9verbs" + } diff --git a/addons/escoria-ui-simplemouse/game.gd b/addons/escoria-ui-simplemouse/game.gd index 8069d219..d254117e 100644 --- a/addons/escoria-ui-simplemouse/game.gd +++ b/addons/escoria-ui-simplemouse/game.gd @@ -32,6 +32,8 @@ Implement methods to react to inputs. - show_main_menu() - hide_main_menu() +- apply_custom_settings() + - _on_event_done(event_name: String) """ @@ -211,6 +213,20 @@ func pause_game(): escoria.main.current_scene.hide() +func apply_custom_settings(custom_settings: Dictionary): + if custom_settings.has("a_custom_setting"): + escoria.logger.info( + "custom setting value loaded:", + [custom_settings["a_custom_setting"]] + ) + + +func get_custom_data() -> Dictionary: + return { + "ui_type": "simplemouse" + } + + # Update the tooltip # # #### Parameters diff --git a/project.godot b/project.godot index 0363f949..fb9b2a9d 100644 --- a/project.godot +++ b/project.godot @@ -144,11 +144,6 @@ _global_script_classes=[ { "language": "GDScript", "path": "res://addons/escoria-core/game/core-scripts/esc/types/esc_condition.gd" }, { -"base": "Reference", -"class": "ESCController", -"language": "GDScript", -"path": "res://addons/escoria-core/game/core-scripts/esc_controller.gd" -}, { "base": "ESCStatement", "class": "ESCDialog", "language": "GDScript", @@ -587,7 +582,6 @@ _global_script_class_icons={ "ESCCommandRegistry": "", "ESCCompiler": "", "ESCCondition": "", -"ESCController": "", "ESCDialog": "", "ESCDialogManager": "", "ESCDialogOption": "", @@ -756,7 +750,7 @@ main/game_migration_path="" esc_show_debug_prompt={ "deadzone": 0.5, -"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777245,"unicode":0,"echo":false,"script":null) +"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777245,"physical_scancode":0,"unicode":0,"echo":false,"script":null) ] } switch_action_verb={