Skip to content

Instantly share code, notes, and snippets.

@me2beats
Last active April 21, 2022 15:16
Show Gist options
  • Save me2beats/069a7775dc485cc299d0231a6684506c to your computer and use it in GitHub Desktop.
Save me2beats/069a7775dc485cc299d0231a6684506c to your computer and use it in GitHub Desktop.
godot get custom classes
func get_custom_classes():
#gets list of "custom" classes (defined using class_name keyword)
var find_this = "_global_script_classes="
var custom_classes_lines = PoolStringArray()
var f = File.new()
f.open("res://project.godot", File.READ)
var add_lines = false
while not f.eof_reached():
var line = f.get_line()
if line.begins_with(find_this):
if "]" in line:
f.close()
return []
add_lines = true
if add_lines:
custom_classes_lines.append(line)
if "]" in line:
break
f.close()
var strip_var_name_len = find_this.length()
custom_classes_lines[0] = custom_classes_lines[0].substr(strip_var_name_len)
return str2var(custom_classes_lines.join(''))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment