flowGraph.d.ts 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. import type { Scene } from "../scene";
  2. import { FlowGraphEventBlock } from "./flowGraphEventBlock";
  3. import { FlowGraphContext } from "./flowGraphContext";
  4. import { FlowGraphBlock } from "./flowGraphBlock";
  5. import type { FlowGraphCoordinator } from "./flowGraphCoordinator";
  6. import type { FlowGraphSignalConnection } from "./flowGraphSignalConnection";
  7. import type { FlowGraphDataConnection } from "./flowGraphDataConnection";
  8. import type { ISerializedFlowGraph, IObjectAccessor } from "./typeDefinitions";
  9. import type { IPathToObjectConverter } from "../ObjectModel/objectModelInterfaces";
  10. export declare enum FlowGraphState {
  11. /**
  12. * The graph is stopped
  13. */
  14. Stopped = 0,
  15. /**
  16. * The graph is running
  17. */
  18. Started = 1
  19. }
  20. /**
  21. * @experimental
  22. * Parameters used to create a flow graph.
  23. */
  24. export interface IFlowGraphParams {
  25. /**
  26. * The scene that the flow graph belongs to.
  27. */
  28. scene: Scene;
  29. /**
  30. * The event coordinator used by the flow graph.
  31. */
  32. coordinator: FlowGraphCoordinator;
  33. }
  34. /**
  35. * @experimental
  36. * Options for parsing a flow graph.
  37. */
  38. export interface IFlowGraphParseOptions {
  39. /**
  40. * A function that parses complex values in a scene.
  41. * @param key the key of the value
  42. * @param serializationObject the object to read the value from
  43. * @param scene the scene to read the value from
  44. */
  45. valueParseFunction?: (key: string, serializationObject: any, scene: Scene) => any;
  46. /**
  47. * The flow graph coordinator.
  48. */
  49. coordinator: FlowGraphCoordinator;
  50. /**
  51. * A function that converts a path to an object accessor.
  52. */
  53. pathConverter: IPathToObjectConverter<IObjectAccessor>;
  54. }
  55. /**
  56. * @experimental
  57. * Class used to represent a flow graph.
  58. * A flow graph is a graph of blocks that can be used to create complex logic.
  59. * Blocks can be added to the graph and connected to each other.
  60. * The graph can then be started, which will init and start all of its event blocks.
  61. */
  62. export declare class FlowGraph {
  63. /** @internal */
  64. _eventBlocks: FlowGraphEventBlock[];
  65. private _sceneDisposeObserver;
  66. /**
  67. * @internal
  68. */
  69. readonly _scene: Scene;
  70. private _coordinator;
  71. private _executionContexts;
  72. /**
  73. * The state of the graph
  74. */
  75. state: FlowGraphState;
  76. /**
  77. * Construct a Flow Graph
  78. * @param params construction parameters. currently only the scene
  79. */
  80. constructor(params: IFlowGraphParams);
  81. /**
  82. * Create a context. A context represents one self contained execution for the graph, with its own variables.
  83. * @returns the context, where you can get and set variables
  84. */
  85. createContext(): FlowGraphContext;
  86. /**
  87. * Returns the execution context at a given index
  88. * @param index the index of the context
  89. * @returns the execution context at that index
  90. */
  91. getContext(index: number): FlowGraphContext;
  92. /**
  93. * Add an event block. When the graph is started, it will start listening to events
  94. * from the block and execute the graph when they are triggered.
  95. * @param block the event block to be added
  96. */
  97. addEventBlock(block: FlowGraphEventBlock): void;
  98. /**
  99. * Starts the flow graph. Initializes the event blocks and starts listening to events.
  100. */
  101. start(): void;
  102. private _getContextualOrder;
  103. /**
  104. * Disposes of the flow graph. Cancels any pending tasks and removes all event listeners.
  105. */
  106. dispose(): void;
  107. /**
  108. * Executes a function in all blocks of a flow graph, starting with the event blocks.
  109. * @param visitor the function to execute.
  110. */
  111. visitAllBlocks(visitor: (block: FlowGraphBlock) => void): void;
  112. /**
  113. * Serializes a graph
  114. * @param serializationObject the object to write the values in
  115. * @param valueSerializeFunction a function to serialize complex values
  116. */
  117. serialize(serializationObject?: any, valueSerializeFunction?: (key: string, value: any, serializationObject: any) => void): void;
  118. /**
  119. * Given a list of blocks, find an output data connection that has a specific unique id
  120. * @param blocks a list of flow graph blocks
  121. * @param uniqueId the unique id of a connection
  122. * @returns the connection that has this unique id. throws an error if none was found
  123. */
  124. static GetDataOutConnectionByUniqueId(blocks: FlowGraphBlock[], uniqueId: string): FlowGraphDataConnection<any>;
  125. /**
  126. * Given a list of blocks, find an input signal connection that has a specific unique id
  127. * @param blocks a list of flow graph blocks
  128. * @param uniqueId the unique id of a connection
  129. * @returns the connection that has this unique id. throws an error if none was found
  130. */
  131. static GetSignalInConnectionByUniqueId(blocks: FlowGraphBlock[], uniqueId: string): FlowGraphSignalConnection;
  132. /**
  133. * Parses a graph from a given serialization object
  134. * @param serializationObject the object where the values are written
  135. * @param options options for parsing the graph
  136. * @returns the parsed graph
  137. */
  138. static Parse(serializationObject: ISerializedFlowGraph, options: IFlowGraphParseOptions): FlowGraph;
  139. }