signalis-eb/godot/addons/utils/utils.gd
2025-06-12 00:32:17 -04:00

28 lines
938 B
GDScript

class_name Utils
static func get_class_name(value: Object) -> String:
match value.get_script():
var script:
match script.get_global_name():
var name: return name
_: return script.get_instance_base_type()
_: return value.get_class()
static func is_string_like(value: Variant) -> bool:
match typeof(value):
TYPE_STRING: return true
TYPE_STRING_NAME: return true
TYPE_NODE_PATH: return true
_: return false
static func to_str(value: Variant) -> String:
match typeof(value):
TYPE_OBJECT:
if value.has_method('_to_string'):
return value.to_string()
else:
var name = get_class_name(value)
value = value as Object
var props: Dictionary = inst_to_dict(value)
return "%s %s" % [name, to_str(props)]
_: return str(value)