OverviewFilesCommitsIssuesDocsReleasesPeers

proc-nodes / demo / socket_dump.gd

55 lines · gd ref:
## Dumps every proc-nodes node type and its input sockets, as JSON.
##
## blender-bridge/test/audit_socket_names.py needs this to answer "can each
## proc socket be found BY NAME on its Blender node". Without it the audit
## SKIPS, which is how its numbers came to be quoted from a commit message
## rather than measured.
##
##   {"MeshGrid": {"inputs":  [["Size X", "Float"], ...],
##                  "outputs": [["Mesh", "Geometry"]]}, ...}
##
## Outputs are in it because a MISSING output is just as silent as a missing
## input: Gradient Texture declared one where Blender's has Color and Fac, and
## every graph reading Fac read a socket that was not there.
##
## Keyed by get_node_type(), because that is what GEOMETRY_NODE_MAP maps to.
##
## Usage: godot --headless --path demo --script res://socket_dump.gd -- <out.json>
extends SceneTree

const TYPE_NAMES := ["Float", "Int", "Bool", "Vector", "Color", "String",
		"Geometry", "Object", "Rotation", "Matrix"]


func _init() -> void:
	var args := OS.get_cmdline_user_args()
	if args.is_empty():
		push_error("usage: ... --script res://socket_dump.gd -- <out.json>")
		quit(1)
		return

	var out := {}
	for cls in ClassDB.get_inheriters_from_class("ProcNode"):
		if not ClassDB.can_instantiate(cls):
			continue
		var n: ProcNode = ClassDB.instantiate(cls)
		if n == null:
			continue
		var ins := []
		for i in range(n.get_input_count()):
			var t := n.get_input_type(i)
			var tn: String = TYPE_NAMES[t] if t >= 0 and t < TYPE_NAMES.size() else "Unknown"
			ins.append([n.get_input_name(i), tn])
		var outs := []
		for i in range(n.get_output_count()):
			var t := n.get_output_type(i)
			var tn: String = TYPE_NAMES[t] if t >= 0 and t < TYPE_NAMES.size() else "Unknown"
			outs.append([n.get_output_name(i), tn])
		out[String(n.get_node_type())] = {"inputs": ins, "outputs": outs}

	var f := FileAccess.open(args[0], FileAccess.WRITE)
	f.store_string(JSON.stringify(out))
	f.close()
	print("SOCKET_DUMP wrote ", out.size(), " node types")
	quit()