aboutsummaryrefslogtreecommitdiff
path: root/game/src/ArgumentOption.gd
diff options
context:
space:
mode:
author George L. Albany <Megacake1234@gmail.com>2023-05-02 06:30:06 +0200
committer GitHub <noreply@github.com>2023-05-02 06:30:06 +0200
commitbe43b260128664756054a289cf9d22319def1f8a (patch)
tree56006651b7228d817b5ab9ec87bb71dd408cc5d1 /game/src/ArgumentOption.gd
parent4a6965515afe26888d1f1eb9248e74a2bcb38afc (diff)
parent865e7aeca7c3090fee914b9ebde9490ef23d3559 (diff)
Merge pull request #102 from Spartan322/refine/argument-parsing
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