2021-08-21 17:13:21 +02:00

93 lines
1.9 KiB
GDScript

extends Reference
class_name GDB_Property
# special types
const TYPE_HEADER = -1
var _name := ""
var _icon : Texture = null
var _value = null
var _type := TYPE_INT
################
# overridables #
################
func get_name() -> String:
return _name
func set_name(name : String) -> void:
if _name != name:
_name = name
emit_signal("name_changed")
func get_icon() -> Texture:
return _icon
func set_icon(icon : Texture) -> void:
if _icon != icon:
_icon = icon
emit_signal("icon_changed")
func get_value():
return _value
func set_value(value) -> void:
if value != _value:
_value = value
emit_signal("value_changed")
func get_type() -> int:
return _type
func set_type(type : int) -> void:
if type != _type:
_type = type
emit_signal("type_changed")
################
# static stuff #
################
static func is_valid_property(object : Object) -> bool:
return object != null \
&& object.has_method("get_name") \
&& object.has_method("get_value") \
&& object.has_method("get_type")
static func get_prop_icon(property : Object) -> Texture:
var icon : Texture = null
if property.has_method("get_icon"):
icon = property.get_icon() as Texture
else:
icon = property.get("icon") as Texture
return icon
static func is_prop_value_valid(property : Object, value) -> bool:
if property.has_method("is_value_valud"):
return property.is_value_valid(value)
match property.get_type():
TYPE_HEADER:
return false
TYPE_INT:
return value is int
TYPE_REAL:
return value is float
TYPE_STRING:
return value is String
_: # TODO: more default checks
return true
static func get_prop_value_as_string(property : Object) -> String:
if property.has_method("get_value_as_string"):
return property.get_value_as_string()
return str(property.get_value())
###########
# signals #
###########
signal name_changed()
signal icon_changed()
signal value_changed()
signal type_changed()