Class ScriptGraph

java.lang.Object
com.soulfiremc.server.script.ScriptGraph

public final class ScriptGraph extends Object
Represents the graph structure of a visual script. Contains nodes and edges that define the execution flow and data connections.
  • Method Details

    • builder

      public static ScriptGraph.Builder builder(String scriptId, String scriptName)
      Creates a new builder for constructing a ScriptGraph.
    • getNode

      public @Nullable ScriptGraph.GraphNode getNode(String nodeId)
      Gets a node by its ID.
      Parameters:
      nodeId - the node identifier
      Returns:
      the node, or null if not found
    • findTriggerNodes

      public List<String> findTriggerNodes()
      Finds all trigger nodes (entry points) in the graph. Trigger nodes are nodes with no incoming execution edges whose type is a registered trigger type (starts with "trigger.").
      Returns:
      list of trigger node IDs
    • getNextExecutionNodes

      public List<String> getNextExecutionNodes(String nodeId, String outputHandle)
      Gets the next execution nodes from a given node's output handle.
      Parameters:
      nodeId - the source node ID
      outputHandle - the execution output handle name
      Returns:
      list of target node IDs to execute next
    • getIncomingDataEdges

      public List<ScriptGraph.GraphEdge> getIncomingDataEdges(String nodeId)
      Gets all incoming DATA edges for a node. Uses pre-computed map for O(1) lookup instead of scanning all edges.
      Parameters:
      nodeId - the target node ID
      Returns:
      list of DATA edges targeting this node
    • topologicalSort

      public List<String> topologicalSort()
      Performs topological sort on the graph nodes. Returns nodes in execution order, respecting dependencies.
      Returns:
      list of node IDs in topological order
      Throws:
      IllegalStateException - if the graph contains cycles
    • scriptId

      public String scriptId()
    • scriptName

      public String scriptName()
    • nodes

      public Map<String, ScriptGraph.GraphNode> nodes()
    • edges

      public List<ScriptGraph.GraphEdge> edges()
    • outgoingEdgesByHandle

      public Map<String, List<ScriptGraph.GraphEdge>> outgoingEdgesByHandle()
    • incomingEdgesByHandle

      public Map<String, List<ScriptGraph.GraphEdge>> incomingEdgesByHandle()
    • incomingDataEdgesByNode

      public Map<String, List<ScriptGraph.GraphEdge>> incomingDataEdgesByNode()