-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: custom default config file (#175)
* feat: custom default config file refers to: #173 * Update addons/panku_console/common/config.gd Co-authored-by: worron <worrongm@gmail.com> --------- Co-authored-by: worron <worrongm@gmail.com>
- Loading branch information
Showing
3 changed files
with
157 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,37 @@ | ||
class_name PankuConfig | ||
|
||
const FILE_NAME = "panku_config.cfg" | ||
const FILE_PATH = "user://" + FILE_NAME | ||
const USER_CONFIG_FILE_PATH = "user://panku_config.cfg" | ||
|
||
# load config from file, always return a dictionary | ||
static func _get_config(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 | ||
return {} | ||
|
||
# save user config to file | ||
static func set_config(config:Dictionary): | ||
var file = FileAccess.open(FILE_PATH, FileAccess.WRITE) | ||
var file = FileAccess.open(USER_CONFIG_FILE_PATH, FileAccess.WRITE) | ||
var content = var_to_str(config) | ||
file.store_string(content) | ||
|
||
# get config, if user config exists, return user config, otherwise return default config configured by plugin user | ||
static func get_config() -> 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 | ||
return {} | ||
var user_config:Dictionary = _get_config(USER_CONFIG_FILE_PATH) | ||
if not user_config.is_empty(): | ||
return user_config | ||
# if no user config, return default config, which is read-only | ||
if PankuConsolePlugin.is_custom_default_config_exists(): | ||
return _get_config(PankuConsolePlugin.get_custom_default_config_path()) | ||
|
||
return _get_config(PankuConsolePlugin.INITIAL_DEFAULT_CONFIG_FILE_PATH) | ||
|
||
static func get_value(key:String, default:Variant) -> Variant: | ||
return get_config().get(key, default) | ||
|
||
static func set_value(key:String, val:Variant) -> void: | ||
var config = get_config() | ||
var config = _get_config(USER_CONFIG_FILE_PATH) | ||
config[key] = val | ||
set_config(config) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
{ | ||
"enable_os_window": false, | ||
"engine_tools": { | ||
"time_scale": 1.0 | ||
}, | ||
"exp_history": [], | ||
"expression_monitor": { | ||
"monitor_data": [{ | ||
"expressions": ["engine_tools.get_performance_info()"], | ||
"group_name": "default group" | ||
}], | ||
"window_position": Vector2(0, 49), | ||
"window_size": Vector2(85, 74), | ||
"window_visibility": false | ||
}, | ||
"general_settings": { | ||
"enable_os_window": false, | ||
"lynx_window_base_color": Color(0, 0.0470588, 0.0941176, 0.501961), | ||
"lynx_window_blur_effect": true, | ||
"lynx_window_enable_os_window": false, | ||
"lynx_window_os_window_bg_color": Color(0, 0, 0, 0.658824), | ||
"os_window_bg_color": Color(0, 0, 0, 0.992157), | ||
"window_blur_effect": true, | ||
"window_position": Vector2(429.546, 94.1911), | ||
"window_size": Vector2(512.568, 478.128), | ||
"window_visibility": true | ||
}, | ||
"history_manager": { | ||
"window_position": Vector2(317.728, 138.82), | ||
"window_size": Vector2(411.987, 339.537), | ||
"window_visibility": false | ||
}, | ||
"interactive_shell": { | ||
"gui_mode": 0, | ||
"histories": [], | ||
"init_expr": "", | ||
"output_font_size": 14.0, | ||
"pause_if_input": false, | ||
"pause_if_popup": false, | ||
"show_side_menu": true, | ||
"unified_visibility": false, | ||
"unified_window_visibility": false, | ||
"window_position": Vector2(427.419, 75.3913), | ||
"window_size": Vector2(510.736, 410.437), | ||
"window_visibility": true | ||
}, | ||
"keyboard_shortcuts": { | ||
"key_mapper": [], | ||
"window_position": Vector2(0, 49), | ||
"window_size": Vector2(85, 74), | ||
"window_visibility": false | ||
}, | ||
"native_logger": { | ||
"font_size": 17.0, | ||
"logger_tags": ["[error]", "[warning]", "[info]"], | ||
"screen_overlay": 0, | ||
"screen_overlay_alpha": 0.44, | ||
"screen_overlay_font_shadow": true, | ||
"screen_overlay_font_size": 20.0, | ||
"show_timestamp": true, | ||
"window_position": Vector2(284.123, 124.547), | ||
"window_size": Vector2(483.998, 379.028), | ||
"window_visibility": false | ||
}, | ||
"os_window_bg_color": Color(0, 0, 0, 0.992157), | ||
"os_window_bgcolor": Color(0, 0, 0, 0.658824), | ||
"snake": { | ||
"leader_board": [{ | ||
"score": 40, | ||
"timestamp": "2024-01-29T16:00:00" | ||
}, { | ||
"score": 20, | ||
"timestamp": "2024-01-29T16:01:14" | ||
}] | ||
}, | ||
"variable_tracker": { | ||
"tracking_delay": 0.5, | ||
"use_last_as_current": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters