Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Godot 4+ specific ignores
.godot/

# misc
export/

test/
test/
.vscode/
addons/lua-gdextension/
68 changes: 43 additions & 25 deletions addons/panku_console/common/config.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe we need to change file extension hint here too.

Also, do we need to keep default_panku_config.cfg file in project or may be we can delete it within this pull request?

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:
Expand All @@ -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)
Comment on lines +66 to +75
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This cause many errors for me, since every PankuConfig.set_value/PankuConfig.get_value I can see have String as first argument, not array. I miss the point why key array and join used here.

Seems it works fine with key-value args

static func get_value(key: String, default:Variant = null) -> Variant:
	var cfg := _get_config()
	return cfg.get(key, default)

static func set_value(key: String, val:Variant) -> void:
	var cfg := _get_config()
	cfg[key] = val
	save_config_with_delay()

var cfg := _get_config()
cfg[key] = val
save_config_with_delay()
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 5 additions & 9 deletions addons/panku_console/common/panku_module.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
1 change: 1 addition & 0 deletions addons/panku_console/console.gd
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,4 @@ func _notification(what):
# quit event
if what == NOTIFICATION_WM_CLOSE_REQUEST:
module_manager.quit_modules()
PankuConfig.save_config_immediately()
76 changes: 76 additions & 0 deletions addons/panku_console/default_panku_config.tres
Original file line number Diff line number Diff line change
@@ -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",
Comment on lines +9 to +12
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is not it some kind of duplication? Which dictionary structure was originally planned: nested or plain with joined keys?

"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
}
}
3 changes: 3 additions & 0 deletions addons/panku_console/dict_res.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class_name PankuConsoleSimpleRes
extends Resource
@export var data := {}
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion addons/panku_console/modules/engine_tools/opt.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 2 additions & 6 deletions addons/panku_console/modules/history_manager/exp_history.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down