/..

Code

GDScript

User class lookup

## Return:
##   If object has class_name'ed script -- class_name.
##   If object has unnamed script       -- script path.
##   If object has no script            -- engine class name.
static func script_get_class( object: Object ) -> String:
	var script: GDScript = object.get_script()
	
	if script:
		var path: String = script.resource_path
		
		for global_class in ProjectSettings._global_script_classes:
			if global_class.path == path:
				return global_class.class
				
			
		return path
	else:
		return object.get_class()
		
	

static func script_instance( class_name_: String ) -> Object:
	
	var entry := script_get_entry( class_name_ )
	
	if not entry.empty():
		var object: Object = ClassDB.instance( script_builtin_base_class(class_name_) )
		object.set_script( load(entry.path) )
		return object
	else:
		return null
		
	

static func script_get_subclasses( class_name_: String ) -> PoolStringArray:
	
	var list: PoolStringArray = []
	
	for global_class in ProjectSettings._global_script_classes:
		if global_class.base == class_name_:
			list.push_back(global_class.class)
			list.append_array( script_get_subclasses(global_class.class) )
			
		
	
	return list
	

static func script_builtin_base_class( class_name_: String ) -> String:
	
	var entry := script_get_entry( class_name_ )
	
	while not entry.empty():
		class_name_ = entry.base
		entry = script_get_entry( class_name_ )
		
	
	return class_name_
	

static func script_get_entry( class_name_: String ) -> Dictionary:
	for global_class in ProjectSettings._global_script_classes:
		if global_class.class == class_name_:
			return global_class
			
		
	
	return {}


# This works with how my project is laid out.
static func get_class_scene( class_: Script ) -> PackedScene:
	var script_path: String = class_.resource_path
	assert( script_path != "" )
	var scene_path: String = script_path.get_basename()+".tscn"
	return load(scene_path) as PackedScene
	

IP conversion

static func string2ip( string: String ) -> int:
	var parts: PoolStringArray = string.split( ".", false )
	assert( parts.size() == 4 )
	return \
		((int(parts[0]) & 0x000000FF) << 24) + \
		((int(parts[1]) & 0x000000FF) << 16) + \
		((int(parts[2]) & 0x000000FF) << 8) + \
		((int(parts[3]) & 0x000000FF) << 0)
		
	

static func ip2string( ip: int ) -> String:
	return "%d.%d.%d.%d" % [
		ip >> 24 & 0x000000FF,
		ip >> 16 & 0x000000FF,
		ip >> 8  & 0x000000FF,
		ip >> 0  & 0x000000FF,
	]
	

static func ip2string_mask( ip: int ) -> String:
	var mask := PoolStringArray()
	mask.resize(32)
	
	for i in range(0, 32, 1):
		mask[31-i] = String(ip & 0x00000001)
		ip >>= 1
		
	return mask.join("")


static func ip_matches_network( ip: int, network: int, mask: int ) -> bool:
	return (ip & mask) == (network & mask)