diff --git a/.gitignore b/.gitignore index ef7e643..25081c6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ # Godot 4+ specific ignores .godot/ - +# misc export/ - -test/ \ No newline at end of file +test/ +.vscode/ +addons/lua-gdextension/ \ No newline at end of file diff --git a/addons/panku_console/common/config.gd b/addons/panku_console/common/config.gd index da77124..39b97d4 100644 --- a/addons/panku_console/common/config.gd +++ b/addons/panku_console/common/config.gd @@ -8,8 +8,12 @@ const OPTIONS = { CUSTOM_DEFAULT_CONFIG = 'custom_default_config', } -const INITIAL_DEFAULT_CONFIG_FILE_PATH = "res://addons/panku_console/default_panku_config.cfg" -const USER_CONFIG_FILE_PATH = "user://panku_config.cfg" +const INITIAL_DEFAULT_CONFIG_FILE_PATH = "res://addons/panku_console/default_panku_config.tres" +const USER_CONFIG_FILE_PATH = "user://panku_config.tres" +const SAVE_DELAY := 0.2 + +static var _cfg:Dictionary = {} +static var _timer:SceneTreeTimer # Get custom config file path from project settings static func get_custom_default_config_path() -> String: @@ -26,35 +30,49 @@ static func panku_option(option: String) -> String: # load config from file, always return a dictionary -static func _get_config(file_path:String) -> Dictionary: +static func _load_config_file(file_path:String) -> Dictionary: if FileAccess.file_exists(file_path): - var file = FileAccess.open(file_path, FileAccess.READ) - var content := file.get_as_text() - var config:Dictionary = str_to_var(content) - if config: return config + var res := load(file_path) as PankuConsoleSimpleRes + if res == null: return {} + return res.data return {} -# save user config to file -static func set_config(config:Dictionary): - var file = FileAccess.open(USER_CONFIG_FILE_PATH, FileAccess.WRITE) - var content = var_to_str(config) - file.store_string(content) +# save user config to file with a time delay +static func save_config_with_delay() -> void: + if _timer: _timer.timeout.disconnect(save_config_immediately) + _timer = (Engine.get_main_loop() as SceneTree).create_timer(SAVE_DELAY, true, false, true) + _timer.timeout.connect(save_config_immediately) + +static func save_config_immediately() -> void: + var res := PankuConsoleSimpleRes.new() + res.data = _cfg + var status = ResourceSaver.save(res, USER_CONFIG_FILE_PATH) + if status != OK: push_error("Failed to save panku config.") + # print("Saved to ", USER_CONFIG_FILE_PATH) # get config, if user config exists, return user config, otherwise return default config configured by plugin user -static func get_config() -> Dictionary: - var user_config:Dictionary = _get_config(USER_CONFIG_FILE_PATH) +static func _get_config() -> Dictionary: + if not _cfg.is_empty(): return _cfg + var user_config:Dictionary = _load_config_file(USER_CONFIG_FILE_PATH) if not user_config.is_empty(): - return user_config + _cfg = user_config # if no user config, return default config, which is read-only - if is_custom_default_config_exists(): - return _get_config(get_custom_default_config_path()) - - return _get_config(INITIAL_DEFAULT_CONFIG_FILE_PATH) + elif is_custom_default_config_exists(): + _cfg = _load_config_file(get_custom_default_config_path()) + else: + _cfg = _load_config_file(INITIAL_DEFAULT_CONFIG_FILE_PATH) + return _cfg -static func get_value(key:String, default:Variant) -> Variant: - return get_config().get(key, default) +static func _get_key(keys:Array[String]) -> String: + return ".".join(keys) + +static func get_value(keys:Array[String], default:Variant = null) -> Variant: + var key := _get_key(keys) + var cfg := _get_config() + return cfg.get(key, default) -static func set_value(key:String, val:Variant) -> void: - var config = _get_config(USER_CONFIG_FILE_PATH) - config[key] = val - set_config(config) +static func set_value(keys:Array[String], val:Variant) -> void: + var key := _get_key(keys) + var cfg := _get_config() + cfg[key] = val + save_config_with_delay() diff --git a/addons/panku_console/common/lynx_window2/lynx_windows_manager_2.gd b/addons/panku_console/common/lynx_window2/lynx_windows_manager_2.gd index 3298c43..7847876 100644 --- a/addons/panku_console/common/lynx_window2/lynx_windows_manager_2.gd +++ b/addons/panku_console/common/lynx_window2/lynx_windows_manager_2.gd @@ -64,15 +64,12 @@ func get_os_window_bg_color() -> Color: return os_window_bg_color func save_data(): - var cfg = PankuConfig.get_config() - cfg[CFG_ENABLE_OS_WINDOW] = os_popup_btn_enabled - cfg[CFG_OS_WINDOW_BGCOLOR] = os_window_bg_color - PankuConfig.set_config(cfg) + PankuConfig.set_value(CFG_ENABLE_OS_WINDOW, os_popup_btn_enabled) + PankuConfig.set_value(CFG_OS_WINDOW_BGCOLOR, os_window_bg_color) func load_data(): - var cfg = PankuConfig.get_config() - enable_os_popup_btns(cfg.get(CFG_ENABLE_OS_WINDOW, false)) - set_os_window_bg_color(cfg.get(CFG_OS_WINDOW_BGCOLOR, Color("#2b2e32"))) + enable_os_popup_btns(PankuConfig.get_value(CFG_ENABLE_OS_WINDOW, false)) + set_os_window_bg_color(PankuConfig.get_value(CFG_OS_WINDOW_BGCOLOR, Color("#2b2e32"))) func _notification(what): #quit event diff --git a/addons/panku_console/common/panku_module.gd b/addons/panku_console/common/panku_module.gd index 4ef3188..75e028c 100644 --- a/addons/panku_console/common/panku_module.gd +++ b/addons/panku_console/common/panku_module.gd @@ -24,23 +24,19 @@ func update_module(delta:float): pass func save_module_data(key:String, value:Variant): - var cfg:Dictionary = PankuConfig.get_config() var module_name:String = get_module_name() - if !cfg.has(module_name): - cfg[module_name] = {} - cfg[module_name][key] = value - PankuConfig.set_config(cfg) + var module_data:Dictionary = PankuConfig.get_value(module_name, {}) + module_data[key] = value + PankuConfig.set_value(module_name, module_data) func load_module_data(key:String, default_value:Variant = null) -> Variant: - var cfg:Dictionary = PankuConfig.get_config() var module_name:String = get_module_name() - var module_data = cfg.get(module_name, {}) + var module_data = PankuConfig.get_value(module_name, {}) return module_data.get(key, default_value) func has_module_data(key:String) -> bool: - var cfg:Dictionary = PankuConfig.get_config() var module_name:String = get_module_name() - var module_data = cfg.get(module_name, {}) + var module_data = PankuConfig.get_value(module_name, {}) return module_data.has(key) func load_window_data(window:PankuLynxWindow): diff --git a/addons/panku_console/console.gd b/addons/panku_console/console.gd index cf4ce19..3f70cbb 100644 --- a/addons/panku_console/console.gd +++ b/addons/panku_console/console.gd @@ -76,3 +76,4 @@ func _notification(what): # quit event if what == NOTIFICATION_WM_CLOSE_REQUEST: module_manager.quit_modules() + PankuConfig.save_config_immediately() diff --git a/addons/panku_console/default_panku_config.tres b/addons/panku_console/default_panku_config.tres new file mode 100644 index 0000000..b342284 --- /dev/null +++ b/addons/panku_console/default_panku_config.tres @@ -0,0 +1,76 @@ +[gd_resource type="Resource" script_class="PankuConsoleSimpleRes" load_steps=2 format=3 uid="uid://carjqi7cx353a"] + +[ext_resource type="Script" path="res://addons/panku_console/dict_res.gd" id="1_8qd6x"] + +[resource] +script = ExtResource("1_8qd6x") +data = { +"enable_os_window": false, +"engine_tools": { +"time_scale": "1" +}, +"engine_tools.time_scale": "1", +"exp_history": [[false, false, "print('Panku Console Loaded!')"]], +"expression_monitor.monitor_data": [{ +"expressions": [], +"group_name": "default group" +}], +"expression_monitor.window_position": Vector2(433.5, 415), +"expression_monitor.window_size": Vector2(413, 305), +"expression_monitor.window_visibility": false, +"general_settings": { +"window_blur_effect": true, +"window_position": Vector2(213.215, 75.1716), +"window_size": Vector2(709.046, 563.371), +"window_visibility": true +}, +"general_settings.global_font_size": 14, +"general_settings.window_blur_effect": true, +"general_settings.window_position": Vector2(584.001, 161.779), +"general_settings.window_size": Vector2(555.042, 397.87), +"general_settings.window_visibility": true, +"history_manager.window_position": Vector2(867, 415), +"history_manager.window_size": Vector2(413, 305), +"history_manager.window_visibility": false, +"interactive_shell": { +"pause_if_popup": true, +"show_side_menu": true, +"unified_visibility": false +}, +"interactive_shell.gui_mode": 0, +"interactive_shell.histories": [], +"interactive_shell.pause_if_popup": true, +"interactive_shell.show_side_menu": true, +"interactive_shell.unified_visibility": true, +"interactive_shell.window_position": Vector2(255.736, 71.0109), +"interactive_shell.window_size": Vector2(615.07, 443.081), +"interactive_shell.window_visibility": true, +"keyboard_shortcuts": { +"window_position": Vector2(617.943, 228.155), +"window_size": Vector2(412.999, 305) +}, +"keyboard_shortcuts.key_mapper": [], +"keyboard_shortcuts.window_position": Vector2(867, 0), +"keyboard_shortcuts.window_size": Vector2(413, 305), +"keyboard_shortcuts.window_visibility": false, +"native_logger": { +"screen_overlay": 0, +"screen_overlay_alpha": 1.0, +"screen_overlay_font_shadow": true, +"screen_overlay_override_font_size": 14, +"show_timestamp": true +}, +"native_logger.logger_tags": ["[error]", "[warning]"], +"native_logger.screen_overlay_alpha": 0.13, +"native_logger.screen_overlay_font_shadow": true, +"native_logger.screen_overlay_override_font_size": 9, +"native_logger.show_timestamp": true, +"native_logger.window_position": Vector2(314.725, 167.815), +"native_logger.window_size": Vector2(481.089, 317.56), +"native_logger.window_visibility": false, +"os_window_bg_color": Color(0.129412, 0.14902, 0.180392, 1), +"variable_tracker": { +"tracking_delay": 0.5, +"use_last_as_current": true +} +} diff --git a/addons/panku_console/dict_res.gd b/addons/panku_console/dict_res.gd new file mode 100644 index 0000000..20d5150 --- /dev/null +++ b/addons/panku_console/dict_res.gd @@ -0,0 +1,3 @@ +class_name PankuConsoleSimpleRes +extends Resource +@export var data := {} diff --git a/addons/panku_console/modules/data_controller/exporter/exporter_2.gd b/addons/panku_console/modules/data_controller/exporter/exporter_2.gd index 05106cd..46102f3 100644 --- a/addons/panku_console/modules/data_controller/exporter/exporter_2.gd +++ b/addons/panku_console/modules/data_controller/exporter/exporter_2.gd @@ -138,6 +138,7 @@ func init_data(): if !is_instance_valid(obj): return if prop_name in obj: + # used to auto save settings panel data if obj.has_method("update_setting"): obj.update_setting(prop_name, val) else: diff --git a/addons/panku_console/modules/engine_tools/opt.gd b/addons/panku_console/modules/engine_tools/opt.gd index 2964957..a789a3a 100644 --- a/addons/panku_console/modules/engine_tools/opt.gd +++ b/addons/panku_console/modules/engine_tools/opt.gd @@ -27,7 +27,7 @@ func toggle_2d_debug_draw(): func reload_current_scene(): _module.reload_current_scene() -@export_range(0.1, 2.0) var time_scale := 1.0: +@export_range(0.1, 10.0, 0.001) var time_scale := 1.0: set(v): time_scale = v _module.set_time_scale(time_scale) diff --git a/addons/panku_console/modules/history_manager/exp_history.gd b/addons/panku_console/modules/history_manager/exp_history.gd index 8d4b469..18f48c2 100644 --- a/addons/panku_console/modules/history_manager/exp_history.gd +++ b/addons/panku_console/modules/history_manager/exp_history.gd @@ -185,14 +185,10 @@ func remove_selected(): reload() func load_data(): - #get saved data from cfg - var cfg = PankuConfig.get_config() - item_data = cfg.get(CFG_EXP_HISTORY, []) + item_data = PankuConfig.get_value(CFG_EXP_HISTORY, []) func save_data(): - var cfg = PankuConfig.get_config() - cfg[CFG_EXP_HISTORY] = item_data - PankuConfig.set_config(cfg) + PankuConfig.set_value(CFG_EXP_HISTORY, item_data) func _notification(what): if what == NOTIFICATION_WM_CLOSE_REQUEST: diff --git a/project.godot b/project.godot index 3d5c53d..1350156 100644 --- a/project.godot +++ b/project.godot @@ -15,7 +15,7 @@ config/description="**Panku Console is a feature-packed real-time debugging tool Panku Console is designed to be modular and extensible, and it is easy to add and maintain features. It is also designed to be as unobtrusive as possible, so you can use it in your project without worrying about the impact on the final product." run/main_scene="res://example/main.tscn" -config/features=PackedStringArray("4.2", "Forward Plus") +config/features=PackedStringArray("4.3", "Forward Plus") boot_splash/bg_color=Color(1, 1, 1, 1) boot_splash/image="res://example/assets/bootsplash.png" boot_splash/fullsize=false