@woosh/meep-engine
Version:
Pure JavaScript game engine. Fully featured and production ready.
241 lines • 7.03 kB
TypeScript
/**
* Graph of nodes, implements node-based programming pattern
* Notable contemporary examples include:
* * SideFX Houdini
* * Blender - geometry nodes, shaders
* * Unreal Engine - blueprints
* * Grasshopper
* @see https://en.wikipedia.org/wiki/Node_graph_architecture
*/
export class NodeGraph {
/**
* @private
* @readonly
* @type {List<NodeInstance>}
*/
private readonly nodes;
/**
* Flat hierarchy of all connections between nodes
* @private
* @readonly
* @type {List<Connection>}
*/
private readonly connections;
/**
*
* @type {IdPool}
* @readonly
* @private
*/
private readonly __idpNodes;
/**
*
* @type {IdPool}
* @readonly
* @private
*/
private readonly __idpConnections;
/**
* Gets incremented every time structure of the graph changes, meaning nodes or connections are added/removed
* Unsigned integer value
* @readonly
* @return {number}
*/
readonly get version(): number;
/**
* @readonly
*/
readonly on: {
/**
* @readonly
* @type {Signal<NodeInstance,number>}
*/
readonly nodeAdded: Signal<NodeInstance<import("./node/NodeDescription.js").NodeDescription>, number>;
/**
* @readonly
* @type {Signal<NodeInstance,number>}
*/
readonly nodeRemoved: Signal<NodeInstance<import("./node/NodeDescription.js").NodeDescription>, number>;
/**
* @readonly
* @type {Signal<Connection,number>}
*/
readonly connectionAdded: Signal<Connection, number>;
/**
* @readonly
* @type {Signal<Connection,number>}
*/
readonly connectionRemoved: Signal<Connection, number>;
};
/**
* Clear out all data from the graph
*/
reset(): void;
/**
* Perform a deep copy
* @param {NodeGraph} other
*/
copy(other: NodeGraph): void;
/**
*
* @returns {NodeGraph}
*/
clone(): NodeGraph;
/**
* Merge another graph into this one
* Supplied graph does not change as a result
* @see {@link #mergeFragment}
* @param {NodeGraph} other
* @returns {{connections:Connection[], nodes:NodeInstance[]}}
*/
merge(other: NodeGraph): {
connections: Connection[];
nodes: NodeInstance[];
};
/**
* Merge foreign nodes and associated connections into this graph
* New node instances and connections will be created to reflect these inside this graph
* NOTE: parameters on merged nodes are shallow copies
* NOTE: if IDs are available - copied nodes will have the same IDs as the originals
* @param {NodeInstance[]} nodes
* @param {Connection[]} [connections]
* @returns {{connections:Connection[], nodes:NodeInstance[]}} local created instances
*/
mergeFragment({ nodes, connections }: NodeInstance[]): {
connections: Connection[];
nodes: NodeInstance[];
};
/**
*
* @param {function(NodeInstance):*} visitor
* @param [thisArg]
*/
traverseNodes(visitor: (arg0: NodeInstance) => any, thisArg?: any): void;
/**
*
* @param {function(Connection):*} visitor
* @param [thisArg]
*/
traverseConnections(visitor: (arg0: Connection) => any, thisArg?: any): void;
/**
* Returns an array of all node instances
* NOTE: this array is a copy
* @return {NodeInstance[]}
*/
getNodes(): NodeInstance[];
/**
* Returns an array of all connections
* NOTE: this array is a copy
* @return {Connection[]}
*/
getConnections(): Connection[];
/**
*
* @param {NodeInstance} node
* @returns {boolean}
*/
hasNode(node: NodeInstance): boolean;
/**
*
* @param {NodeDescription} description
* @returns {NodeInstance[]}
*/
getNodesByDescription(description: NodeDescription): NodeInstance[];
/**
*
* @param {Type<NodeDescription>} Klass
* @returns {NodeInstance[]}
*/
getNodesByDescriptionClass(Klass: Type<NodeDescription>): NodeInstance[];
/**
*
* @param {number} id
* @returns {NodeInstance|undefined}
*/
getNode(id: number): NodeInstance | undefined;
/**
* Same as getNode but throw exception when node doesn't exist
* @param {number} id
* @returns {NodeInstance}
* @throws if node doesn't exist
*/
getNodeSafe(id: number): NodeInstance;
/**
*
* @param {number} id
* @returns {Connection|undefined}
*/
getConnection(id: number): Connection | undefined;
/**
*
* @param {number} node_id
* @param {number} port_id
* @returns {NodeInstancePortReference|undefined}
*/
getConnectionEndpoint(node_id: number, port_id: number): NodeInstancePortReference | undefined;
/**
*
* @param {NodeDescription} node
* @returns {number} ID of the new node
*/
createNode(node: NodeDescription): number;
/**
*
* @param {NodeInstance} node
*/
addNode(node: NodeInstance): void;
/**
*
* @param {number} id
* @returns {boolean} True if deleted, false if node was not found
*/
deleteNode(id: number): boolean;
/**
* Utility method to help in creation of connections
* Same as {@link #createConnection}, but ports are identified by their named instead
* @param {number} sourceNode
* @param {string} sourcePort
* @param {number} targetNode
* @param {string} targetPort
* @returns {number} connection ID
*/
createConnectionByPortName(sourceNode: number, sourcePort: string, targetNode: number, targetPort: string): number;
/**
*
* @param {number} sourceNode
* @param {number} sourcePort
* @param {number} targetNode
* @param {number} targetPort
* @returns {number} ID of created or already existing connection
* @throws if any node or port are not found
*/
createConnection(sourceNode: number, sourcePort: number, targetNode: number, targetPort: number): number;
/**
*
* @param {number} id
* @returns {boolean} True if deleted, false if connection was not found
*/
deleteConnection(id: number): boolean;
/**
*
* @param {number} id
* @param {number[]} result IDs of attached connections
* @returns {number} number of found connections
*/
getConnectionsAttachedToNode(id: number, result: number[]): number;
toString(): string;
/**
* Useful for type checks
* @example
* if(graph.isNodeGraph === true){
* // yep, that's a NodeGraph alright!
* }
* @readonly
* @type {boolean}
*/
readonly isNodeGraph: boolean;
#private;
}
import { NodeInstance } from "./node/NodeInstance.js";
import { Connection } from "./Connection.js";
//# sourceMappingURL=NodeGraph.d.ts.map