godot-xterm/addons/gut/inner_class_registry.gd

71 lines
1.5 KiB
GDScript
Raw Normal View History

var _registry = {}
func _create_reg_entry(base_path, subpath):
var to_return = {
2023-01-20 23:34:39 +01:00
"base_path": base_path,
"subpath": subpath,
"base_resource": load(base_path),
"full_path": str("'", base_path, "'", subpath)
}
return to_return
2023-01-20 23:34:39 +01:00
func _register_inners(base_path, obj, prev_inner = ""):
var const_map = obj.get_script_constant_map()
var consts = const_map.keys()
var const_idx = 0
2023-01-20 23:34:39 +01:00
while const_idx < consts.size():
var key = consts[const_idx]
var thing = const_map[key]
2023-01-20 23:34:39 +01:00
if typeof(thing) == TYPE_OBJECT:
var cur_inner = str(prev_inner, ".", key)
_registry[thing] = _create_reg_entry(base_path, cur_inner)
_register_inners(base_path, thing, cur_inner)
const_idx += 1
func register(base_script):
var base_path = base_script.resource_path
_register_inners(base_path, base_script)
func get_extends_path(inner_class):
2023-01-20 23:34:39 +01:00
if _registry.has(inner_class):
return _registry[inner_class].full_path
else:
return null
2023-01-20 23:34:39 +01:00
# returns the subpath for the inner class. This includes the leading "." in
# the path.
func get_subpath(inner_class):
2023-01-20 23:34:39 +01:00
if _registry.has(inner_class):
return _registry[inner_class].subpath
else:
2023-01-20 23:34:39 +01:00
return ""
func get_base_path(inner_class):
2023-01-20 23:34:39 +01:00
if _registry.has(inner_class):
return _registry[inner_class].base_path
func has(inner_class):
return _registry.has(inner_class)
func get_base_resource(inner_class):
2023-01-20 23:34:39 +01:00
if _registry.has(inner_class):
return _registry[inner_class].base_resource
func to_s():
var text = ""
for key in _registry:
text += str(key, ": ", _registry[key], "\n")
return text