start command line setup
This commit is contained in:
43
scripts/cmd.gd
Normal file
43
scripts/cmd.gd
Normal file
@ -0,0 +1,43 @@
|
||||
class_name CMD
|
||||
|
||||
## Returns a dictionary of all arguments passed after `--` on the command line
|
||||
## arguments take one of 2 forms:
|
||||
## - `--arg` which is a boolean (using `--no-arg` for `false` is possible)
|
||||
## - `--arg=value`. If the value is quoted with `"` or `'`, this function will
|
||||
## unsurround the string
|
||||
## This function does no evaluation and does not attempt to guess the type of
|
||||
## arguments. You will receive either bools, or strings.
|
||||
var command_line_arguments: Dictionary = (func get_command_line_arguments() -> Dictionary:
|
||||
var unsurround := func unsurround(value: String, quotes := PackedStringArray(['"', "'"])) -> String:
|
||||
for quote_str in quotes:
|
||||
if value.begins_with(quote_str) \
|
||||
and value.ends_with(quote_str) \
|
||||
and value[value.length() - 2] != "\\":
|
||||
return value.trim_prefix(quote_str).trim_suffix(quote_str).strip_edges()
|
||||
return value
|
||||
var arguments := {}
|
||||
for argument in OS.get_cmdline_user_args():
|
||||
argument = argument.lstrip("--").to_lower()
|
||||
if argument.find("=") > -1:
|
||||
var arg_tuple := argument.split("=")
|
||||
var key := arg_tuple[0]
|
||||
var value:String = unsurround.call(arg_tuple[1])
|
||||
arguments[key] = value
|
||||
else:
|
||||
var key := argument
|
||||
var value := true
|
||||
if argument.begins_with("no-"):
|
||||
value = false
|
||||
key = argument.lstrip("no-")
|
||||
arguments[key] = value
|
||||
return arguments).call()
|
||||
|
||||
|
||||
func get_argument(name: String, default: Variant = null) -> Variant:
|
||||
if command_line_arguments.has(name):
|
||||
return command_line_arguments[name]
|
||||
return default
|
||||
|
||||
|
||||
func has_argument(name: String) -> bool:
|
||||
return command_line_arguments.has(name)
|
51
scripts/config_manager.gd
Normal file
51
scripts/config_manager.gd
Normal file
@ -0,0 +1,51 @@
|
||||
class_name ConfigManager extends Resource
|
||||
|
||||
|
||||
const CONFIG_PATH := "user://settings.cfg"
|
||||
var _config := ConfigFile.new()
|
||||
|
||||
|
||||
var current_file: String = "":
|
||||
set(value):
|
||||
current_file = value
|
||||
_config.set_value("MAIN", "file", value)
|
||||
save()
|
||||
get:
|
||||
var _default_path := OS.get_system_dir(OS.SYSTEM_DIR_DOCUMENTS, true).path_join("mouse_timer.csv")
|
||||
return _config.get_value("MAIN", "file", _default_path)
|
||||
|
||||
|
||||
var theme_path: String = "":
|
||||
set(value):
|
||||
theme_path = value
|
||||
_config.set_value("MAIN", "theme", value)
|
||||
save()
|
||||
get:
|
||||
return _config.get_value("MAIN", "theme", preload("res://assets/default_theme.theme").resource_path)
|
||||
|
||||
|
||||
var last_task_name: String = "":
|
||||
set(value):
|
||||
last_task_name = value
|
||||
_config.set_value("MAIN", "last_task_name", value)
|
||||
save()
|
||||
get:
|
||||
return _config.get_value("MAIN", "last_task_name", "")
|
||||
|
||||
|
||||
var sound_fx_on: bool = true:
|
||||
set(value):
|
||||
sound_fx_on = value
|
||||
_config.set_value("MAIN", "sound_fx_on", value)
|
||||
save()
|
||||
get:
|
||||
return _config.get_value("MAIN", "sound_fx", true)
|
||||
|
||||
|
||||
|
||||
func _init() -> void:
|
||||
_config.load(CONFIG_PATH)
|
||||
|
||||
|
||||
func save() -> void:
|
||||
_config.save(CONFIG_PATH)
|
Reference in New Issue
Block a user