## ## Roles file, implements an interface to roles like in perl ## The roles module is inteded as an interface to easily write mods ## for existing objects as such, it also contains functions to look ## for a mods/ folder in the current directory ## ## Simple dymmy role for testing class DummyRole extends Node: func _init(): pass func dummyfunc(): globl.dbg_print("Dummy function called in dummy role") ## Check if a given object implements a role ## The role argument is given as lib.Role. ## But Godot shows this as GDScript anyway static func fulfills(obj : Node, role : Variant) -> bool: for ch in obj.get_children(): if is_instance_of(ch, role): return true return false ## Implement the given role into the object static func consume(obj : Node, role : Variant, args : Array): var new_role = role.callv('new', args) obj.add_child(new_role) return new_role ## Implements the given class but from a file instead static func consume_gd(obj :Node, gdcls : GDScript, args :Array): var newrole = gdcls.callv("new", args) obj.add_child.call_deferred(gdcls) var roles = obj.get_meta("roles") if not roles: obj.set_meta("roles", [gdcls]) else: roles.push_back(gdcls) obj.set_meta("roles", roles) return newrole ## Checks to see if a given object implements a gd script file role static func fulfills_gd(obj :Node, gdcls : GDScript) -> bool: for ch in obj.get_children(): if is_instance_of(ch, gdcls): return true return false ## Check if mods are present static func get_mods_folder() -> DirAccess: var exec_folder = OS.get_executable_path().get_base_dir() var mod_path = DirAccess.open(exec_folder) # expecting a file called mods/ in the executable install path # but only on release builds if OS.is_debug_build(): # Debugging, use user file path for testing mod_path = DirAccess.open("user://mods") return mod_path ## Get mod folders static func get_mod(): push_error("Not implemented") .