flowGraphContext.d.ts 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. import type { Scene } from "../scene";
  2. import type { FlowGraphAsyncExecutionBlock } from "./flowGraphAsyncExecutionBlock";
  3. import type { FlowGraphBlock } from "./flowGraphBlock";
  4. import type { FlowGraphDataConnection } from "./flowGraphDataConnection";
  5. import type { FlowGraph } from "./flowGraph";
  6. import type { ISerializedFlowGraphContext } from "./typeDefinitions";
  7. import type { FlowGraphCoordinator } from "./flowGraphCoordinator";
  8. import { Observable } from "../Misc/observable";
  9. /**
  10. * Construction parameters for the context.
  11. * @experimental
  12. */
  13. export interface IFlowGraphContextConfiguration {
  14. /**
  15. * The scene that the flow graph context belongs to.
  16. */
  17. readonly scene: Scene;
  18. /**
  19. * The event coordinator used by the flow graph context.
  20. */
  21. readonly coordinator: FlowGraphCoordinator;
  22. }
  23. /**
  24. * @experimental
  25. * Options for parsing a context.
  26. */
  27. export interface IFlowGraphContextParseOptions {
  28. /**
  29. * A function that parses a value from a serialization object.
  30. * @param key the key of the value
  31. * @param serializationObject the object containing the value
  32. * @param scene the current scene
  33. * @returns
  34. */
  35. readonly valueParseFunction?: (key: string, serializationObject: any, scene: Scene) => any;
  36. /**
  37. * The graph that the context is being parsed in.
  38. */
  39. readonly graph: FlowGraph;
  40. }
  41. /**
  42. * @experimental
  43. * The context represents the current state and execution of the flow graph.
  44. * It contains both user-defined variables, which are derived from
  45. * a more general variable definition, and execution variables that
  46. * are set by the blocks.
  47. */
  48. export declare class FlowGraphContext {
  49. /**
  50. * A randomly generated GUID for each context.
  51. */
  52. uniqueId: string;
  53. /**
  54. * These are the variables defined by a user.
  55. */
  56. private _userVariables;
  57. /**
  58. * These are the variables set by the blocks.
  59. */
  60. private _executionVariables;
  61. /**
  62. * These are the values for the data connection points
  63. */
  64. private _connectionValues;
  65. /**
  66. * These are the variables set by the graph.
  67. */
  68. private readonly _configuration;
  69. /**
  70. * These are blocks that have currently pending tasks/listeners that need to be cleaned up.
  71. */
  72. private _pendingBlocks;
  73. /**
  74. * A monotonically increasing ID for each execution.
  75. * Incremented for every block executed.
  76. */
  77. private _executionId;
  78. /**
  79. * Observable that is triggered when a node is executed.
  80. */
  81. onNodeExecutedObservable: Observable<FlowGraphBlock>;
  82. constructor(params: IFlowGraphContextConfiguration);
  83. /**
  84. * Check if a user-defined variable is defined.
  85. * @param name the name of the variable
  86. * @returns true if the variable is defined
  87. */
  88. hasVariable(name: string): boolean;
  89. /**
  90. * Set a user-defined variable.
  91. * @param name the name of the variable
  92. * @param value the value of the variable
  93. */
  94. setVariable(name: string, value: any): void;
  95. /**
  96. * Get a user-defined variable.
  97. * @param name the name of the variable
  98. * @returns the value of the variable
  99. */
  100. getVariable(name: string): any;
  101. /**
  102. * Gets all user variables map
  103. */
  104. get userVariables(): {
  105. [key: string]: any;
  106. };
  107. private _getUniqueIdPrefixedName;
  108. /**
  109. * Set an internal execution variable
  110. * @internal
  111. * @param name
  112. * @param value
  113. */
  114. _setExecutionVariable(block: FlowGraphBlock, name: string, value: any): void;
  115. /**
  116. * Get an internal execution variable
  117. * @internal
  118. * @param name
  119. * @returns
  120. */
  121. _getExecutionVariable(block: FlowGraphBlock, name: string, defaultValue?: any): any;
  122. /**
  123. * Delete an internal execution variable
  124. * @internal
  125. * @param block
  126. * @param name
  127. */
  128. _deleteExecutionVariable(block: FlowGraphBlock, name: string): void;
  129. /**
  130. * Check if an internal execution variable is defined
  131. * @internal
  132. * @param block
  133. * @param name
  134. * @returns
  135. */
  136. _hasExecutionVariable(block: FlowGraphBlock, name: string): boolean;
  137. /**
  138. * Check if a connection value is defined
  139. * @internal
  140. * @param connectionPoint
  141. * @returns
  142. */
  143. _hasConnectionValue(connectionPoint: FlowGraphDataConnection<any>): boolean;
  144. /**
  145. * Set a connection value
  146. * @internal
  147. * @param connectionPoint
  148. * @param value
  149. */
  150. _setConnectionValue<T>(connectionPoint: FlowGraphDataConnection<T>, value: T): void;
  151. /**
  152. * Get a connection value
  153. * @internal
  154. * @param connectionPoint
  155. * @returns
  156. */
  157. _getConnectionValue<T>(connectionPoint: FlowGraphDataConnection<T>): T;
  158. /**
  159. * Get the configuration
  160. * @internal
  161. * @param name
  162. * @param value
  163. */
  164. get configuration(): IFlowGraphContextConfiguration;
  165. /**
  166. * Add a block to the list of blocks that have pending tasks.
  167. * @internal
  168. * @param block
  169. */
  170. _addPendingBlock(block: FlowGraphAsyncExecutionBlock): void;
  171. /**
  172. * Remove a block from the list of blocks that have pending tasks.
  173. * @internal
  174. * @param block
  175. */
  176. _removePendingBlock(block: FlowGraphAsyncExecutionBlock): void;
  177. /**
  178. * Clear all pending blocks.
  179. * @internal
  180. */
  181. _clearPendingBlocks(): void;
  182. /**
  183. * @internal
  184. * Function that notifies the node executed observable
  185. * @param node
  186. */
  187. _notifyExecuteNode(node: FlowGraphBlock): void;
  188. /**
  189. * @internal
  190. */
  191. _increaseExecutionId(): void;
  192. /**
  193. * A monotonically increasing ID for each execution.
  194. * Incremented for every block executed.
  195. */
  196. get executionId(): number;
  197. /**
  198. * Serializes a context
  199. * @param serializationObject the object to write the values in
  200. * @param valueSerializationFunction a function to serialize complex values
  201. */
  202. serialize(serializationObject?: any, valueSerializationFunction?: (key: string, value: any, serializationObject: any) => void): void;
  203. /**
  204. * @returns the class name of the object.
  205. */
  206. getClassName(): string;
  207. /**
  208. * Parses a context
  209. * @param serializationObject the object containing the context serialization values
  210. * @param options the options for parsing the context
  211. * @returns
  212. */
  213. static Parse(serializationObject: ISerializedFlowGraphContext, options: IFlowGraphContextParseOptions): FlowGraphContext;
  214. }