mirror of
https://github.com/litruv/lit.ruv.wtf.git
synced 2026-07-24 10:46:03 +10:00
update to node site
This commit is contained in:
50
website/scripts/nodes/NodeRegistry.js
Normal file
50
website/scripts/nodes/NodeRegistry.js
Normal file
@@ -0,0 +1,50 @@
|
||||
/**
|
||||
* @file NodeRegistry.js
|
||||
* Static registry mapping node type strings to their handler instances.
|
||||
*/
|
||||
|
||||
import { NodeBase } from './NodeBase.js';
|
||||
|
||||
/**
|
||||
* Static registry for all Blueprint node types.
|
||||
* Node classes self-register by calling UCLASS_Register during module init.
|
||||
*/
|
||||
export class NodeRegistry {
|
||||
/** @type {Map<string, NodeBase>} */
|
||||
static #registry = new Map();
|
||||
|
||||
/**
|
||||
* Registers a node class by its static NodeType.
|
||||
* Call once per class, typically at the bottom of the class file.
|
||||
*
|
||||
* @UFUNCTION(BlueprintCallable)
|
||||
* @param {typeof NodeBase} NodeClass
|
||||
*/
|
||||
static UCLASS_Register(NodeClass) {
|
||||
if (!NodeClass.NodeType) {
|
||||
throw new Error(`[NodeRegistry] "${NodeClass.name}" is missing a static NodeType.`);
|
||||
}
|
||||
this.#registry.set(NodeClass.NodeType, new NodeClass());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the handler instance for a given node type, or null.
|
||||
*
|
||||
* @UFUNCTION(BlueprintPure)
|
||||
* @param {string} nodeType
|
||||
* @returns {NodeBase | null}
|
||||
*/
|
||||
static BlueprintPure_Get(nodeType) {
|
||||
return this.#registry.get(nodeType) ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all currently registered type strings.
|
||||
*
|
||||
* @UFUNCTION(BlueprintPure)
|
||||
* @returns {string[]}
|
||||
*/
|
||||
static BlueprintPure_GetRegisteredTypes() {
|
||||
return [...this.#registry.keys()];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user