aboutsummaryrefslogtreecommitdiff
path: root/game/src/ArgumentOption.gd
blob: f14cef05825397510e8497615fa5900ad8d5da23 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
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