aboutsummaryrefslogtreecommitdiff
path: root/game/src/ArgumentOption.gd
diff options
context:
space:
mode:
author Spartan322 <Megacake1234@gmail.com>2023-04-29 08:49:48 +0200
committer Spartan322 <Megacake1234@gmail.com>2023-05-02 01:00:09 +0200
commit865e7aeca7c3090fee914b9ebde9490ef23d3559 (patch)
tree7836ab6e2e5bd751c226d86646883f8424577a7c /game/src/ArgumentOption.gd
parent10053cf259c55ee45803268a844edf1011d8a16b (diff)
Add ArgumentParser
Streamlines parsing of commandline arguments Arguments reside in ProjectSettings as `openvic2/data/arguments` as a dictionary The dictionary's key is the option name The dictionary is set with default values This enables project setting overrides for arguments (user specified arguments take priority) Add help commandline option Prepare for removal of GameDebug.gd Add game project description
Diffstat (limited to 'game/src/ArgumentOption.gd')
-rw-r--r--game/src/ArgumentOption.gd60
1 files changed, 60 insertions, 0 deletions
diff --git a/game/src/ArgumentOption.gd b/game/src/ArgumentOption.gd
new file mode 100644
index 0000000..f14cef0
--- /dev/null
+++ b/game/src/ArgumentOption.gd
@@ -0,0 +1,60 @@
+@tool
+class_name ArgumentOption
+extends Resource
+
+@export var name : StringName
+@export var aliases : Array[StringName] = []
+@export var type : Variant.Type :
+ get: return type
+ set(v):
+ type = v
+ match v:
+ TYPE_BOOL: default_value = false
+ TYPE_INT: default_value = 0
+ TYPE_FLOAT: default_value = 0.0
+ TYPE_STRING: default_value = ""
+ TYPE_STRING_NAME: default_value = &""
+ TYPE_COLOR: default_value = Color()
+ _: default_value = null
+ notify_property_list_changed()
+var default_value
+@export var description : String
+
+func _init(_name = "", _type = TYPE_NIL, _description = "", default = null):
+ name = _name
+ type = _type
+ if default != null and typeof(default) == type:
+ default_value = default
+ description = _description
+
+func add_alias(alias : StringName) -> ArgumentOption:
+ aliases.append(alias)
+ return self
+
+func get_type_string() -> StringName:
+ match type:
+ TYPE_NIL: return "null"
+ TYPE_BOOL: return "boolean"
+ TYPE_INT: return "integer"
+ TYPE_FLOAT: return "float"
+ TYPE_STRING, TYPE_STRING_NAME: return "string"
+ TYPE_COLOR: return "color"
+ return "<invalid type>"
+
+func _get(property):
+ if property == "default_value": return default_value
+
+func _set(property, value):
+ if property == "default_value":
+ default_value = value
+ return true
+
+func _get_property_list():
+ var properties := []
+
+ properties.append({
+ "name": "default_value",
+ "type": type
+ })
+
+ return properties