@esengine/blueprint 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js ADDED
@@ -0,0 +1,3196 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
4
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
5
+
6
+ // src/types/pins.ts
7
+ function getPinTypeColor(type) {
8
+ const colors = {
9
+ exec: "#ffffff",
10
+ bool: "#cc0000",
11
+ int: "#00d4aa",
12
+ float: "#88cc00",
13
+ string: "#ff88cc",
14
+ vector2: "#d4aa00",
15
+ vector3: "#ffcc00",
16
+ color: "#ff8844",
17
+ entity: "#0088ff",
18
+ component: "#44aaff",
19
+ object: "#4444aa",
20
+ array: "#8844ff",
21
+ any: "#888888"
22
+ };
23
+ return colors[type] ?? colors.any;
24
+ }
25
+ __name(getPinTypeColor, "getPinTypeColor");
26
+ function arePinTypesCompatible(from, to) {
27
+ if (from === to) return true;
28
+ if (from === "any" || to === "any") return true;
29
+ if (from === "exec" || to === "exec") return false;
30
+ const numericTypes = [
31
+ "int",
32
+ "float"
33
+ ];
34
+ if (numericTypes.includes(from) && numericTypes.includes(to)) return true;
35
+ const vectorTypes = [
36
+ "vector2",
37
+ "vector3",
38
+ "color"
39
+ ];
40
+ if (vectorTypes.includes(from) && vectorTypes.includes(to)) return true;
41
+ return false;
42
+ }
43
+ __name(arePinTypesCompatible, "arePinTypesCompatible");
44
+
45
+ // src/types/nodes.ts
46
+ function getNodeCategoryColor(category) {
47
+ const colors = {
48
+ event: "#8b1e1e",
49
+ flow: "#4a4a4a",
50
+ entity: "#1e5a8b",
51
+ component: "#1e8b8b",
52
+ math: "#1e8b5a",
53
+ logic: "#8b1e5a",
54
+ variable: "#5a1e8b",
55
+ input: "#8b5a1e",
56
+ physics: "#8b8b1e",
57
+ audio: "#8b1e6b",
58
+ time: "#1e6b8b",
59
+ debug: "#5a5a5a",
60
+ custom: "#4a4a4a"
61
+ };
62
+ return colors[category] ?? colors.custom;
63
+ }
64
+ __name(getNodeCategoryColor, "getNodeCategoryColor");
65
+
66
+ // src/types/blueprint.ts
67
+ function createEmptyBlueprint(name) {
68
+ return {
69
+ version: 1,
70
+ type: "blueprint",
71
+ metadata: {
72
+ name,
73
+ createdAt: Date.now(),
74
+ modifiedAt: Date.now()
75
+ },
76
+ variables: [],
77
+ nodes: [],
78
+ connections: []
79
+ };
80
+ }
81
+ __name(createEmptyBlueprint, "createEmptyBlueprint");
82
+ function validateBlueprintAsset(asset) {
83
+ if (!asset || typeof asset !== "object") return false;
84
+ const bp = asset;
85
+ return typeof bp.version === "number" && bp.type === "blueprint" && typeof bp.metadata === "object" && Array.isArray(bp.variables) && Array.isArray(bp.nodes) && Array.isArray(bp.connections);
86
+ }
87
+ __name(validateBlueprintAsset, "validateBlueprintAsset");
88
+
89
+ // src/runtime/ExecutionContext.ts
90
+ var _ExecutionContext = class _ExecutionContext {
91
+ constructor(blueprint, entity, scene) {
92
+ /** Current blueprint asset (当前蓝图资产) */
93
+ __publicField(this, "blueprint");
94
+ /** Owner entity (所有者实体) */
95
+ __publicField(this, "entity");
96
+ /** Current scene (当前场景) */
97
+ __publicField(this, "scene");
98
+ /** Frame delta time (帧增量时间) */
99
+ __publicField(this, "deltaTime", 0);
100
+ /** Total time since start (开始以来的总时间) */
101
+ __publicField(this, "time", 0);
102
+ /** Instance variables (实例变量) */
103
+ __publicField(this, "_instanceVariables", /* @__PURE__ */ new Map());
104
+ /** Local variables (per-execution) (局部变量,每次执行) */
105
+ __publicField(this, "_localVariables", /* @__PURE__ */ new Map());
106
+ /** Node output cache for current execution (当前执行的节点输出缓存) */
107
+ __publicField(this, "_outputCache", /* @__PURE__ */ new Map());
108
+ /** Connection lookup by target (按目标的连接查找) */
109
+ __publicField(this, "_connectionsByTarget", /* @__PURE__ */ new Map());
110
+ /** Connection lookup by source (按源的连接查找) */
111
+ __publicField(this, "_connectionsBySource", /* @__PURE__ */ new Map());
112
+ this.blueprint = blueprint;
113
+ this.entity = entity;
114
+ this.scene = scene;
115
+ for (const variable of blueprint.variables) {
116
+ if (variable.scope === "instance") {
117
+ this._instanceVariables.set(variable.name, variable.defaultValue);
118
+ }
119
+ }
120
+ this._buildConnectionMaps();
121
+ }
122
+ _buildConnectionMaps() {
123
+ for (const conn of this.blueprint.connections) {
124
+ const targetKey = `${conn.toNodeId}.${conn.toPin}`;
125
+ if (!this._connectionsByTarget.has(targetKey)) {
126
+ this._connectionsByTarget.set(targetKey, []);
127
+ }
128
+ this._connectionsByTarget.get(targetKey).push(conn);
129
+ const sourceKey = `${conn.fromNodeId}.${conn.fromPin}`;
130
+ if (!this._connectionsBySource.has(sourceKey)) {
131
+ this._connectionsBySource.set(sourceKey, []);
132
+ }
133
+ this._connectionsBySource.get(sourceKey).push(conn);
134
+ }
135
+ }
136
+ /**
137
+ * Get a node by ID
138
+ * 通过ID获取节点
139
+ */
140
+ getNode(nodeId) {
141
+ return this.blueprint.nodes.find((n) => n.id === nodeId);
142
+ }
143
+ /**
144
+ * Get connections to a target pin
145
+ * 获取到目标引脚的连接
146
+ */
147
+ getConnectionsToPin(nodeId, pinName) {
148
+ return this._connectionsByTarget.get(`${nodeId}.${pinName}`) ?? [];
149
+ }
150
+ /**
151
+ * Get connections from a source pin
152
+ * 获取从源引脚的连接
153
+ */
154
+ getConnectionsFromPin(nodeId, pinName) {
155
+ return this._connectionsBySource.get(`${nodeId}.${pinName}`) ?? [];
156
+ }
157
+ /**
158
+ * Evaluate an input pin value (follows connections or uses default)
159
+ * 计算输入引脚值(跟随连接或使用默认值)
160
+ */
161
+ evaluateInput(nodeId, pinName, defaultValue) {
162
+ const connections = this.getConnectionsToPin(nodeId, pinName);
163
+ if (connections.length === 0) {
164
+ const node = this.getNode(nodeId);
165
+ return node?.data[pinName] ?? defaultValue;
166
+ }
167
+ const conn = connections[0];
168
+ const cachedOutputs = this._outputCache.get(conn.fromNodeId);
169
+ if (cachedOutputs && conn.fromPin in cachedOutputs) {
170
+ return cachedOutputs[conn.fromPin];
171
+ }
172
+ return defaultValue;
173
+ }
174
+ /**
175
+ * Set output values for a node (cached for current execution)
176
+ * 设置节点的输出值(为当前执行缓存)
177
+ */
178
+ setOutputs(nodeId, outputs) {
179
+ this._outputCache.set(nodeId, outputs);
180
+ }
181
+ /**
182
+ * Get cached outputs for a node
183
+ * 获取节点的缓存输出
184
+ */
185
+ getOutputs(nodeId) {
186
+ return this._outputCache.get(nodeId);
187
+ }
188
+ /**
189
+ * Clear output cache (call at start of new execution)
190
+ * 清除输出缓存(在新执行开始时调用)
191
+ */
192
+ clearOutputCache() {
193
+ this._outputCache.clear();
194
+ this._localVariables.clear();
195
+ }
196
+ /**
197
+ * Get a variable value
198
+ * 获取变量值
199
+ */
200
+ getVariable(name) {
201
+ if (this._localVariables.has(name)) {
202
+ return this._localVariables.get(name);
203
+ }
204
+ if (this._instanceVariables.has(name)) {
205
+ return this._instanceVariables.get(name);
206
+ }
207
+ if (_ExecutionContext._globalVariables.has(name)) {
208
+ return _ExecutionContext._globalVariables.get(name);
209
+ }
210
+ const varDef = this.blueprint.variables.find((v) => v.name === name);
211
+ return varDef?.defaultValue;
212
+ }
213
+ /**
214
+ * Set a variable value
215
+ * 设置变量值
216
+ */
217
+ setVariable(name, value) {
218
+ const varDef = this.blueprint.variables.find((v) => v.name === name);
219
+ if (!varDef) {
220
+ this._localVariables.set(name, value);
221
+ return;
222
+ }
223
+ switch (varDef.scope) {
224
+ case "local":
225
+ this._localVariables.set(name, value);
226
+ break;
227
+ case "instance":
228
+ this._instanceVariables.set(name, value);
229
+ break;
230
+ case "global":
231
+ _ExecutionContext._globalVariables.set(name, value);
232
+ break;
233
+ }
234
+ }
235
+ /**
236
+ * Get all instance variables (for serialization)
237
+ * 获取所有实例变量(用于序列化)
238
+ */
239
+ getInstanceVariables() {
240
+ return new Map(this._instanceVariables);
241
+ }
242
+ /**
243
+ * Set instance variables (for deserialization)
244
+ * 设置实例变量(用于反序列化)
245
+ */
246
+ setInstanceVariables(variables) {
247
+ this._instanceVariables = new Map(variables);
248
+ }
249
+ /**
250
+ * Clear global variables (for scene reset)
251
+ * 清除全局变量(用于场景重置)
252
+ */
253
+ static clearGlobalVariables() {
254
+ _ExecutionContext._globalVariables.clear();
255
+ }
256
+ };
257
+ __name(_ExecutionContext, "ExecutionContext");
258
+ /** Global variables (shared) (全局变量,共享) */
259
+ __publicField(_ExecutionContext, "_globalVariables", /* @__PURE__ */ new Map());
260
+ var ExecutionContext = _ExecutionContext;
261
+
262
+ // src/runtime/NodeRegistry.ts
263
+ var _NodeRegistry = class _NodeRegistry {
264
+ constructor() {
265
+ __publicField(this, "_nodes", /* @__PURE__ */ new Map());
266
+ }
267
+ static get instance() {
268
+ if (!_NodeRegistry._instance) {
269
+ _NodeRegistry._instance = new _NodeRegistry();
270
+ }
271
+ return _NodeRegistry._instance;
272
+ }
273
+ /**
274
+ * Register a node type
275
+ * 注册节点类型
276
+ */
277
+ register(template, executor) {
278
+ if (this._nodes.has(template.type)) {
279
+ console.warn(`Node type "${template.type}" is already registered, overwriting`);
280
+ }
281
+ this._nodes.set(template.type, {
282
+ template,
283
+ executor
284
+ });
285
+ }
286
+ /**
287
+ * Get a node definition by type
288
+ * 通过类型获取节点定义
289
+ */
290
+ get(type) {
291
+ return this._nodes.get(type);
292
+ }
293
+ /**
294
+ * Get node template by type
295
+ * 通过类型获取节点模板
296
+ */
297
+ getTemplate(type) {
298
+ return this._nodes.get(type)?.template;
299
+ }
300
+ /**
301
+ * Get node executor by type
302
+ * 通过类型获取节点执行器
303
+ */
304
+ getExecutor(type) {
305
+ return this._nodes.get(type)?.executor;
306
+ }
307
+ /**
308
+ * Check if a node type is registered
309
+ * 检查节点类型是否已注册
310
+ */
311
+ has(type) {
312
+ return this._nodes.has(type);
313
+ }
314
+ /**
315
+ * Get all registered templates
316
+ * 获取所有注册的模板
317
+ */
318
+ getAllTemplates() {
319
+ return Array.from(this._nodes.values()).map((d) => d.template);
320
+ }
321
+ /**
322
+ * Get templates by category
323
+ * 按类别获取模板
324
+ */
325
+ getTemplatesByCategory(category) {
326
+ return this.getAllTemplates().filter((t) => t.category === category);
327
+ }
328
+ /**
329
+ * Search templates by keyword
330
+ * 按关键词搜索模板
331
+ */
332
+ searchTemplates(keyword) {
333
+ const lower = keyword.toLowerCase();
334
+ return this.getAllTemplates().filter((t) => t.title.toLowerCase().includes(lower) || t.type.toLowerCase().includes(lower) || t.keywords?.some((k) => k.toLowerCase().includes(lower)) || t.description?.toLowerCase().includes(lower));
335
+ }
336
+ /**
337
+ * Clear all registrations (for testing)
338
+ * 清除所有注册(用于测试)
339
+ */
340
+ clear() {
341
+ this._nodes.clear();
342
+ }
343
+ };
344
+ __name(_NodeRegistry, "NodeRegistry");
345
+ __publicField(_NodeRegistry, "_instance");
346
+ var NodeRegistry = _NodeRegistry;
347
+ function RegisterNode(template) {
348
+ return function(constructor) {
349
+ const executor = new constructor();
350
+ NodeRegistry.instance.register(template, executor);
351
+ return constructor;
352
+ };
353
+ }
354
+ __name(RegisterNode, "RegisterNode");
355
+
356
+ // src/runtime/BlueprintVM.ts
357
+ var _BlueprintVM = class _BlueprintVM {
358
+ constructor(blueprint, entity, scene) {
359
+ /** Execution context (执行上下文) */
360
+ __publicField(this, "_context");
361
+ /** Pending executions (delayed nodes) (待处理的执行) */
362
+ __publicField(this, "_pendingExecutions", []);
363
+ /** Event node cache by type (按类型缓存的事件节点) */
364
+ __publicField(this, "_eventNodes", /* @__PURE__ */ new Map());
365
+ /** Whether the VM is running (VM 是否运行中) */
366
+ __publicField(this, "_isRunning", false);
367
+ /** Current execution time (当前执行时间) */
368
+ __publicField(this, "_currentTime", 0);
369
+ /** Maximum execution steps per frame (每帧最大执行步骤) */
370
+ __publicField(this, "_maxStepsPerFrame", 1e3);
371
+ /** Debug mode (调试模式) */
372
+ __publicField(this, "debug", false);
373
+ this._context = new ExecutionContext(blueprint, entity, scene);
374
+ this._cacheEventNodes();
375
+ }
376
+ get context() {
377
+ return this._context;
378
+ }
379
+ get isRunning() {
380
+ return this._isRunning;
381
+ }
382
+ /**
383
+ * Cache event nodes by type for quick lookup
384
+ * 按类型缓存事件节点以便快速查找
385
+ */
386
+ _cacheEventNodes() {
387
+ for (const node of this._context.blueprint.nodes) {
388
+ if (node.type.startsWith("Event")) {
389
+ const eventType = node.type;
390
+ if (!this._eventNodes.has(eventType)) {
391
+ this._eventNodes.set(eventType, []);
392
+ }
393
+ this._eventNodes.get(eventType).push(node);
394
+ }
395
+ }
396
+ }
397
+ /**
398
+ * Start the VM
399
+ * 启动 VM
400
+ */
401
+ start() {
402
+ this._isRunning = true;
403
+ this._currentTime = 0;
404
+ this.triggerEvent("EventBeginPlay");
405
+ }
406
+ /**
407
+ * Stop the VM
408
+ * 停止 VM
409
+ */
410
+ stop() {
411
+ this.triggerEvent("EventEndPlay");
412
+ this._isRunning = false;
413
+ this._pendingExecutions = [];
414
+ }
415
+ /**
416
+ * Pause the VM
417
+ * 暂停 VM
418
+ */
419
+ pause() {
420
+ this._isRunning = false;
421
+ }
422
+ /**
423
+ * Resume the VM
424
+ * 恢复 VM
425
+ */
426
+ resume() {
427
+ this._isRunning = true;
428
+ }
429
+ /**
430
+ * Update the VM (called every frame)
431
+ * 更新 VM(每帧调用)
432
+ */
433
+ tick(deltaTime) {
434
+ if (!this._isRunning) return;
435
+ this._currentTime += deltaTime;
436
+ this._context.deltaTime = deltaTime;
437
+ this._context.time = this._currentTime;
438
+ this._processPendingExecutions();
439
+ this.triggerEvent("EventTick");
440
+ }
441
+ /**
442
+ * Trigger an event by type
443
+ * 按类型触发事件
444
+ */
445
+ triggerEvent(eventType, data) {
446
+ const eventNodes = this._eventNodes.get(eventType);
447
+ if (!eventNodes) return;
448
+ for (const node of eventNodes) {
449
+ this._executeFromNode(node, "exec", data);
450
+ }
451
+ }
452
+ /**
453
+ * Trigger a custom event by name
454
+ * 按名称触发自定义事件
455
+ */
456
+ triggerCustomEvent(eventName, data) {
457
+ const eventNodes = this._eventNodes.get("EventCustom");
458
+ if (!eventNodes) return;
459
+ for (const node of eventNodes) {
460
+ if (node.data.eventName === eventName) {
461
+ this._executeFromNode(node, "exec", data);
462
+ }
463
+ }
464
+ }
465
+ /**
466
+ * Execute from a starting node
467
+ * 从起始节点执行
468
+ */
469
+ _executeFromNode(startNode, startPin, eventData) {
470
+ this._context.clearOutputCache();
471
+ if (eventData) {
472
+ this._context.setOutputs(startNode.id, eventData);
473
+ }
474
+ let currentNodeId = startNode.id;
475
+ let currentPin = startPin;
476
+ let steps = 0;
477
+ while (currentNodeId && steps < this._maxStepsPerFrame) {
478
+ steps++;
479
+ const connections = this._context.getConnectionsFromPin(currentNodeId, currentPin);
480
+ if (connections.length === 0) {
481
+ break;
482
+ }
483
+ const nextConn = connections[0];
484
+ const result = this._executeNode(nextConn.toNodeId);
485
+ if (result.error) {
486
+ console.error(`Blueprint error in node ${nextConn.toNodeId}: ${result.error}`);
487
+ break;
488
+ }
489
+ if (result.delay && result.delay > 0) {
490
+ this._pendingExecutions.push({
491
+ nodeId: nextConn.toNodeId,
492
+ execPin: result.nextExec ?? "exec",
493
+ resumeTime: this._currentTime + result.delay
494
+ });
495
+ break;
496
+ }
497
+ if (result.yield) {
498
+ break;
499
+ }
500
+ if (result.nextExec === null) {
501
+ break;
502
+ }
503
+ currentNodeId = nextConn.toNodeId;
504
+ currentPin = result.nextExec ?? "exec";
505
+ }
506
+ if (steps >= this._maxStepsPerFrame) {
507
+ console.warn("Blueprint execution exceeded maximum steps, possible infinite loop");
508
+ }
509
+ }
510
+ /**
511
+ * Execute a single node
512
+ * 执行单个节点
513
+ */
514
+ _executeNode(nodeId) {
515
+ const node = this._context.getNode(nodeId);
516
+ if (!node) {
517
+ return {
518
+ error: `Node not found: ${nodeId}`
519
+ };
520
+ }
521
+ const executor = NodeRegistry.instance.getExecutor(node.type);
522
+ if (!executor) {
523
+ return {
524
+ error: `No executor for node type: ${node.type}`
525
+ };
526
+ }
527
+ try {
528
+ if (this.debug) {
529
+ console.log(`[Blueprint] Executing: ${node.type} (${nodeId})`);
530
+ }
531
+ const result = executor.execute(node, this._context);
532
+ if (result.outputs) {
533
+ this._context.setOutputs(nodeId, result.outputs);
534
+ }
535
+ return result;
536
+ } catch (error) {
537
+ return {
538
+ error: `Execution error: ${error}`
539
+ };
540
+ }
541
+ }
542
+ /**
543
+ * Process pending delayed executions
544
+ * 处理待处理的延迟执行
545
+ */
546
+ _processPendingExecutions() {
547
+ const stillPending = [];
548
+ for (const pending of this._pendingExecutions) {
549
+ if (this._currentTime >= pending.resumeTime) {
550
+ const node = this._context.getNode(pending.nodeId);
551
+ if (node) {
552
+ this._executeFromNode(node, pending.execPin);
553
+ }
554
+ } else {
555
+ stillPending.push(pending);
556
+ }
557
+ }
558
+ this._pendingExecutions = stillPending;
559
+ }
560
+ /**
561
+ * Get instance variables for serialization
562
+ * 获取实例变量用于序列化
563
+ */
564
+ getInstanceVariables() {
565
+ return this._context.getInstanceVariables();
566
+ }
567
+ /**
568
+ * Set instance variables from serialization
569
+ * 从序列化设置实例变量
570
+ */
571
+ setInstanceVariables(variables) {
572
+ this._context.setInstanceVariables(variables);
573
+ }
574
+ };
575
+ __name(_BlueprintVM, "BlueprintVM");
576
+ var BlueprintVM = _BlueprintVM;
577
+
578
+ // src/runtime/BlueprintComponent.ts
579
+ function createBlueprintComponentData() {
580
+ return {
581
+ entityId: null,
582
+ blueprintAsset: null,
583
+ blueprintPath: "",
584
+ autoStart: true,
585
+ debug: false,
586
+ vm: null,
587
+ isStarted: false
588
+ };
589
+ }
590
+ __name(createBlueprintComponentData, "createBlueprintComponentData");
591
+ function initializeBlueprintVM(component, entity, scene) {
592
+ if (!component.blueprintAsset) {
593
+ return;
594
+ }
595
+ component.vm = new BlueprintVM(component.blueprintAsset, entity, scene);
596
+ component.vm.debug = component.debug;
597
+ }
598
+ __name(initializeBlueprintVM, "initializeBlueprintVM");
599
+ function startBlueprint(component) {
600
+ if (component.vm && !component.isStarted) {
601
+ component.vm.start();
602
+ component.isStarted = true;
603
+ }
604
+ }
605
+ __name(startBlueprint, "startBlueprint");
606
+ function stopBlueprint(component) {
607
+ if (component.vm && component.isStarted) {
608
+ component.vm.stop();
609
+ component.isStarted = false;
610
+ }
611
+ }
612
+ __name(stopBlueprint, "stopBlueprint");
613
+ function tickBlueprint(component, deltaTime) {
614
+ if (component.vm && component.isStarted) {
615
+ component.vm.tick(deltaTime);
616
+ }
617
+ }
618
+ __name(tickBlueprint, "tickBlueprint");
619
+ function cleanupBlueprint(component) {
620
+ if (component.vm) {
621
+ if (component.isStarted) {
622
+ component.vm.stop();
623
+ }
624
+ component.vm = null;
625
+ component.isStarted = false;
626
+ }
627
+ }
628
+ __name(cleanupBlueprint, "cleanupBlueprint");
629
+
630
+ // src/runtime/BlueprintSystem.ts
631
+ function createBlueprintSystem(scene) {
632
+ return {
633
+ process(entities, deltaTime) {
634
+ for (const entity of entities) {
635
+ const component = entity.blueprintComponent;
636
+ if (!component.blueprintAsset) {
637
+ continue;
638
+ }
639
+ if (!component.vm) {
640
+ initializeBlueprintVM(component, entity, scene);
641
+ }
642
+ if (component.autoStart && !component.isStarted) {
643
+ startBlueprint(component);
644
+ }
645
+ tickBlueprint(component, deltaTime);
646
+ }
647
+ },
648
+ onEntityAdded(entity) {
649
+ const component = entity.blueprintComponent;
650
+ if (component.blueprintAsset) {
651
+ initializeBlueprintVM(component, entity, scene);
652
+ if (component.autoStart) {
653
+ startBlueprint(component);
654
+ }
655
+ }
656
+ },
657
+ onEntityRemoved(entity) {
658
+ cleanupBlueprint(entity.blueprintComponent);
659
+ }
660
+ };
661
+ }
662
+ __name(createBlueprintSystem, "createBlueprintSystem");
663
+ function triggerBlueprintEvent(entity, eventType, data) {
664
+ const vm = entity.blueprintComponent.vm;
665
+ if (vm && entity.blueprintComponent.isStarted) {
666
+ vm.triggerEvent(eventType, data);
667
+ }
668
+ }
669
+ __name(triggerBlueprintEvent, "triggerBlueprintEvent");
670
+ function triggerCustomBlueprintEvent(entity, eventName, data) {
671
+ const vm = entity.blueprintComponent.vm;
672
+ if (vm && entity.blueprintComponent.isStarted) {
673
+ vm.triggerCustomEvent(eventName, data);
674
+ }
675
+ }
676
+ __name(triggerCustomBlueprintEvent, "triggerCustomBlueprintEvent");
677
+
678
+ // src/triggers/TriggerTypes.ts
679
+ var TriggerTypes = {
680
+ TICK: "tick",
681
+ INPUT: "input",
682
+ COLLISION: "collision",
683
+ MESSAGE: "message",
684
+ TIMER: "timer",
685
+ STATE_ENTER: "stateEnter",
686
+ STATE_EXIT: "stateExit",
687
+ CUSTOM: "custom"
688
+ };
689
+ function createTickContext(deltaTime, frameCount, sourceEntityId) {
690
+ return {
691
+ type: "tick",
692
+ timestamp: Date.now(),
693
+ deltaTime,
694
+ frameCount,
695
+ sourceEntityId
696
+ };
697
+ }
698
+ __name(createTickContext, "createTickContext");
699
+ function createInputContext(action, value, options) {
700
+ return {
701
+ type: "input",
702
+ timestamp: Date.now(),
703
+ action,
704
+ value,
705
+ pressed: options?.pressed,
706
+ released: options?.released,
707
+ sourceEntityId: options?.sourceEntityId
708
+ };
709
+ }
710
+ __name(createInputContext, "createInputContext");
711
+ function createCollisionContext(otherEntityId, isEnter, options) {
712
+ return {
713
+ type: "collision",
714
+ timestamp: Date.now(),
715
+ otherEntityId,
716
+ isEnter,
717
+ isExit: !isEnter,
718
+ point: options?.point,
719
+ normal: options?.normal,
720
+ sourceEntityId: options?.sourceEntityId
721
+ };
722
+ }
723
+ __name(createCollisionContext, "createCollisionContext");
724
+ function createMessageContext(messageName, payload, options) {
725
+ return {
726
+ type: "message",
727
+ timestamp: Date.now(),
728
+ messageName,
729
+ payload,
730
+ senderId: options?.senderId,
731
+ sourceEntityId: options?.sourceEntityId
732
+ };
733
+ }
734
+ __name(createMessageContext, "createMessageContext");
735
+ function createTimerContext(timerId, isRepeating, timesFired, sourceEntityId) {
736
+ return {
737
+ type: "timer",
738
+ timestamp: Date.now(),
739
+ timerId,
740
+ isRepeating,
741
+ timesFired,
742
+ sourceEntityId
743
+ };
744
+ }
745
+ __name(createTimerContext, "createTimerContext");
746
+ function createStateContext(type, stateMachineId, currentState, previousState, sourceEntityId) {
747
+ return {
748
+ type,
749
+ timestamp: Date.now(),
750
+ stateMachineId,
751
+ currentState,
752
+ previousState,
753
+ sourceEntityId
754
+ };
755
+ }
756
+ __name(createStateContext, "createStateContext");
757
+ function createCustomContext(eventName, data, sourceEntityId) {
758
+ return {
759
+ type: "custom",
760
+ timestamp: Date.now(),
761
+ eventName,
762
+ data,
763
+ sourceEntityId
764
+ };
765
+ }
766
+ __name(createCustomContext, "createCustomContext");
767
+
768
+ // src/triggers/TriggerCondition.ts
769
+ var _CompositeCondition = class _CompositeCondition {
770
+ constructor(_conditions, _logic = "and") {
771
+ __publicField(this, "_conditions");
772
+ __publicField(this, "_logic");
773
+ __publicField(this, "type", "composite");
774
+ this._conditions = _conditions;
775
+ this._logic = _logic;
776
+ }
777
+ evaluate(context) {
778
+ if (this._conditions.length === 0) {
779
+ return true;
780
+ }
781
+ if (this._logic === "and") {
782
+ return this._conditions.every((c) => c.evaluate(context));
783
+ } else {
784
+ return this._conditions.some((c) => c.evaluate(context));
785
+ }
786
+ }
787
+ };
788
+ __name(_CompositeCondition, "CompositeCondition");
789
+ var CompositeCondition = _CompositeCondition;
790
+ var _NotCondition = class _NotCondition {
791
+ constructor(_condition) {
792
+ __publicField(this, "_condition");
793
+ __publicField(this, "type", "not");
794
+ this._condition = _condition;
795
+ }
796
+ evaluate(context) {
797
+ return !this._condition.evaluate(context);
798
+ }
799
+ };
800
+ __name(_NotCondition, "NotCondition");
801
+ var NotCondition = _NotCondition;
802
+ var _AlwaysTrueCondition = class _AlwaysTrueCondition {
803
+ constructor() {
804
+ __publicField(this, "type", "alwaysTrue");
805
+ }
806
+ evaluate(_context) {
807
+ return true;
808
+ }
809
+ };
810
+ __name(_AlwaysTrueCondition, "AlwaysTrueCondition");
811
+ var AlwaysTrueCondition = _AlwaysTrueCondition;
812
+ var _AlwaysFalseCondition = class _AlwaysFalseCondition {
813
+ constructor() {
814
+ __publicField(this, "type", "alwaysFalse");
815
+ }
816
+ evaluate(_context) {
817
+ return false;
818
+ }
819
+ };
820
+ __name(_AlwaysFalseCondition, "AlwaysFalseCondition");
821
+ var AlwaysFalseCondition = _AlwaysFalseCondition;
822
+ var _TriggerTypeCondition = class _TriggerTypeCondition {
823
+ constructor(_allowedTypes) {
824
+ __publicField(this, "_allowedTypes");
825
+ __publicField(this, "type", "triggerType");
826
+ this._allowedTypes = _allowedTypes;
827
+ }
828
+ evaluate(context) {
829
+ return this._allowedTypes.includes(context.type);
830
+ }
831
+ };
832
+ __name(_TriggerTypeCondition, "TriggerTypeCondition");
833
+ var TriggerTypeCondition = _TriggerTypeCondition;
834
+ var _EntityIdCondition = class _EntityIdCondition {
835
+ constructor(_entityId, _checkSource = true) {
836
+ __publicField(this, "_entityId");
837
+ __publicField(this, "_checkSource");
838
+ __publicField(this, "type", "entityId");
839
+ this._entityId = _entityId;
840
+ this._checkSource = _checkSource;
841
+ }
842
+ evaluate(context) {
843
+ if (this._checkSource) {
844
+ return context.sourceEntityId === this._entityId;
845
+ }
846
+ return false;
847
+ }
848
+ };
849
+ __name(_EntityIdCondition, "EntityIdCondition");
850
+ var EntityIdCondition = _EntityIdCondition;
851
+ var _FunctionCondition = class _FunctionCondition {
852
+ constructor(_predicate) {
853
+ __publicField(this, "_predicate");
854
+ __publicField(this, "type", "function");
855
+ this._predicate = _predicate;
856
+ }
857
+ evaluate(context) {
858
+ return this._predicate(context);
859
+ }
860
+ };
861
+ __name(_FunctionCondition, "FunctionCondition");
862
+ var FunctionCondition = _FunctionCondition;
863
+ var _InputActionCondition = class _InputActionCondition {
864
+ constructor(_action, _checkPressed, _checkReleased) {
865
+ __publicField(this, "_action");
866
+ __publicField(this, "_checkPressed");
867
+ __publicField(this, "_checkReleased");
868
+ __publicField(this, "type", "inputAction");
869
+ this._action = _action;
870
+ this._checkPressed = _checkPressed;
871
+ this._checkReleased = _checkReleased;
872
+ }
873
+ evaluate(context) {
874
+ if (context.type !== "input") {
875
+ return false;
876
+ }
877
+ const inputContext = context;
878
+ if (inputContext.action !== this._action) {
879
+ return false;
880
+ }
881
+ if (this._checkPressed !== void 0 && inputContext.pressed !== this._checkPressed) {
882
+ return false;
883
+ }
884
+ if (this._checkReleased !== void 0 && inputContext.released !== this._checkReleased) {
885
+ return false;
886
+ }
887
+ return true;
888
+ }
889
+ };
890
+ __name(_InputActionCondition, "InputActionCondition");
891
+ var InputActionCondition = _InputActionCondition;
892
+ var _MessageNameCondition = class _MessageNameCondition {
893
+ constructor(_messageName) {
894
+ __publicField(this, "_messageName");
895
+ __publicField(this, "type", "messageName");
896
+ this._messageName = _messageName;
897
+ }
898
+ evaluate(context) {
899
+ if (context.type !== "message") {
900
+ return false;
901
+ }
902
+ const messageContext = context;
903
+ return messageContext.messageName === this._messageName;
904
+ }
905
+ };
906
+ __name(_MessageNameCondition, "MessageNameCondition");
907
+ var MessageNameCondition = _MessageNameCondition;
908
+ var _StateNameCondition = class _StateNameCondition {
909
+ constructor(_stateName, _checkCurrent = true) {
910
+ __publicField(this, "_stateName");
911
+ __publicField(this, "_checkCurrent");
912
+ __publicField(this, "type", "stateName");
913
+ this._stateName = _stateName;
914
+ this._checkCurrent = _checkCurrent;
915
+ }
916
+ evaluate(context) {
917
+ if (context.type !== "stateEnter" && context.type !== "stateExit") {
918
+ return false;
919
+ }
920
+ const stateContext = context;
921
+ if (this._checkCurrent) {
922
+ return stateContext.currentState === this._stateName;
923
+ } else {
924
+ return stateContext.previousState === this._stateName;
925
+ }
926
+ }
927
+ };
928
+ __name(_StateNameCondition, "StateNameCondition");
929
+ var StateNameCondition = _StateNameCondition;
930
+ var _TimerIdCondition = class _TimerIdCondition {
931
+ constructor(_timerId) {
932
+ __publicField(this, "_timerId");
933
+ __publicField(this, "type", "timerId");
934
+ this._timerId = _timerId;
935
+ }
936
+ evaluate(context) {
937
+ if (context.type !== "timer") {
938
+ return false;
939
+ }
940
+ const timerContext = context;
941
+ return timerContext.timerId === this._timerId;
942
+ }
943
+ };
944
+ __name(_TimerIdCondition, "TimerIdCondition");
945
+ var TimerIdCondition = _TimerIdCondition;
946
+ var _CollisionEntityCondition = class _CollisionEntityCondition {
947
+ constructor(_otherEntityId, _checkEnter, _checkExit) {
948
+ __publicField(this, "_otherEntityId");
949
+ __publicField(this, "_checkEnter");
950
+ __publicField(this, "_checkExit");
951
+ __publicField(this, "type", "collisionEntity");
952
+ this._otherEntityId = _otherEntityId;
953
+ this._checkEnter = _checkEnter;
954
+ this._checkExit = _checkExit;
955
+ }
956
+ evaluate(context) {
957
+ if (context.type !== "collision") {
958
+ return false;
959
+ }
960
+ const collisionContext = context;
961
+ if (this._otherEntityId !== void 0 && collisionContext.otherEntityId !== this._otherEntityId) {
962
+ return false;
963
+ }
964
+ if (this._checkEnter !== void 0 && collisionContext.isEnter !== this._checkEnter) {
965
+ return false;
966
+ }
967
+ if (this._checkExit !== void 0 && collisionContext.isExit !== this._checkExit) {
968
+ return false;
969
+ }
970
+ return true;
971
+ }
972
+ };
973
+ __name(_CollisionEntityCondition, "CollisionEntityCondition");
974
+ var CollisionEntityCondition = _CollisionEntityCondition;
975
+ var _CustomEventCondition = class _CustomEventCondition {
976
+ constructor(_eventName) {
977
+ __publicField(this, "_eventName");
978
+ __publicField(this, "type", "customEvent");
979
+ this._eventName = _eventName;
980
+ }
981
+ evaluate(context) {
982
+ if (context.type !== "custom") {
983
+ return false;
984
+ }
985
+ const customContext = context;
986
+ return customContext.eventName === this._eventName;
987
+ }
988
+ };
989
+ __name(_CustomEventCondition, "CustomEventCondition");
990
+ var CustomEventCondition = _CustomEventCondition;
991
+ var _ConditionBuilder = class _ConditionBuilder {
992
+ constructor() {
993
+ __publicField(this, "_conditions", []);
994
+ __publicField(this, "_logic", "and");
995
+ }
996
+ /**
997
+ * @zh 设置组合逻辑为 AND
998
+ * @en Set combination logic to AND
999
+ */
1000
+ and() {
1001
+ this._logic = "and";
1002
+ return this;
1003
+ }
1004
+ /**
1005
+ * @zh 设置组合逻辑为 OR
1006
+ * @en Set combination logic to OR
1007
+ */
1008
+ or() {
1009
+ this._logic = "or";
1010
+ return this;
1011
+ }
1012
+ /**
1013
+ * @zh 添加触发器类型条件
1014
+ * @en Add trigger type condition
1015
+ */
1016
+ ofType(...types) {
1017
+ this._conditions.push(new TriggerTypeCondition(types));
1018
+ return this;
1019
+ }
1020
+ /**
1021
+ * @zh 添加实体 ID 条件
1022
+ * @en Add entity ID condition
1023
+ */
1024
+ fromEntity(entityId) {
1025
+ this._conditions.push(new EntityIdCondition(entityId));
1026
+ return this;
1027
+ }
1028
+ /**
1029
+ * @zh 添加输入动作条件
1030
+ * @en Add input action condition
1031
+ */
1032
+ onInput(action, options) {
1033
+ this._conditions.push(new InputActionCondition(action, options?.pressed, options?.released));
1034
+ return this;
1035
+ }
1036
+ /**
1037
+ * @zh 添加消息条件
1038
+ * @en Add message condition
1039
+ */
1040
+ onMessage(messageName) {
1041
+ this._conditions.push(new MessageNameCondition(messageName));
1042
+ return this;
1043
+ }
1044
+ /**
1045
+ * @zh 添加状态条件
1046
+ * @en Add state condition
1047
+ */
1048
+ onState(stateName, checkCurrent = true) {
1049
+ this._conditions.push(new StateNameCondition(stateName, checkCurrent));
1050
+ return this;
1051
+ }
1052
+ /**
1053
+ * @zh 添加定时器条件
1054
+ * @en Add timer condition
1055
+ */
1056
+ onTimer(timerId) {
1057
+ this._conditions.push(new TimerIdCondition(timerId));
1058
+ return this;
1059
+ }
1060
+ /**
1061
+ * @zh 添加碰撞条件
1062
+ * @en Add collision condition
1063
+ */
1064
+ onCollision(options) {
1065
+ this._conditions.push(new CollisionEntityCondition(options?.entityId, options?.isEnter, options?.isExit));
1066
+ return this;
1067
+ }
1068
+ /**
1069
+ * @zh 添加自定义事件条件
1070
+ * @en Add custom event condition
1071
+ */
1072
+ onCustomEvent(eventName) {
1073
+ this._conditions.push(new CustomEventCondition(eventName));
1074
+ return this;
1075
+ }
1076
+ /**
1077
+ * @zh 添加自定义函数条件
1078
+ * @en Add custom function condition
1079
+ */
1080
+ where(predicate) {
1081
+ this._conditions.push(new FunctionCondition(predicate));
1082
+ return this;
1083
+ }
1084
+ /**
1085
+ * @zh 添加取反条件
1086
+ * @en Add negated condition
1087
+ */
1088
+ not(condition2) {
1089
+ this._conditions.push(new NotCondition(condition2));
1090
+ return this;
1091
+ }
1092
+ /**
1093
+ * @zh 构建条件
1094
+ * @en Build condition
1095
+ */
1096
+ build() {
1097
+ if (this._conditions.length === 0) {
1098
+ return new AlwaysTrueCondition();
1099
+ }
1100
+ if (this._conditions.length === 1) {
1101
+ return this._conditions[0];
1102
+ }
1103
+ return new CompositeCondition(this._conditions, this._logic);
1104
+ }
1105
+ };
1106
+ __name(_ConditionBuilder, "ConditionBuilder");
1107
+ var ConditionBuilder = _ConditionBuilder;
1108
+ function condition() {
1109
+ return new ConditionBuilder();
1110
+ }
1111
+ __name(condition, "condition");
1112
+
1113
+ // src/triggers/BlueprintTrigger.ts
1114
+ var _triggerId = 0;
1115
+ function generateTriggerId() {
1116
+ return `trigger_${++_triggerId}`;
1117
+ }
1118
+ __name(generateTriggerId, "generateTriggerId");
1119
+ var _BlueprintTrigger = class _BlueprintTrigger {
1120
+ constructor(config) {
1121
+ __publicField(this, "id");
1122
+ __publicField(this, "type");
1123
+ __publicField(this, "condition");
1124
+ __publicField(this, "priority");
1125
+ __publicField(this, "enabled");
1126
+ __publicField(this, "_callback");
1127
+ __publicField(this, "_callbacks", /* @__PURE__ */ new Set());
1128
+ this.id = config.id ?? generateTriggerId();
1129
+ this.type = config.type;
1130
+ this.condition = config.condition ?? new AlwaysTrueCondition();
1131
+ this.priority = config.priority ?? 0;
1132
+ this.enabled = config.enabled ?? true;
1133
+ this._callback = config.callback;
1134
+ }
1135
+ /**
1136
+ * @zh 检查是否应该触发
1137
+ * @en Check if should fire
1138
+ */
1139
+ shouldFire(context) {
1140
+ if (!this.enabled) {
1141
+ return false;
1142
+ }
1143
+ if (context.type !== this.type && this.type !== "custom") {
1144
+ return false;
1145
+ }
1146
+ return this.condition.evaluate(context);
1147
+ }
1148
+ /**
1149
+ * @zh 执行触发器
1150
+ * @en Execute trigger
1151
+ */
1152
+ fire(context) {
1153
+ if (this._callback) {
1154
+ this._callback(context);
1155
+ }
1156
+ for (const callback of this._callbacks) {
1157
+ callback(context);
1158
+ }
1159
+ }
1160
+ /**
1161
+ * @zh 添加回调
1162
+ * @en Add callback
1163
+ */
1164
+ addCallback(callback) {
1165
+ this._callbacks.add(callback);
1166
+ }
1167
+ /**
1168
+ * @zh 移除回调
1169
+ * @en Remove callback
1170
+ */
1171
+ removeCallback(callback) {
1172
+ this._callbacks.delete(callback);
1173
+ }
1174
+ /**
1175
+ * @zh 清除所有回调
1176
+ * @en Clear all callbacks
1177
+ */
1178
+ clearCallbacks() {
1179
+ this._callbacks.clear();
1180
+ }
1181
+ };
1182
+ __name(_BlueprintTrigger, "BlueprintTrigger");
1183
+ var BlueprintTrigger = _BlueprintTrigger;
1184
+ var _TriggerRegistry = class _TriggerRegistry {
1185
+ constructor() {
1186
+ __publicField(this, "_triggers", /* @__PURE__ */ new Map());
1187
+ __publicField(this, "_triggersByType", /* @__PURE__ */ new Map());
1188
+ }
1189
+ /**
1190
+ * @zh 注册触发器
1191
+ * @en Register trigger
1192
+ */
1193
+ register(trigger) {
1194
+ if (this._triggers.has(trigger.id)) {
1195
+ console.warn(`Trigger ${trigger.id} already registered, overwriting`);
1196
+ }
1197
+ this._triggers.set(trigger.id, trigger);
1198
+ if (!this._triggersByType.has(trigger.type)) {
1199
+ this._triggersByType.set(trigger.type, /* @__PURE__ */ new Set());
1200
+ }
1201
+ this._triggersByType.get(trigger.type).add(trigger.id);
1202
+ }
1203
+ /**
1204
+ * @zh 注销触发器
1205
+ * @en Unregister trigger
1206
+ */
1207
+ unregister(triggerId) {
1208
+ const trigger = this._triggers.get(triggerId);
1209
+ if (!trigger) {
1210
+ return false;
1211
+ }
1212
+ this._triggers.delete(triggerId);
1213
+ const typeSet = this._triggersByType.get(trigger.type);
1214
+ if (typeSet) {
1215
+ typeSet.delete(triggerId);
1216
+ }
1217
+ return true;
1218
+ }
1219
+ /**
1220
+ * @zh 获取触发器
1221
+ * @en Get trigger
1222
+ */
1223
+ get(triggerId) {
1224
+ return this._triggers.get(triggerId);
1225
+ }
1226
+ /**
1227
+ * @zh 获取所有触发器
1228
+ * @en Get all triggers
1229
+ */
1230
+ getAll() {
1231
+ return Array.from(this._triggers.values());
1232
+ }
1233
+ /**
1234
+ * @zh 按类型获取触发器
1235
+ * @en Get triggers by type
1236
+ */
1237
+ getByType(type) {
1238
+ const typeSet = this._triggersByType.get(type);
1239
+ if (!typeSet) {
1240
+ return [];
1241
+ }
1242
+ const triggers = [];
1243
+ for (const id of typeSet) {
1244
+ const trigger = this._triggers.get(id);
1245
+ if (trigger) {
1246
+ triggers.push(trigger);
1247
+ }
1248
+ }
1249
+ return triggers.sort((a, b) => b.priority - a.priority);
1250
+ }
1251
+ /**
1252
+ * @zh 清除所有触发器
1253
+ * @en Clear all triggers
1254
+ */
1255
+ clear() {
1256
+ this._triggers.clear();
1257
+ this._triggersByType.clear();
1258
+ }
1259
+ /**
1260
+ * @zh 获取触发器数量
1261
+ * @en Get trigger count
1262
+ */
1263
+ get count() {
1264
+ return this._triggers.size;
1265
+ }
1266
+ };
1267
+ __name(_TriggerRegistry, "TriggerRegistry");
1268
+ var TriggerRegistry = _TriggerRegistry;
1269
+ function createTrigger(config) {
1270
+ return new BlueprintTrigger(config);
1271
+ }
1272
+ __name(createTrigger, "createTrigger");
1273
+ function createTickTrigger(callback, options) {
1274
+ return new BlueprintTrigger({
1275
+ id: options?.id,
1276
+ type: "tick",
1277
+ condition: options?.condition,
1278
+ priority: options?.priority,
1279
+ callback
1280
+ });
1281
+ }
1282
+ __name(createTickTrigger, "createTickTrigger");
1283
+ function createInputTrigger(callback, options) {
1284
+ return new BlueprintTrigger({
1285
+ id: options?.id,
1286
+ type: "input",
1287
+ condition: options?.condition,
1288
+ priority: options?.priority,
1289
+ callback
1290
+ });
1291
+ }
1292
+ __name(createInputTrigger, "createInputTrigger");
1293
+ function createCollisionTrigger(callback, options) {
1294
+ return new BlueprintTrigger({
1295
+ id: options?.id,
1296
+ type: "collision",
1297
+ condition: options?.condition,
1298
+ priority: options?.priority,
1299
+ callback
1300
+ });
1301
+ }
1302
+ __name(createCollisionTrigger, "createCollisionTrigger");
1303
+ function createMessageTrigger(callback, options) {
1304
+ return new BlueprintTrigger({
1305
+ id: options?.id,
1306
+ type: "message",
1307
+ condition: options?.condition,
1308
+ priority: options?.priority,
1309
+ callback
1310
+ });
1311
+ }
1312
+ __name(createMessageTrigger, "createMessageTrigger");
1313
+ function createTimerTrigger(callback, options) {
1314
+ return new BlueprintTrigger({
1315
+ id: options?.id,
1316
+ type: "timer",
1317
+ condition: options?.condition,
1318
+ priority: options?.priority,
1319
+ callback
1320
+ });
1321
+ }
1322
+ __name(createTimerTrigger, "createTimerTrigger");
1323
+ function createStateEnterTrigger(callback, options) {
1324
+ return new BlueprintTrigger({
1325
+ id: options?.id,
1326
+ type: "stateEnter",
1327
+ condition: options?.condition,
1328
+ priority: options?.priority,
1329
+ callback
1330
+ });
1331
+ }
1332
+ __name(createStateEnterTrigger, "createStateEnterTrigger");
1333
+ function createStateExitTrigger(callback, options) {
1334
+ return new BlueprintTrigger({
1335
+ id: options?.id,
1336
+ type: "stateExit",
1337
+ condition: options?.condition,
1338
+ priority: options?.priority,
1339
+ callback
1340
+ });
1341
+ }
1342
+ __name(createStateExitTrigger, "createStateExitTrigger");
1343
+ function createCustomTrigger(callback, options) {
1344
+ return new BlueprintTrigger({
1345
+ id: options?.id,
1346
+ type: "custom",
1347
+ condition: options?.condition,
1348
+ priority: options?.priority,
1349
+ callback
1350
+ });
1351
+ }
1352
+ __name(createCustomTrigger, "createCustomTrigger");
1353
+
1354
+ // src/triggers/TriggerDispatcher.ts
1355
+ var _TriggerDispatcher = class _TriggerDispatcher {
1356
+ constructor(registry) {
1357
+ __publicField(this, "_registry");
1358
+ __publicField(this, "_typeSubscribers", /* @__PURE__ */ new Map());
1359
+ __publicField(this, "_globalSubscribers", /* @__PURE__ */ new Set());
1360
+ __publicField(this, "_isDispatching", false);
1361
+ __publicField(this, "_pendingContexts", []);
1362
+ this._registry = registry ?? new TriggerRegistry();
1363
+ }
1364
+ get registry() {
1365
+ return this._registry;
1366
+ }
1367
+ /**
1368
+ * @zh 调度触发器
1369
+ * @en Dispatch trigger
1370
+ */
1371
+ dispatch(context) {
1372
+ if (this._isDispatching) {
1373
+ this._pendingContexts.push(context);
1374
+ return {
1375
+ context,
1376
+ triggeredCount: 0,
1377
+ results: []
1378
+ };
1379
+ }
1380
+ this._isDispatching = true;
1381
+ try {
1382
+ const result = this._doDispatch(context);
1383
+ while (this._pendingContexts.length > 0) {
1384
+ const pendingContext = this._pendingContexts.shift();
1385
+ this._doDispatch(pendingContext);
1386
+ }
1387
+ return result;
1388
+ } finally {
1389
+ this._isDispatching = false;
1390
+ }
1391
+ }
1392
+ /**
1393
+ * @zh 执行调度
1394
+ * @en Do dispatch
1395
+ */
1396
+ _doDispatch(context) {
1397
+ const results = [];
1398
+ let triggeredCount = 0;
1399
+ const triggers = this._registry.getByType(context.type);
1400
+ for (const trigger of triggers) {
1401
+ if (trigger.shouldFire(context)) {
1402
+ try {
1403
+ trigger.fire(context);
1404
+ triggeredCount++;
1405
+ results.push({
1406
+ triggerId: trigger.id,
1407
+ success: true
1408
+ });
1409
+ } catch (error) {
1410
+ results.push({
1411
+ triggerId: trigger.id,
1412
+ success: false,
1413
+ error: error instanceof Error ? error.message : String(error)
1414
+ });
1415
+ }
1416
+ }
1417
+ }
1418
+ this._notifySubscribers(context);
1419
+ return {
1420
+ context,
1421
+ triggeredCount,
1422
+ results
1423
+ };
1424
+ }
1425
+ /**
1426
+ * @zh 通知订阅者
1427
+ * @en Notify subscribers
1428
+ */
1429
+ _notifySubscribers(context) {
1430
+ const typeSubscribers = this._typeSubscribers.get(context.type);
1431
+ if (typeSubscribers) {
1432
+ for (const callback of typeSubscribers) {
1433
+ try {
1434
+ callback(context);
1435
+ } catch (error) {
1436
+ console.error(`Trigger subscriber error: ${error}`);
1437
+ }
1438
+ }
1439
+ }
1440
+ for (const callback of this._globalSubscribers) {
1441
+ try {
1442
+ callback(context);
1443
+ } catch (error) {
1444
+ console.error(`Global trigger subscriber error: ${error}`);
1445
+ }
1446
+ }
1447
+ }
1448
+ /**
1449
+ * @zh 异步调度触发器
1450
+ * @en Async dispatch trigger
1451
+ */
1452
+ async dispatchAsync(context) {
1453
+ return new Promise((resolve) => {
1454
+ queueMicrotask(() => {
1455
+ resolve(this.dispatch(context));
1456
+ });
1457
+ });
1458
+ }
1459
+ /**
1460
+ * @zh 订阅触发器类型
1461
+ * @en Subscribe to trigger type
1462
+ */
1463
+ subscribe(type, callback) {
1464
+ if (!this._typeSubscribers.has(type)) {
1465
+ this._typeSubscribers.set(type, /* @__PURE__ */ new Set());
1466
+ }
1467
+ this._typeSubscribers.get(type).add(callback);
1468
+ return () => this.unsubscribe(type, callback);
1469
+ }
1470
+ /**
1471
+ * @zh 取消订阅
1472
+ * @en Unsubscribe
1473
+ */
1474
+ unsubscribe(type, callback) {
1475
+ const subscribers = this._typeSubscribers.get(type);
1476
+ if (subscribers) {
1477
+ subscribers.delete(callback);
1478
+ }
1479
+ }
1480
+ /**
1481
+ * @zh 订阅所有触发器
1482
+ * @en Subscribe to all triggers
1483
+ */
1484
+ subscribeAll(callback) {
1485
+ this._globalSubscribers.add(callback);
1486
+ return () => this.unsubscribeAll(callback);
1487
+ }
1488
+ /**
1489
+ * @zh 取消订阅所有
1490
+ * @en Unsubscribe from all
1491
+ */
1492
+ unsubscribeAll(callback) {
1493
+ this._globalSubscribers.delete(callback);
1494
+ }
1495
+ /**
1496
+ * @zh 清除所有订阅
1497
+ * @en Clear all subscriptions
1498
+ */
1499
+ clearSubscriptions() {
1500
+ this._typeSubscribers.clear();
1501
+ this._globalSubscribers.clear();
1502
+ }
1503
+ };
1504
+ __name(_TriggerDispatcher, "TriggerDispatcher");
1505
+ var TriggerDispatcher = _TriggerDispatcher;
1506
+ var _EntityTriggerManager = class _EntityTriggerManager {
1507
+ constructor(dispatcher) {
1508
+ __publicField(this, "_dispatcher");
1509
+ __publicField(this, "_entityTriggers", /* @__PURE__ */ new Map());
1510
+ this._dispatcher = dispatcher ?? new TriggerDispatcher();
1511
+ }
1512
+ get dispatcher() {
1513
+ return this._dispatcher;
1514
+ }
1515
+ /**
1516
+ * @zh 为实体注册触发器
1517
+ * @en Register trigger for entity
1518
+ */
1519
+ registerForEntity(entityId, trigger) {
1520
+ this._dispatcher.registry.register(trigger);
1521
+ if (!this._entityTriggers.has(entityId)) {
1522
+ this._entityTriggers.set(entityId, /* @__PURE__ */ new Set());
1523
+ }
1524
+ this._entityTriggers.get(entityId).add(trigger.id);
1525
+ }
1526
+ /**
1527
+ * @zh 注销实体的触发器
1528
+ * @en Unregister trigger from entity
1529
+ */
1530
+ unregisterFromEntity(entityId, triggerId) {
1531
+ const entitySet = this._entityTriggers.get(entityId);
1532
+ if (!entitySet) {
1533
+ return false;
1534
+ }
1535
+ if (!entitySet.has(triggerId)) {
1536
+ return false;
1537
+ }
1538
+ entitySet.delete(triggerId);
1539
+ return this._dispatcher.registry.unregister(triggerId);
1540
+ }
1541
+ /**
1542
+ * @zh 获取实体的所有触发器
1543
+ * @en Get all triggers for entity
1544
+ */
1545
+ getEntityTriggers(entityId) {
1546
+ const entitySet = this._entityTriggers.get(entityId);
1547
+ if (!entitySet) {
1548
+ return [];
1549
+ }
1550
+ const triggers = [];
1551
+ for (const triggerId of entitySet) {
1552
+ const trigger = this._dispatcher.registry.get(triggerId);
1553
+ if (trigger) {
1554
+ triggers.push(trigger);
1555
+ }
1556
+ }
1557
+ return triggers;
1558
+ }
1559
+ /**
1560
+ * @zh 清除实体的所有触发器
1561
+ * @en Clear all triggers for entity
1562
+ */
1563
+ clearEntityTriggers(entityId) {
1564
+ const entitySet = this._entityTriggers.get(entityId);
1565
+ if (!entitySet) {
1566
+ return;
1567
+ }
1568
+ for (const triggerId of entitySet) {
1569
+ this._dispatcher.registry.unregister(triggerId);
1570
+ }
1571
+ this._entityTriggers.delete(entityId);
1572
+ }
1573
+ /**
1574
+ * @zh 调度触发器到实体
1575
+ * @en Dispatch trigger to entity
1576
+ */
1577
+ dispatchToEntity(entityId, context) {
1578
+ const entityTriggers = this.getEntityTriggers(entityId);
1579
+ const results = [];
1580
+ let triggeredCount = 0;
1581
+ for (const trigger of entityTriggers) {
1582
+ if (trigger.shouldFire(context)) {
1583
+ try {
1584
+ trigger.fire(context);
1585
+ triggeredCount++;
1586
+ results.push({
1587
+ triggerId: trigger.id,
1588
+ success: true
1589
+ });
1590
+ } catch (error) {
1591
+ results.push({
1592
+ triggerId: trigger.id,
1593
+ success: false,
1594
+ error: error instanceof Error ? error.message : String(error)
1595
+ });
1596
+ }
1597
+ }
1598
+ }
1599
+ return {
1600
+ context,
1601
+ triggeredCount,
1602
+ results
1603
+ };
1604
+ }
1605
+ };
1606
+ __name(_EntityTriggerManager, "EntityTriggerManager");
1607
+ var EntityTriggerManager = _EntityTriggerManager;
1608
+ function createTriggerDispatcher(registry) {
1609
+ return new TriggerDispatcher(registry);
1610
+ }
1611
+ __name(createTriggerDispatcher, "createTriggerDispatcher");
1612
+ function createEntityTriggerManager(dispatcher) {
1613
+ return new EntityTriggerManager(dispatcher);
1614
+ }
1615
+ __name(createEntityTriggerManager, "createEntityTriggerManager");
1616
+
1617
+ // src/composition/BlueprintFragment.ts
1618
+ var _BlueprintFragment = class _BlueprintFragment {
1619
+ constructor(config) {
1620
+ __publicField(this, "id");
1621
+ __publicField(this, "name");
1622
+ __publicField(this, "description");
1623
+ __publicField(this, "category");
1624
+ __publicField(this, "tags");
1625
+ __publicField(this, "inputs");
1626
+ __publicField(this, "outputs");
1627
+ __publicField(this, "graph");
1628
+ __publicField(this, "version");
1629
+ __publicField(this, "icon");
1630
+ __publicField(this, "color");
1631
+ this.id = config.id;
1632
+ this.name = config.name;
1633
+ this.description = config.description;
1634
+ this.category = config.category;
1635
+ this.tags = config.tags;
1636
+ this.inputs = config.inputs ?? [];
1637
+ this.outputs = config.outputs ?? [];
1638
+ this.graph = config.graph;
1639
+ this.version = config.version;
1640
+ this.icon = config.icon;
1641
+ this.color = config.color;
1642
+ }
1643
+ /**
1644
+ * @zh 获取所有暴露引脚
1645
+ * @en Get all exposed pins
1646
+ */
1647
+ getAllExposedPins() {
1648
+ return [
1649
+ ...this.inputs,
1650
+ ...this.outputs
1651
+ ];
1652
+ }
1653
+ /**
1654
+ * @zh 通过名称查找输入引脚
1655
+ * @en Find input pin by name
1656
+ */
1657
+ findInput(name) {
1658
+ return this.inputs.find((p) => p.name === name);
1659
+ }
1660
+ /**
1661
+ * @zh 通过名称查找输出引脚
1662
+ * @en Find output pin by name
1663
+ */
1664
+ findOutput(name) {
1665
+ return this.outputs.find((p) => p.name === name);
1666
+ }
1667
+ };
1668
+ __name(_BlueprintFragment, "BlueprintFragment");
1669
+ var BlueprintFragment = _BlueprintFragment;
1670
+ function createExposedPin(name, type, direction, internalNodeId, internalPinName, options) {
1671
+ return {
1672
+ name,
1673
+ displayName: options?.displayName ?? name,
1674
+ type,
1675
+ direction,
1676
+ description: options?.description,
1677
+ defaultValue: options?.defaultValue,
1678
+ internalNodeId,
1679
+ internalPinName
1680
+ };
1681
+ }
1682
+ __name(createExposedPin, "createExposedPin");
1683
+ function createFragment(config) {
1684
+ return new BlueprintFragment(config);
1685
+ }
1686
+ __name(createFragment, "createFragment");
1687
+ function fragmentFromAsset(asset) {
1688
+ return new BlueprintFragment({
1689
+ ...asset.fragment,
1690
+ graph: asset.graph
1691
+ });
1692
+ }
1693
+ __name(fragmentFromAsset, "fragmentFromAsset");
1694
+ function fragmentToAsset(fragment) {
1695
+ return {
1696
+ version: 1,
1697
+ type: "blueprint-fragment",
1698
+ fragment: {
1699
+ id: fragment.id,
1700
+ name: fragment.name,
1701
+ description: fragment.description,
1702
+ category: fragment.category,
1703
+ tags: fragment.tags,
1704
+ inputs: fragment.inputs,
1705
+ outputs: fragment.outputs,
1706
+ version: fragment.version,
1707
+ icon: fragment.icon,
1708
+ color: fragment.color
1709
+ },
1710
+ graph: fragment.graph
1711
+ };
1712
+ }
1713
+ __name(fragmentToAsset, "fragmentToAsset");
1714
+
1715
+ // src/composition/BlueprintComposer.ts
1716
+ var _BlueprintComposer = class _BlueprintComposer {
1717
+ constructor(name) {
1718
+ __publicField(this, "name");
1719
+ __publicField(this, "slots", /* @__PURE__ */ new Map());
1720
+ __publicField(this, "connections", /* @__PURE__ */ new Map());
1721
+ __publicField(this, "connectionIdCounter", 0);
1722
+ this.name = name;
1723
+ }
1724
+ getSlots() {
1725
+ return Array.from(this.slots.values());
1726
+ }
1727
+ getConnections() {
1728
+ return Array.from(this.connections.values());
1729
+ }
1730
+ addFragment(fragment, slotId, options) {
1731
+ if (this.slots.has(slotId)) {
1732
+ throw new Error(`Slot '${slotId}' already exists`);
1733
+ }
1734
+ const slot = {
1735
+ id: slotId,
1736
+ name: options?.name ?? fragment.name,
1737
+ fragment,
1738
+ position: options?.position ?? {
1739
+ x: 0,
1740
+ y: 0
1741
+ }
1742
+ };
1743
+ this.slots.set(slotId, slot);
1744
+ }
1745
+ removeSlot(slotId) {
1746
+ if (!this.slots.has(slotId)) {
1747
+ return;
1748
+ }
1749
+ const toRemove = [];
1750
+ for (const [id, conn] of this.connections) {
1751
+ if (conn.fromSlotId === slotId || conn.toSlotId === slotId) {
1752
+ toRemove.push(id);
1753
+ }
1754
+ }
1755
+ for (const id of toRemove) {
1756
+ this.connections.delete(id);
1757
+ }
1758
+ this.slots.delete(slotId);
1759
+ }
1760
+ connect(fromSlotId, fromPin, toSlotId, toPin) {
1761
+ const fromSlot = this.slots.get(fromSlotId);
1762
+ const toSlot = this.slots.get(toSlotId);
1763
+ if (!fromSlot) {
1764
+ throw new Error(`Source slot '${fromSlotId}' not found`);
1765
+ }
1766
+ if (!toSlot) {
1767
+ throw new Error(`Target slot '${toSlotId}' not found`);
1768
+ }
1769
+ const fromPinDef = fromSlot.fragment.outputs.find((p) => p.name === fromPin);
1770
+ const toPinDef = toSlot.fragment.inputs.find((p) => p.name === toPin);
1771
+ if (!fromPinDef) {
1772
+ throw new Error(`Output pin '${fromPin}' not found in slot '${fromSlotId}'`);
1773
+ }
1774
+ if (!toPinDef) {
1775
+ throw new Error(`Input pin '${toPin}' not found in slot '${toSlotId}'`);
1776
+ }
1777
+ const connectionId = `conn_${++this.connectionIdCounter}`;
1778
+ const connection = {
1779
+ id: connectionId,
1780
+ fromSlotId,
1781
+ fromPin,
1782
+ toSlotId,
1783
+ toPin
1784
+ };
1785
+ this.connections.set(connectionId, connection);
1786
+ }
1787
+ disconnect(connectionId) {
1788
+ this.connections.delete(connectionId);
1789
+ }
1790
+ validate() {
1791
+ const errors = [];
1792
+ const warnings = [];
1793
+ for (const slot of this.slots.values()) {
1794
+ for (const input of slot.fragment.inputs) {
1795
+ const hasConnection = Array.from(this.connections.values()).some((c) => c.toSlotId === slot.id && c.toPin === input.name);
1796
+ if (!hasConnection && input.defaultValue === void 0) {
1797
+ warnings.push({
1798
+ type: "unconnected-input",
1799
+ message: `Input '${input.name}' in slot '${slot.id}' is not connected`,
1800
+ slotId: slot.id,
1801
+ pinName: input.name
1802
+ });
1803
+ }
1804
+ }
1805
+ for (const output of slot.fragment.outputs) {
1806
+ const hasConnection = Array.from(this.connections.values()).some((c) => c.fromSlotId === slot.id && c.fromPin === output.name);
1807
+ if (!hasConnection) {
1808
+ warnings.push({
1809
+ type: "unused-output",
1810
+ message: `Output '${output.name}' in slot '${slot.id}' is not connected`,
1811
+ slotId: slot.id,
1812
+ pinName: output.name
1813
+ });
1814
+ }
1815
+ }
1816
+ }
1817
+ for (const conn of this.connections.values()) {
1818
+ const fromSlot = this.slots.get(conn.fromSlotId);
1819
+ const toSlot = this.slots.get(conn.toSlotId);
1820
+ if (!fromSlot || !toSlot) {
1821
+ errors.push({
1822
+ type: "invalid-slot",
1823
+ message: `Invalid slot reference in connection '${conn.id}'`
1824
+ });
1825
+ continue;
1826
+ }
1827
+ const fromPinDef = fromSlot.fragment.outputs.find((p) => p.name === conn.fromPin);
1828
+ const toPinDef = toSlot.fragment.inputs.find((p) => p.name === conn.toPin);
1829
+ if (fromPinDef && toPinDef && fromPinDef.type !== toPinDef.type) {
1830
+ if (fromPinDef.type !== "any" && toPinDef.type !== "any") {
1831
+ errors.push({
1832
+ type: "type-mismatch",
1833
+ message: `Type mismatch: '${fromPinDef.type}' -> '${toPinDef.type}' in connection '${conn.id}'`
1834
+ });
1835
+ }
1836
+ }
1837
+ }
1838
+ return {
1839
+ isValid: errors.length === 0,
1840
+ errors,
1841
+ warnings
1842
+ };
1843
+ }
1844
+ compile() {
1845
+ const nodes = [];
1846
+ const connections = [];
1847
+ const variables = [];
1848
+ const nodeIdMap = /* @__PURE__ */ new Map();
1849
+ let nodeIdCounter = 0;
1850
+ for (const slot of this.slots.values()) {
1851
+ const slotNodeMap = /* @__PURE__ */ new Map();
1852
+ nodeIdMap.set(slot.id, slotNodeMap);
1853
+ for (const node of slot.fragment.graph.nodes) {
1854
+ const newNodeId = `node_${++nodeIdCounter}`;
1855
+ slotNodeMap.set(node.id, newNodeId);
1856
+ nodes.push({
1857
+ ...node,
1858
+ id: newNodeId,
1859
+ position: {
1860
+ x: node.position.x + slot.position.x,
1861
+ y: node.position.y + slot.position.y
1862
+ }
1863
+ });
1864
+ }
1865
+ for (const conn of slot.fragment.graph.connections) {
1866
+ const newFromId = slotNodeMap.get(conn.fromNodeId);
1867
+ const newToId = slotNodeMap.get(conn.toNodeId);
1868
+ if (newFromId && newToId) {
1869
+ connections.push({
1870
+ ...conn,
1871
+ id: `conn_internal_${connections.length}`,
1872
+ fromNodeId: newFromId,
1873
+ toNodeId: newToId
1874
+ });
1875
+ }
1876
+ }
1877
+ for (const variable of slot.fragment.graph.variables) {
1878
+ variables.push({
1879
+ ...variable,
1880
+ name: `${slot.id}_${variable.name}`
1881
+ });
1882
+ }
1883
+ }
1884
+ for (const slotConn of this.connections.values()) {
1885
+ const fromSlot = this.slots.get(slotConn.fromSlotId);
1886
+ const toSlot = this.slots.get(slotConn.toSlotId);
1887
+ if (!fromSlot || !toSlot) continue;
1888
+ const fromPinDef = fromSlot.fragment.outputs.find((p) => p.name === slotConn.fromPin);
1889
+ const toPinDef = toSlot.fragment.inputs.find((p) => p.name === slotConn.toPin);
1890
+ if (!fromPinDef || !toPinDef) continue;
1891
+ const fromNodeMap = nodeIdMap.get(slotConn.fromSlotId);
1892
+ const toNodeMap = nodeIdMap.get(slotConn.toSlotId);
1893
+ if (!fromNodeMap || !toNodeMap) continue;
1894
+ const fromNodeId = fromNodeMap.get(fromPinDef.internalNodeId);
1895
+ const toNodeId = toNodeMap.get(toPinDef.internalNodeId);
1896
+ if (fromNodeId && toNodeId) {
1897
+ connections.push({
1898
+ id: `conn_slot_${connections.length}`,
1899
+ fromNodeId,
1900
+ fromPin: fromPinDef.internalPinName,
1901
+ toNodeId,
1902
+ toPin: toPinDef.internalPinName
1903
+ });
1904
+ }
1905
+ }
1906
+ return {
1907
+ version: 1,
1908
+ type: "blueprint",
1909
+ metadata: {
1910
+ name: this.name,
1911
+ description: `Composed from ${this.slots.size} fragments`,
1912
+ createdAt: Date.now(),
1913
+ modifiedAt: Date.now()
1914
+ },
1915
+ variables,
1916
+ nodes,
1917
+ connections
1918
+ };
1919
+ }
1920
+ clear() {
1921
+ this.slots.clear();
1922
+ this.connections.clear();
1923
+ this.connectionIdCounter = 0;
1924
+ }
1925
+ };
1926
+ __name(_BlueprintComposer, "BlueprintComposer");
1927
+ var BlueprintComposer = _BlueprintComposer;
1928
+ function createComposer(name) {
1929
+ return new BlueprintComposer(name);
1930
+ }
1931
+ __name(createComposer, "createComposer");
1932
+
1933
+ // src/composition/FragmentRegistry.ts
1934
+ var _FragmentRegistry = class _FragmentRegistry {
1935
+ constructor() {
1936
+ __publicField(this, "fragments", /* @__PURE__ */ new Map());
1937
+ }
1938
+ register(fragment) {
1939
+ if (this.fragments.has(fragment.id)) {
1940
+ console.warn(`Fragment '${fragment.id}' already registered, overwriting`);
1941
+ }
1942
+ this.fragments.set(fragment.id, fragment);
1943
+ }
1944
+ unregister(id) {
1945
+ this.fragments.delete(id);
1946
+ }
1947
+ get(id) {
1948
+ return this.fragments.get(id);
1949
+ }
1950
+ has(id) {
1951
+ return this.fragments.has(id);
1952
+ }
1953
+ getAll() {
1954
+ return Array.from(this.fragments.values());
1955
+ }
1956
+ filter(filter) {
1957
+ let results = this.getAll();
1958
+ if (filter.category) {
1959
+ results = results.filter((f) => f.category === filter.category);
1960
+ }
1961
+ if (filter.tags && filter.tags.length > 0) {
1962
+ results = results.filter((f) => f.tags && filter.tags.some((t) => f.tags.includes(t)));
1963
+ }
1964
+ if (filter.search) {
1965
+ const searchLower = filter.search.toLowerCase();
1966
+ results = results.filter((f) => f.name.toLowerCase().includes(searchLower) || f.description?.toLowerCase().includes(searchLower));
1967
+ }
1968
+ return results;
1969
+ }
1970
+ getCategories() {
1971
+ const categories = /* @__PURE__ */ new Set();
1972
+ for (const fragment of this.fragments.values()) {
1973
+ if (fragment.category) {
1974
+ categories.add(fragment.category);
1975
+ }
1976
+ }
1977
+ return Array.from(categories).sort();
1978
+ }
1979
+ getTags() {
1980
+ const tags = /* @__PURE__ */ new Set();
1981
+ for (const fragment of this.fragments.values()) {
1982
+ if (fragment.tags) {
1983
+ for (const tag of fragment.tags) {
1984
+ tags.add(tag);
1985
+ }
1986
+ }
1987
+ }
1988
+ return Array.from(tags).sort();
1989
+ }
1990
+ clear() {
1991
+ this.fragments.clear();
1992
+ }
1993
+ /**
1994
+ * @zh 获取片段数量
1995
+ * @en Get fragment count
1996
+ */
1997
+ get size() {
1998
+ return this.fragments.size;
1999
+ }
2000
+ };
2001
+ __name(_FragmentRegistry, "FragmentRegistry");
2002
+ var FragmentRegistry = _FragmentRegistry;
2003
+ var defaultFragmentRegistry = new FragmentRegistry();
2004
+ function createFragmentRegistry() {
2005
+ return new FragmentRegistry();
2006
+ }
2007
+ __name(createFragmentRegistry, "createFragmentRegistry");
2008
+
2009
+ // src/nodes/events/EventBeginPlay.ts
2010
+ function _ts_decorate(decorators, target, key, desc) {
2011
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2012
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
2013
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
2014
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
2015
+ }
2016
+ __name(_ts_decorate, "_ts_decorate");
2017
+ var EventBeginPlayTemplate = {
2018
+ type: "EventBeginPlay",
2019
+ title: "Event Begin Play",
2020
+ category: "event",
2021
+ color: "#CC0000",
2022
+ description: "Triggered once when the blueprint starts executing (\u84DD\u56FE\u5F00\u59CB\u6267\u884C\u65F6\u89E6\u53D1\u4E00\u6B21)",
2023
+ keywords: [
2024
+ "start",
2025
+ "begin",
2026
+ "init",
2027
+ "event"
2028
+ ],
2029
+ inputs: [],
2030
+ outputs: [
2031
+ {
2032
+ name: "exec",
2033
+ type: "exec",
2034
+ displayName: ""
2035
+ }
2036
+ ]
2037
+ };
2038
+ var _EventBeginPlayExecutor = class _EventBeginPlayExecutor {
2039
+ execute(_node, _context) {
2040
+ return {
2041
+ nextExec: "exec"
2042
+ };
2043
+ }
2044
+ };
2045
+ __name(_EventBeginPlayExecutor, "EventBeginPlayExecutor");
2046
+ var EventBeginPlayExecutor = _EventBeginPlayExecutor;
2047
+ EventBeginPlayExecutor = _ts_decorate([
2048
+ RegisterNode(EventBeginPlayTemplate)
2049
+ ], EventBeginPlayExecutor);
2050
+
2051
+ // src/nodes/events/EventTick.ts
2052
+ function _ts_decorate2(decorators, target, key, desc) {
2053
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2054
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
2055
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
2056
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
2057
+ }
2058
+ __name(_ts_decorate2, "_ts_decorate");
2059
+ var EventTickTemplate = {
2060
+ type: "EventTick",
2061
+ title: "Event Tick",
2062
+ category: "event",
2063
+ color: "#CC0000",
2064
+ description: "Triggered every frame during execution (\u6267\u884C\u671F\u95F4\u6BCF\u5E27\u89E6\u53D1)",
2065
+ keywords: [
2066
+ "update",
2067
+ "frame",
2068
+ "tick",
2069
+ "event"
2070
+ ],
2071
+ inputs: [],
2072
+ outputs: [
2073
+ {
2074
+ name: "exec",
2075
+ type: "exec",
2076
+ displayName: ""
2077
+ },
2078
+ {
2079
+ name: "deltaTime",
2080
+ type: "float",
2081
+ displayName: "Delta Seconds"
2082
+ }
2083
+ ]
2084
+ };
2085
+ var _EventTickExecutor = class _EventTickExecutor {
2086
+ execute(_node, context) {
2087
+ return {
2088
+ nextExec: "exec",
2089
+ outputs: {
2090
+ deltaTime: context.deltaTime
2091
+ }
2092
+ };
2093
+ }
2094
+ };
2095
+ __name(_EventTickExecutor, "EventTickExecutor");
2096
+ var EventTickExecutor = _EventTickExecutor;
2097
+ EventTickExecutor = _ts_decorate2([
2098
+ RegisterNode(EventTickTemplate)
2099
+ ], EventTickExecutor);
2100
+
2101
+ // src/nodes/events/EventEndPlay.ts
2102
+ function _ts_decorate3(decorators, target, key, desc) {
2103
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2104
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
2105
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
2106
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
2107
+ }
2108
+ __name(_ts_decorate3, "_ts_decorate");
2109
+ var EventEndPlayTemplate = {
2110
+ type: "EventEndPlay",
2111
+ title: "Event End Play",
2112
+ category: "event",
2113
+ color: "#CC0000",
2114
+ description: "Triggered once when the blueprint stops executing (\u84DD\u56FE\u505C\u6B62\u6267\u884C\u65F6\u89E6\u53D1\u4E00\u6B21)",
2115
+ keywords: [
2116
+ "stop",
2117
+ "end",
2118
+ "destroy",
2119
+ "event"
2120
+ ],
2121
+ inputs: [],
2122
+ outputs: [
2123
+ {
2124
+ name: "exec",
2125
+ type: "exec",
2126
+ displayName: ""
2127
+ }
2128
+ ]
2129
+ };
2130
+ var _EventEndPlayExecutor = class _EventEndPlayExecutor {
2131
+ execute(_node, _context) {
2132
+ return {
2133
+ nextExec: "exec"
2134
+ };
2135
+ }
2136
+ };
2137
+ __name(_EventEndPlayExecutor, "EventEndPlayExecutor");
2138
+ var EventEndPlayExecutor = _EventEndPlayExecutor;
2139
+ EventEndPlayExecutor = _ts_decorate3([
2140
+ RegisterNode(EventEndPlayTemplate)
2141
+ ], EventEndPlayExecutor);
2142
+
2143
+ // src/nodes/events/EventInput.ts
2144
+ function _ts_decorate4(decorators, target, key, desc) {
2145
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2146
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
2147
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
2148
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
2149
+ }
2150
+ __name(_ts_decorate4, "_ts_decorate");
2151
+ var EventInputTemplate = {
2152
+ type: "EventInput",
2153
+ title: "Event Input",
2154
+ category: "event",
2155
+ color: "#CC0000",
2156
+ description: "Triggered when input action occurs / \u8F93\u5165\u52A8\u4F5C\u53D1\u751F\u65F6\u89E6\u53D1",
2157
+ keywords: [
2158
+ "input",
2159
+ "key",
2160
+ "button",
2161
+ "action",
2162
+ "event"
2163
+ ],
2164
+ menuPath: [
2165
+ "Event",
2166
+ "Input"
2167
+ ],
2168
+ inputs: [
2169
+ {
2170
+ name: "action",
2171
+ type: "string",
2172
+ displayName: "Action",
2173
+ defaultValue: ""
2174
+ }
2175
+ ],
2176
+ outputs: [
2177
+ {
2178
+ name: "exec",
2179
+ type: "exec",
2180
+ displayName: ""
2181
+ },
2182
+ {
2183
+ name: "action",
2184
+ type: "string",
2185
+ displayName: "Action"
2186
+ },
2187
+ {
2188
+ name: "value",
2189
+ type: "float",
2190
+ displayName: "Value"
2191
+ },
2192
+ {
2193
+ name: "pressed",
2194
+ type: "bool",
2195
+ displayName: "Pressed"
2196
+ },
2197
+ {
2198
+ name: "released",
2199
+ type: "bool",
2200
+ displayName: "Released"
2201
+ }
2202
+ ]
2203
+ };
2204
+ var _EventInputExecutor = class _EventInputExecutor {
2205
+ execute(node, _context) {
2206
+ return {
2207
+ nextExec: "exec",
2208
+ outputs: {
2209
+ action: node.data?.action ?? "",
2210
+ value: 0,
2211
+ pressed: false,
2212
+ released: false
2213
+ }
2214
+ };
2215
+ }
2216
+ };
2217
+ __name(_EventInputExecutor, "EventInputExecutor");
2218
+ var EventInputExecutor = _EventInputExecutor;
2219
+ EventInputExecutor = _ts_decorate4([
2220
+ RegisterNode(EventInputTemplate)
2221
+ ], EventInputExecutor);
2222
+
2223
+ // src/nodes/events/EventCollision.ts
2224
+ function _ts_decorate5(decorators, target, key, desc) {
2225
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2226
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
2227
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
2228
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
2229
+ }
2230
+ __name(_ts_decorate5, "_ts_decorate");
2231
+ var EventCollisionEnterTemplate = {
2232
+ type: "EventCollisionEnter",
2233
+ title: "Event Collision Enter",
2234
+ category: "event",
2235
+ color: "#CC0000",
2236
+ description: "Triggered when collision starts / \u78B0\u649E\u5F00\u59CB\u65F6\u89E6\u53D1",
2237
+ keywords: [
2238
+ "collision",
2239
+ "enter",
2240
+ "hit",
2241
+ "overlap",
2242
+ "event"
2243
+ ],
2244
+ menuPath: [
2245
+ "Event",
2246
+ "Collision",
2247
+ "Enter"
2248
+ ],
2249
+ inputs: [],
2250
+ outputs: [
2251
+ {
2252
+ name: "exec",
2253
+ type: "exec",
2254
+ displayName: ""
2255
+ },
2256
+ {
2257
+ name: "otherEntityId",
2258
+ type: "string",
2259
+ displayName: "Other Entity"
2260
+ },
2261
+ {
2262
+ name: "pointX",
2263
+ type: "float",
2264
+ displayName: "Point X"
2265
+ },
2266
+ {
2267
+ name: "pointY",
2268
+ type: "float",
2269
+ displayName: "Point Y"
2270
+ },
2271
+ {
2272
+ name: "normalX",
2273
+ type: "float",
2274
+ displayName: "Normal X"
2275
+ },
2276
+ {
2277
+ name: "normalY",
2278
+ type: "float",
2279
+ displayName: "Normal Y"
2280
+ }
2281
+ ]
2282
+ };
2283
+ var _EventCollisionEnterExecutor = class _EventCollisionEnterExecutor {
2284
+ execute(_node) {
2285
+ return {
2286
+ nextExec: "exec",
2287
+ outputs: {
2288
+ otherEntityId: "",
2289
+ pointX: 0,
2290
+ pointY: 0,
2291
+ normalX: 0,
2292
+ normalY: 0
2293
+ }
2294
+ };
2295
+ }
2296
+ };
2297
+ __name(_EventCollisionEnterExecutor, "EventCollisionEnterExecutor");
2298
+ var EventCollisionEnterExecutor = _EventCollisionEnterExecutor;
2299
+ EventCollisionEnterExecutor = _ts_decorate5([
2300
+ RegisterNode(EventCollisionEnterTemplate)
2301
+ ], EventCollisionEnterExecutor);
2302
+ var EventCollisionExitTemplate = {
2303
+ type: "EventCollisionExit",
2304
+ title: "Event Collision Exit",
2305
+ category: "event",
2306
+ color: "#CC0000",
2307
+ description: "Triggered when collision ends / \u78B0\u649E\u7ED3\u675F\u65F6\u89E6\u53D1",
2308
+ keywords: [
2309
+ "collision",
2310
+ "exit",
2311
+ "end",
2312
+ "separate",
2313
+ "event"
2314
+ ],
2315
+ menuPath: [
2316
+ "Event",
2317
+ "Collision",
2318
+ "Exit"
2319
+ ],
2320
+ inputs: [],
2321
+ outputs: [
2322
+ {
2323
+ name: "exec",
2324
+ type: "exec",
2325
+ displayName: ""
2326
+ },
2327
+ {
2328
+ name: "otherEntityId",
2329
+ type: "string",
2330
+ displayName: "Other Entity"
2331
+ }
2332
+ ]
2333
+ };
2334
+ var _EventCollisionExitExecutor = class _EventCollisionExitExecutor {
2335
+ execute(_node) {
2336
+ return {
2337
+ nextExec: "exec",
2338
+ outputs: {
2339
+ otherEntityId: ""
2340
+ }
2341
+ };
2342
+ }
2343
+ };
2344
+ __name(_EventCollisionExitExecutor, "EventCollisionExitExecutor");
2345
+ var EventCollisionExitExecutor = _EventCollisionExitExecutor;
2346
+ EventCollisionExitExecutor = _ts_decorate5([
2347
+ RegisterNode(EventCollisionExitTemplate)
2348
+ ], EventCollisionExitExecutor);
2349
+
2350
+ // src/nodes/events/EventMessage.ts
2351
+ function _ts_decorate6(decorators, target, key, desc) {
2352
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2353
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
2354
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
2355
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
2356
+ }
2357
+ __name(_ts_decorate6, "_ts_decorate");
2358
+ var EventMessageTemplate = {
2359
+ type: "EventMessage",
2360
+ title: "Event Message",
2361
+ category: "event",
2362
+ color: "#CC0000",
2363
+ description: "Triggered when a message is received / \u63A5\u6536\u5230\u6D88\u606F\u65F6\u89E6\u53D1",
2364
+ keywords: [
2365
+ "message",
2366
+ "receive",
2367
+ "broadcast",
2368
+ "event",
2369
+ "signal"
2370
+ ],
2371
+ menuPath: [
2372
+ "Event",
2373
+ "Message"
2374
+ ],
2375
+ inputs: [
2376
+ {
2377
+ name: "messageName",
2378
+ type: "string",
2379
+ displayName: "Message Name",
2380
+ defaultValue: ""
2381
+ }
2382
+ ],
2383
+ outputs: [
2384
+ {
2385
+ name: "exec",
2386
+ type: "exec",
2387
+ displayName: ""
2388
+ },
2389
+ {
2390
+ name: "messageName",
2391
+ type: "string",
2392
+ displayName: "Message"
2393
+ },
2394
+ {
2395
+ name: "senderId",
2396
+ type: "string",
2397
+ displayName: "Sender ID"
2398
+ },
2399
+ {
2400
+ name: "payload",
2401
+ type: "any",
2402
+ displayName: "Payload"
2403
+ }
2404
+ ]
2405
+ };
2406
+ var _EventMessageExecutor = class _EventMessageExecutor {
2407
+ execute(node) {
2408
+ return {
2409
+ nextExec: "exec",
2410
+ outputs: {
2411
+ messageName: node.data?.messageName ?? "",
2412
+ senderId: "",
2413
+ payload: null
2414
+ }
2415
+ };
2416
+ }
2417
+ };
2418
+ __name(_EventMessageExecutor, "EventMessageExecutor");
2419
+ var EventMessageExecutor = _EventMessageExecutor;
2420
+ EventMessageExecutor = _ts_decorate6([
2421
+ RegisterNode(EventMessageTemplate)
2422
+ ], EventMessageExecutor);
2423
+
2424
+ // src/nodes/events/EventTimer.ts
2425
+ function _ts_decorate7(decorators, target, key, desc) {
2426
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2427
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
2428
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
2429
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
2430
+ }
2431
+ __name(_ts_decorate7, "_ts_decorate");
2432
+ var EventTimerTemplate = {
2433
+ type: "EventTimer",
2434
+ title: "Event Timer",
2435
+ category: "event",
2436
+ color: "#CC0000",
2437
+ description: "Triggered when a timer fires / \u5B9A\u65F6\u5668\u89E6\u53D1\u65F6\u6267\u884C",
2438
+ keywords: [
2439
+ "timer",
2440
+ "delay",
2441
+ "schedule",
2442
+ "event",
2443
+ "interval"
2444
+ ],
2445
+ menuPath: [
2446
+ "Event",
2447
+ "Timer"
2448
+ ],
2449
+ inputs: [
2450
+ {
2451
+ name: "timerId",
2452
+ type: "string",
2453
+ displayName: "Timer ID",
2454
+ defaultValue: ""
2455
+ }
2456
+ ],
2457
+ outputs: [
2458
+ {
2459
+ name: "exec",
2460
+ type: "exec",
2461
+ displayName: ""
2462
+ },
2463
+ {
2464
+ name: "timerId",
2465
+ type: "string",
2466
+ displayName: "Timer ID"
2467
+ },
2468
+ {
2469
+ name: "isRepeating",
2470
+ type: "bool",
2471
+ displayName: "Is Repeating"
2472
+ },
2473
+ {
2474
+ name: "timesFired",
2475
+ type: "int",
2476
+ displayName: "Times Fired"
2477
+ }
2478
+ ]
2479
+ };
2480
+ var _EventTimerExecutor = class _EventTimerExecutor {
2481
+ execute(node) {
2482
+ return {
2483
+ nextExec: "exec",
2484
+ outputs: {
2485
+ timerId: node.data?.timerId ?? "",
2486
+ isRepeating: false,
2487
+ timesFired: 0
2488
+ }
2489
+ };
2490
+ }
2491
+ };
2492
+ __name(_EventTimerExecutor, "EventTimerExecutor");
2493
+ var EventTimerExecutor = _EventTimerExecutor;
2494
+ EventTimerExecutor = _ts_decorate7([
2495
+ RegisterNode(EventTimerTemplate)
2496
+ ], EventTimerExecutor);
2497
+
2498
+ // src/nodes/events/EventState.ts
2499
+ function _ts_decorate8(decorators, target, key, desc) {
2500
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2501
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
2502
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
2503
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
2504
+ }
2505
+ __name(_ts_decorate8, "_ts_decorate");
2506
+ var EventStateEnterTemplate = {
2507
+ type: "EventStateEnter",
2508
+ title: "Event State Enter",
2509
+ category: "event",
2510
+ color: "#CC0000",
2511
+ description: "Triggered when entering a state / \u8FDB\u5165\u72B6\u6001\u65F6\u89E6\u53D1",
2512
+ keywords: [
2513
+ "state",
2514
+ "enter",
2515
+ "fsm",
2516
+ "machine",
2517
+ "event"
2518
+ ],
2519
+ menuPath: [
2520
+ "Event",
2521
+ "State",
2522
+ "Enter"
2523
+ ],
2524
+ inputs: [
2525
+ {
2526
+ name: "stateName",
2527
+ type: "string",
2528
+ displayName: "State Name",
2529
+ defaultValue: ""
2530
+ }
2531
+ ],
2532
+ outputs: [
2533
+ {
2534
+ name: "exec",
2535
+ type: "exec",
2536
+ displayName: ""
2537
+ },
2538
+ {
2539
+ name: "stateMachineId",
2540
+ type: "string",
2541
+ displayName: "State Machine"
2542
+ },
2543
+ {
2544
+ name: "currentState",
2545
+ type: "string",
2546
+ displayName: "Current State"
2547
+ },
2548
+ {
2549
+ name: "previousState",
2550
+ type: "string",
2551
+ displayName: "Previous State"
2552
+ }
2553
+ ]
2554
+ };
2555
+ var _EventStateEnterExecutor = class _EventStateEnterExecutor {
2556
+ execute(node) {
2557
+ return {
2558
+ nextExec: "exec",
2559
+ outputs: {
2560
+ stateMachineId: "",
2561
+ currentState: node.data?.stateName ?? "",
2562
+ previousState: ""
2563
+ }
2564
+ };
2565
+ }
2566
+ };
2567
+ __name(_EventStateEnterExecutor, "EventStateEnterExecutor");
2568
+ var EventStateEnterExecutor = _EventStateEnterExecutor;
2569
+ EventStateEnterExecutor = _ts_decorate8([
2570
+ RegisterNode(EventStateEnterTemplate)
2571
+ ], EventStateEnterExecutor);
2572
+ var EventStateExitTemplate = {
2573
+ type: "EventStateExit",
2574
+ title: "Event State Exit",
2575
+ category: "event",
2576
+ color: "#CC0000",
2577
+ description: "Triggered when exiting a state / \u9000\u51FA\u72B6\u6001\u65F6\u89E6\u53D1",
2578
+ keywords: [
2579
+ "state",
2580
+ "exit",
2581
+ "leave",
2582
+ "fsm",
2583
+ "machine",
2584
+ "event"
2585
+ ],
2586
+ menuPath: [
2587
+ "Event",
2588
+ "State",
2589
+ "Exit"
2590
+ ],
2591
+ inputs: [
2592
+ {
2593
+ name: "stateName",
2594
+ type: "string",
2595
+ displayName: "State Name",
2596
+ defaultValue: ""
2597
+ }
2598
+ ],
2599
+ outputs: [
2600
+ {
2601
+ name: "exec",
2602
+ type: "exec",
2603
+ displayName: ""
2604
+ },
2605
+ {
2606
+ name: "stateMachineId",
2607
+ type: "string",
2608
+ displayName: "State Machine"
2609
+ },
2610
+ {
2611
+ name: "currentState",
2612
+ type: "string",
2613
+ displayName: "Current State"
2614
+ },
2615
+ {
2616
+ name: "previousState",
2617
+ type: "string",
2618
+ displayName: "Previous State"
2619
+ }
2620
+ ]
2621
+ };
2622
+ var _EventStateExitExecutor = class _EventStateExitExecutor {
2623
+ execute(node) {
2624
+ return {
2625
+ nextExec: "exec",
2626
+ outputs: {
2627
+ stateMachineId: "",
2628
+ currentState: "",
2629
+ previousState: node.data?.stateName ?? ""
2630
+ }
2631
+ };
2632
+ }
2633
+ };
2634
+ __name(_EventStateExitExecutor, "EventStateExitExecutor");
2635
+ var EventStateExitExecutor = _EventStateExitExecutor;
2636
+ EventStateExitExecutor = _ts_decorate8([
2637
+ RegisterNode(EventStateExitTemplate)
2638
+ ], EventStateExitExecutor);
2639
+
2640
+ // src/nodes/debug/Print.ts
2641
+ function _ts_decorate9(decorators, target, key, desc) {
2642
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2643
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
2644
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
2645
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
2646
+ }
2647
+ __name(_ts_decorate9, "_ts_decorate");
2648
+ var PrintTemplate = {
2649
+ type: "Print",
2650
+ title: "Print String",
2651
+ category: "debug",
2652
+ color: "#785EF0",
2653
+ description: "Prints a message to the console for debugging (\u6253\u5370\u6D88\u606F\u5230\u63A7\u5236\u53F0\u7528\u4E8E\u8C03\u8BD5)",
2654
+ keywords: [
2655
+ "log",
2656
+ "debug",
2657
+ "console",
2658
+ "output",
2659
+ "print"
2660
+ ],
2661
+ inputs: [
2662
+ {
2663
+ name: "exec",
2664
+ type: "exec",
2665
+ displayName: ""
2666
+ },
2667
+ {
2668
+ name: "message",
2669
+ type: "string",
2670
+ displayName: "Message",
2671
+ defaultValue: "Hello Blueprint!"
2672
+ },
2673
+ {
2674
+ name: "printToScreen",
2675
+ type: "bool",
2676
+ displayName: "Print to Screen",
2677
+ defaultValue: true
2678
+ },
2679
+ {
2680
+ name: "duration",
2681
+ type: "float",
2682
+ displayName: "Duration",
2683
+ defaultValue: 2
2684
+ }
2685
+ ],
2686
+ outputs: [
2687
+ {
2688
+ name: "exec",
2689
+ type: "exec",
2690
+ displayName: ""
2691
+ }
2692
+ ]
2693
+ };
2694
+ var _PrintExecutor = class _PrintExecutor {
2695
+ execute(node, context) {
2696
+ const message = context.evaluateInput(node.id, "message", "Hello Blueprint!");
2697
+ const printToScreen = context.evaluateInput(node.id, "printToScreen", true);
2698
+ const duration = context.evaluateInput(node.id, "duration", 2);
2699
+ console.log(`[Blueprint] ${message}`);
2700
+ if (printToScreen) {
2701
+ const event = new CustomEvent("blueprint:print", {
2702
+ detail: {
2703
+ message: String(message),
2704
+ duration: Number(duration),
2705
+ entityId: context.entity.id,
2706
+ entityName: context.entity.name
2707
+ }
2708
+ });
2709
+ if (typeof window !== "undefined") {
2710
+ window.dispatchEvent(event);
2711
+ }
2712
+ }
2713
+ return {
2714
+ nextExec: "exec"
2715
+ };
2716
+ }
2717
+ };
2718
+ __name(_PrintExecutor, "PrintExecutor");
2719
+ var PrintExecutor = _PrintExecutor;
2720
+ PrintExecutor = _ts_decorate9([
2721
+ RegisterNode(PrintTemplate)
2722
+ ], PrintExecutor);
2723
+
2724
+ // src/nodes/time/GetDeltaTime.ts
2725
+ function _ts_decorate10(decorators, target, key, desc) {
2726
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2727
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
2728
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
2729
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
2730
+ }
2731
+ __name(_ts_decorate10, "_ts_decorate");
2732
+ var GetDeltaTimeTemplate = {
2733
+ type: "GetDeltaTime",
2734
+ title: "Get Delta Time",
2735
+ category: "time",
2736
+ color: "#4FC3F7",
2737
+ description: "Returns the time elapsed since the last frame in seconds (\u8FD4\u56DE\u4E0A\u4E00\u5E27\u4EE5\u6765\u7ECF\u8FC7\u7684\u65F6\u95F4\uFF0C\u5355\u4F4D\u79D2)",
2738
+ keywords: [
2739
+ "delta",
2740
+ "time",
2741
+ "frame",
2742
+ "dt"
2743
+ ],
2744
+ isPure: true,
2745
+ inputs: [],
2746
+ outputs: [
2747
+ {
2748
+ name: "deltaTime",
2749
+ type: "float",
2750
+ displayName: "Delta Seconds"
2751
+ }
2752
+ ]
2753
+ };
2754
+ var _GetDeltaTimeExecutor = class _GetDeltaTimeExecutor {
2755
+ execute(_node, context) {
2756
+ return {
2757
+ outputs: {
2758
+ deltaTime: context.deltaTime
2759
+ }
2760
+ };
2761
+ }
2762
+ };
2763
+ __name(_GetDeltaTimeExecutor, "GetDeltaTimeExecutor");
2764
+ var GetDeltaTimeExecutor = _GetDeltaTimeExecutor;
2765
+ GetDeltaTimeExecutor = _ts_decorate10([
2766
+ RegisterNode(GetDeltaTimeTemplate)
2767
+ ], GetDeltaTimeExecutor);
2768
+
2769
+ // src/nodes/time/GetTime.ts
2770
+ function _ts_decorate11(decorators, target, key, desc) {
2771
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2772
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
2773
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
2774
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
2775
+ }
2776
+ __name(_ts_decorate11, "_ts_decorate");
2777
+ var GetTimeTemplate = {
2778
+ type: "GetTime",
2779
+ title: "Get Game Time",
2780
+ category: "time",
2781
+ color: "#4FC3F7",
2782
+ description: "Returns the total time since the blueprint started in seconds (\u8FD4\u56DE\u84DD\u56FE\u542F\u52A8\u4EE5\u6765\u7684\u603B\u65F6\u95F4\uFF0C\u5355\u4F4D\u79D2)",
2783
+ keywords: [
2784
+ "time",
2785
+ "total",
2786
+ "elapsed",
2787
+ "game"
2788
+ ],
2789
+ isPure: true,
2790
+ inputs: [],
2791
+ outputs: [
2792
+ {
2793
+ name: "time",
2794
+ type: "float",
2795
+ displayName: "Seconds"
2796
+ }
2797
+ ]
2798
+ };
2799
+ var _GetTimeExecutor = class _GetTimeExecutor {
2800
+ execute(_node, context) {
2801
+ return {
2802
+ outputs: {
2803
+ time: context.time
2804
+ }
2805
+ };
2806
+ }
2807
+ };
2808
+ __name(_GetTimeExecutor, "GetTimeExecutor");
2809
+ var GetTimeExecutor = _GetTimeExecutor;
2810
+ GetTimeExecutor = _ts_decorate11([
2811
+ RegisterNode(GetTimeTemplate)
2812
+ ], GetTimeExecutor);
2813
+
2814
+ // src/nodes/time/Delay.ts
2815
+ function _ts_decorate12(decorators, target, key, desc) {
2816
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2817
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
2818
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
2819
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
2820
+ }
2821
+ __name(_ts_decorate12, "_ts_decorate");
2822
+ var DelayTemplate = {
2823
+ type: "Delay",
2824
+ title: "Delay",
2825
+ category: "flow",
2826
+ color: "#FFFFFF",
2827
+ description: "Pauses execution for a specified number of seconds (\u6682\u505C\u6267\u884C\u6307\u5B9A\u7684\u79D2\u6570)",
2828
+ keywords: [
2829
+ "wait",
2830
+ "delay",
2831
+ "pause",
2832
+ "sleep",
2833
+ "timer"
2834
+ ],
2835
+ inputs: [
2836
+ {
2837
+ name: "exec",
2838
+ type: "exec",
2839
+ displayName: ""
2840
+ },
2841
+ {
2842
+ name: "duration",
2843
+ type: "float",
2844
+ displayName: "Duration",
2845
+ defaultValue: 1
2846
+ }
2847
+ ],
2848
+ outputs: [
2849
+ {
2850
+ name: "exec",
2851
+ type: "exec",
2852
+ displayName: "Completed"
2853
+ }
2854
+ ]
2855
+ };
2856
+ var _DelayExecutor = class _DelayExecutor {
2857
+ execute(node, context) {
2858
+ const duration = context.evaluateInput(node.id, "duration", 1);
2859
+ return {
2860
+ nextExec: "exec",
2861
+ delay: duration
2862
+ };
2863
+ }
2864
+ };
2865
+ __name(_DelayExecutor, "DelayExecutor");
2866
+ var DelayExecutor = _DelayExecutor;
2867
+ DelayExecutor = _ts_decorate12([
2868
+ RegisterNode(DelayTemplate)
2869
+ ], DelayExecutor);
2870
+
2871
+ // src/nodes/math/MathOperations.ts
2872
+ function _ts_decorate13(decorators, target, key, desc) {
2873
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2874
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
2875
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
2876
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
2877
+ }
2878
+ __name(_ts_decorate13, "_ts_decorate");
2879
+ var AddTemplate = {
2880
+ type: "Add",
2881
+ title: "Add",
2882
+ category: "math",
2883
+ color: "#4CAF50",
2884
+ description: "Adds two numbers together (\u5C06\u4E24\u4E2A\u6570\u5B57\u76F8\u52A0)",
2885
+ keywords: [
2886
+ "add",
2887
+ "plus",
2888
+ "sum",
2889
+ "+",
2890
+ "math"
2891
+ ],
2892
+ isPure: true,
2893
+ inputs: [
2894
+ {
2895
+ name: "a",
2896
+ type: "float",
2897
+ displayName: "A",
2898
+ defaultValue: 0
2899
+ },
2900
+ {
2901
+ name: "b",
2902
+ type: "float",
2903
+ displayName: "B",
2904
+ defaultValue: 0
2905
+ }
2906
+ ],
2907
+ outputs: [
2908
+ {
2909
+ name: "result",
2910
+ type: "float",
2911
+ displayName: "Result"
2912
+ }
2913
+ ]
2914
+ };
2915
+ var _AddExecutor = class _AddExecutor {
2916
+ execute(node, context) {
2917
+ const a = Number(context.evaluateInput(node.id, "a", 0));
2918
+ const b = Number(context.evaluateInput(node.id, "b", 0));
2919
+ return {
2920
+ outputs: {
2921
+ result: a + b
2922
+ }
2923
+ };
2924
+ }
2925
+ };
2926
+ __name(_AddExecutor, "AddExecutor");
2927
+ var AddExecutor = _AddExecutor;
2928
+ AddExecutor = _ts_decorate13([
2929
+ RegisterNode(AddTemplate)
2930
+ ], AddExecutor);
2931
+ var SubtractTemplate = {
2932
+ type: "Subtract",
2933
+ title: "Subtract",
2934
+ category: "math",
2935
+ color: "#4CAF50",
2936
+ description: "Subtracts B from A (\u4ECE A \u51CF\u53BB B)",
2937
+ keywords: [
2938
+ "subtract",
2939
+ "minus",
2940
+ "-",
2941
+ "math"
2942
+ ],
2943
+ isPure: true,
2944
+ inputs: [
2945
+ {
2946
+ name: "a",
2947
+ type: "float",
2948
+ displayName: "A",
2949
+ defaultValue: 0
2950
+ },
2951
+ {
2952
+ name: "b",
2953
+ type: "float",
2954
+ displayName: "B",
2955
+ defaultValue: 0
2956
+ }
2957
+ ],
2958
+ outputs: [
2959
+ {
2960
+ name: "result",
2961
+ type: "float",
2962
+ displayName: "Result"
2963
+ }
2964
+ ]
2965
+ };
2966
+ var _SubtractExecutor = class _SubtractExecutor {
2967
+ execute(node, context) {
2968
+ const a = Number(context.evaluateInput(node.id, "a", 0));
2969
+ const b = Number(context.evaluateInput(node.id, "b", 0));
2970
+ return {
2971
+ outputs: {
2972
+ result: a - b
2973
+ }
2974
+ };
2975
+ }
2976
+ };
2977
+ __name(_SubtractExecutor, "SubtractExecutor");
2978
+ var SubtractExecutor = _SubtractExecutor;
2979
+ SubtractExecutor = _ts_decorate13([
2980
+ RegisterNode(SubtractTemplate)
2981
+ ], SubtractExecutor);
2982
+ var MultiplyTemplate = {
2983
+ type: "Multiply",
2984
+ title: "Multiply",
2985
+ category: "math",
2986
+ color: "#4CAF50",
2987
+ description: "Multiplies two numbers (\u5C06\u4E24\u4E2A\u6570\u5B57\u76F8\u4E58)",
2988
+ keywords: [
2989
+ "multiply",
2990
+ "times",
2991
+ "*",
2992
+ "math"
2993
+ ],
2994
+ isPure: true,
2995
+ inputs: [
2996
+ {
2997
+ name: "a",
2998
+ type: "float",
2999
+ displayName: "A",
3000
+ defaultValue: 0
3001
+ },
3002
+ {
3003
+ name: "b",
3004
+ type: "float",
3005
+ displayName: "B",
3006
+ defaultValue: 1
3007
+ }
3008
+ ],
3009
+ outputs: [
3010
+ {
3011
+ name: "result",
3012
+ type: "float",
3013
+ displayName: "Result"
3014
+ }
3015
+ ]
3016
+ };
3017
+ var _MultiplyExecutor = class _MultiplyExecutor {
3018
+ execute(node, context) {
3019
+ const a = Number(context.evaluateInput(node.id, "a", 0));
3020
+ const b = Number(context.evaluateInput(node.id, "b", 1));
3021
+ return {
3022
+ outputs: {
3023
+ result: a * b
3024
+ }
3025
+ };
3026
+ }
3027
+ };
3028
+ __name(_MultiplyExecutor, "MultiplyExecutor");
3029
+ var MultiplyExecutor = _MultiplyExecutor;
3030
+ MultiplyExecutor = _ts_decorate13([
3031
+ RegisterNode(MultiplyTemplate)
3032
+ ], MultiplyExecutor);
3033
+ var DivideTemplate = {
3034
+ type: "Divide",
3035
+ title: "Divide",
3036
+ category: "math",
3037
+ color: "#4CAF50",
3038
+ description: "Divides A by B (A \u9664\u4EE5 B)",
3039
+ keywords: [
3040
+ "divide",
3041
+ "/",
3042
+ "math"
3043
+ ],
3044
+ isPure: true,
3045
+ inputs: [
3046
+ {
3047
+ name: "a",
3048
+ type: "float",
3049
+ displayName: "A",
3050
+ defaultValue: 0
3051
+ },
3052
+ {
3053
+ name: "b",
3054
+ type: "float",
3055
+ displayName: "B",
3056
+ defaultValue: 1
3057
+ }
3058
+ ],
3059
+ outputs: [
3060
+ {
3061
+ name: "result",
3062
+ type: "float",
3063
+ displayName: "Result"
3064
+ }
3065
+ ]
3066
+ };
3067
+ var _DivideExecutor = class _DivideExecutor {
3068
+ execute(node, context) {
3069
+ const a = Number(context.evaluateInput(node.id, "a", 0));
3070
+ const b = Number(context.evaluateInput(node.id, "b", 1));
3071
+ if (b === 0) {
3072
+ return {
3073
+ outputs: {
3074
+ result: 0
3075
+ }
3076
+ };
3077
+ }
3078
+ return {
3079
+ outputs: {
3080
+ result: a / b
3081
+ }
3082
+ };
3083
+ }
3084
+ };
3085
+ __name(_DivideExecutor, "DivideExecutor");
3086
+ var DivideExecutor = _DivideExecutor;
3087
+ DivideExecutor = _ts_decorate13([
3088
+ RegisterNode(DivideTemplate)
3089
+ ], DivideExecutor);
3090
+
3091
+ // src/BlueprintPlugin.ts
3092
+ var _a;
3093
+ var BlueprintRuntimeModule = (_a = class {
3094
+ async onInitialize() {
3095
+ }
3096
+ onDestroy() {
3097
+ }
3098
+ }, __name(_a, "BlueprintRuntimeModule"), _a);
3099
+ var manifest = {
3100
+ id: "blueprint",
3101
+ name: "@esengine/blueprint",
3102
+ displayName: "Blueprint",
3103
+ version: "1.0.0",
3104
+ description: "\u53EF\u89C6\u5316\u811A\u672C\u7CFB\u7EDF",
3105
+ category: "AI",
3106
+ icon: "Workflow",
3107
+ isCore: false,
3108
+ defaultEnabled: false,
3109
+ isEngineModule: true,
3110
+ dependencies: [
3111
+ "core"
3112
+ ],
3113
+ exports: {
3114
+ components: [
3115
+ "BlueprintComponent"
3116
+ ],
3117
+ systems: [
3118
+ "BlueprintSystem"
3119
+ ]
3120
+ },
3121
+ requiresWasm: false
3122
+ };
3123
+ var BlueprintPlugin = {
3124
+ manifest,
3125
+ runtimeModule: new BlueprintRuntimeModule()
3126
+ };
3127
+ export {
3128
+ AlwaysFalseCondition,
3129
+ AlwaysTrueCondition,
3130
+ BlueprintComposer,
3131
+ BlueprintFragment,
3132
+ BlueprintPlugin,
3133
+ BlueprintTrigger,
3134
+ BlueprintVM,
3135
+ CollisionEntityCondition,
3136
+ CompositeCondition,
3137
+ ConditionBuilder,
3138
+ CustomEventCondition,
3139
+ EntityIdCondition,
3140
+ EntityTriggerManager,
3141
+ ExecutionContext,
3142
+ FragmentRegistry,
3143
+ FunctionCondition,
3144
+ InputActionCondition,
3145
+ MessageNameCondition,
3146
+ NodeRegistry,
3147
+ NotCondition,
3148
+ RegisterNode,
3149
+ StateNameCondition,
3150
+ TimerIdCondition,
3151
+ TriggerDispatcher,
3152
+ TriggerRegistry,
3153
+ TriggerTypeCondition,
3154
+ TriggerTypes,
3155
+ arePinTypesCompatible,
3156
+ cleanupBlueprint,
3157
+ condition,
3158
+ createBlueprintComponentData,
3159
+ createBlueprintSystem,
3160
+ createCollisionContext,
3161
+ createCollisionTrigger,
3162
+ createComposer,
3163
+ createCustomContext,
3164
+ createCustomTrigger,
3165
+ createEmptyBlueprint,
3166
+ createEntityTriggerManager,
3167
+ createExposedPin,
3168
+ createFragment,
3169
+ createFragmentRegistry,
3170
+ createInputContext,
3171
+ createInputTrigger,
3172
+ createMessageContext,
3173
+ createMessageTrigger,
3174
+ createStateContext,
3175
+ createStateEnterTrigger,
3176
+ createStateExitTrigger,
3177
+ createTickContext,
3178
+ createTickTrigger,
3179
+ createTimerContext,
3180
+ createTimerTrigger,
3181
+ createTrigger,
3182
+ createTriggerDispatcher,
3183
+ defaultFragmentRegistry,
3184
+ fragmentFromAsset,
3185
+ fragmentToAsset,
3186
+ getNodeCategoryColor,
3187
+ getPinTypeColor,
3188
+ initializeBlueprintVM,
3189
+ startBlueprint,
3190
+ stopBlueprint,
3191
+ tickBlueprint,
3192
+ triggerBlueprintEvent,
3193
+ triggerCustomBlueprintEvent,
3194
+ validateBlueprintAsset
3195
+ };
3196
+ //# sourceMappingURL=index.js.map