@esengine/behavior-tree 1.0.1 → 1.0.2
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/LICENSE +21 -0
- package/{index.d.ts → dist/index.d.ts} +361 -73
- package/dist/index.js +4692 -0
- package/dist/index.js.map +1 -0
- package/package.json +35 -29
- package/index.cjs +0 -2
- package/index.cjs.map +0 -1
- package/index.es5.js +0 -4
- package/index.es5.js.map +0 -1
- package/index.mjs +0 -2
- package/index.mjs.map +0 -1
- package/index.umd.js +0 -2
- package/index.umd.js.map +0 -1
package/dist/index.js
ADDED
|
@@ -0,0 +1,4692 @@
|
|
|
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/constants.ts
|
|
7
|
+
var BehaviorTreeAssetType = "behavior-tree";
|
|
8
|
+
|
|
9
|
+
// src/Types/TaskStatus.ts
|
|
10
|
+
var TaskStatus = /* @__PURE__ */ (function(TaskStatus2) {
|
|
11
|
+
TaskStatus2[TaskStatus2["Invalid"] = 0] = "Invalid";
|
|
12
|
+
TaskStatus2[TaskStatus2["Success"] = 1] = "Success";
|
|
13
|
+
TaskStatus2[TaskStatus2["Failure"] = 2] = "Failure";
|
|
14
|
+
TaskStatus2[TaskStatus2["Running"] = 3] = "Running";
|
|
15
|
+
return TaskStatus2;
|
|
16
|
+
})({});
|
|
17
|
+
var NodeType = {
|
|
18
|
+
/** 根节点 - 行为树的起始节点 */
|
|
19
|
+
Root: "root",
|
|
20
|
+
/** 复合节点 - 有多个子节点 */
|
|
21
|
+
Composite: "composite",
|
|
22
|
+
/** 装饰器节点 - 有一个子节点 */
|
|
23
|
+
Decorator: "decorator",
|
|
24
|
+
/** 动作节点 - 叶子节点 */
|
|
25
|
+
Action: "action",
|
|
26
|
+
/** 条件节点 - 叶子节点 */
|
|
27
|
+
Condition: "condition"
|
|
28
|
+
};
|
|
29
|
+
var CompositeType = /* @__PURE__ */ (function(CompositeType2) {
|
|
30
|
+
CompositeType2["Sequence"] = "sequence";
|
|
31
|
+
CompositeType2["Selector"] = "selector";
|
|
32
|
+
CompositeType2["Parallel"] = "parallel";
|
|
33
|
+
CompositeType2["ParallelSelector"] = "parallel-selector";
|
|
34
|
+
CompositeType2["RandomSequence"] = "random-sequence";
|
|
35
|
+
CompositeType2["RandomSelector"] = "random-selector";
|
|
36
|
+
return CompositeType2;
|
|
37
|
+
})({});
|
|
38
|
+
var DecoratorType = /* @__PURE__ */ (function(DecoratorType2) {
|
|
39
|
+
DecoratorType2["Inverter"] = "inverter";
|
|
40
|
+
DecoratorType2["Repeater"] = "repeater";
|
|
41
|
+
DecoratorType2["UntilSuccess"] = "until-success";
|
|
42
|
+
DecoratorType2["UntilFail"] = "until-fail";
|
|
43
|
+
DecoratorType2["AlwaysSucceed"] = "always-succeed";
|
|
44
|
+
DecoratorType2["AlwaysFail"] = "always-fail";
|
|
45
|
+
DecoratorType2["Conditional"] = "conditional";
|
|
46
|
+
DecoratorType2["Cooldown"] = "cooldown";
|
|
47
|
+
DecoratorType2["Timeout"] = "timeout";
|
|
48
|
+
return DecoratorType2;
|
|
49
|
+
})({});
|
|
50
|
+
var AbortType = /* @__PURE__ */ (function(AbortType2) {
|
|
51
|
+
AbortType2["None"] = "none";
|
|
52
|
+
AbortType2["Self"] = "self";
|
|
53
|
+
AbortType2["LowerPriority"] = "lower-priority";
|
|
54
|
+
AbortType2["Both"] = "both";
|
|
55
|
+
return AbortType2;
|
|
56
|
+
})({});
|
|
57
|
+
var BlackboardValueType = /* @__PURE__ */ (function(BlackboardValueType2) {
|
|
58
|
+
BlackboardValueType2["String"] = "string";
|
|
59
|
+
BlackboardValueType2["Number"] = "number";
|
|
60
|
+
BlackboardValueType2["Boolean"] = "boolean";
|
|
61
|
+
BlackboardValueType2["Vector2"] = "vector2";
|
|
62
|
+
BlackboardValueType2["Vector3"] = "vector3";
|
|
63
|
+
BlackboardValueType2["Object"] = "object";
|
|
64
|
+
BlackboardValueType2["Array"] = "array";
|
|
65
|
+
return BlackboardValueType2;
|
|
66
|
+
})({});
|
|
67
|
+
|
|
68
|
+
// src/execution/BehaviorTreeData.ts
|
|
69
|
+
function createDefaultRuntimeState() {
|
|
70
|
+
return {
|
|
71
|
+
status: TaskStatus.Invalid,
|
|
72
|
+
currentChildIndex: 0
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
__name(createDefaultRuntimeState, "createDefaultRuntimeState");
|
|
76
|
+
|
|
77
|
+
// src/execution/BehaviorTreeRuntimeComponent.ts
|
|
78
|
+
import { Component, ECSComponent, Property } from "@esengine/ecs-framework";
|
|
79
|
+
import { Serializable, Serialize, IgnoreSerialization } from "@esengine/ecs-framework";
|
|
80
|
+
function _ts_decorate(decorators, target, key, desc) {
|
|
81
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
82
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
83
|
+
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;
|
|
84
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
85
|
+
}
|
|
86
|
+
__name(_ts_decorate, "_ts_decorate");
|
|
87
|
+
function _ts_metadata(k, v) {
|
|
88
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
89
|
+
}
|
|
90
|
+
__name(_ts_metadata, "_ts_metadata");
|
|
91
|
+
var _BehaviorTreeRuntimeComponent = class _BehaviorTreeRuntimeComponent extends Component {
|
|
92
|
+
constructor() {
|
|
93
|
+
super(...arguments);
|
|
94
|
+
/**
|
|
95
|
+
* 引用的行为树资产ID(可序列化)
|
|
96
|
+
*/
|
|
97
|
+
__publicField(this, "treeAssetId", "");
|
|
98
|
+
/**
|
|
99
|
+
* 是否自动启动
|
|
100
|
+
*/
|
|
101
|
+
__publicField(this, "autoStart", true);
|
|
102
|
+
/**
|
|
103
|
+
* 是否正在运行
|
|
104
|
+
*/
|
|
105
|
+
__publicField(this, "isRunning", false);
|
|
106
|
+
/**
|
|
107
|
+
* 节点运行时状态(每个节点独立)
|
|
108
|
+
* 不序列化,每次加载时重新初始化
|
|
109
|
+
*/
|
|
110
|
+
__publicField(this, "nodeStates", /* @__PURE__ */ new Map());
|
|
111
|
+
/**
|
|
112
|
+
* 黑板数据(该Entity独立的数据)
|
|
113
|
+
* 不序列化,通过初始化设置
|
|
114
|
+
*/
|
|
115
|
+
__publicField(this, "blackboard", /* @__PURE__ */ new Map());
|
|
116
|
+
/**
|
|
117
|
+
* 黑板观察者列表
|
|
118
|
+
*/
|
|
119
|
+
__publicField(this, "blackboardObservers", /* @__PURE__ */ new Map());
|
|
120
|
+
/**
|
|
121
|
+
* 当前激活的节点ID列表(用于调试)
|
|
122
|
+
*/
|
|
123
|
+
__publicField(this, "activeNodeIds", /* @__PURE__ */ new Set());
|
|
124
|
+
/**
|
|
125
|
+
* 标记是否需要在下一个tick重置状态
|
|
126
|
+
*/
|
|
127
|
+
__publicField(this, "needsReset", false);
|
|
128
|
+
/**
|
|
129
|
+
* 需要中止的节点ID列表
|
|
130
|
+
*/
|
|
131
|
+
__publicField(this, "nodesToAbort", /* @__PURE__ */ new Set());
|
|
132
|
+
/**
|
|
133
|
+
* 执行顺序计数器(用于调试和可视化)
|
|
134
|
+
*/
|
|
135
|
+
__publicField(this, "executionOrderCounter", 0);
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* 获取节点运行时状态
|
|
139
|
+
*/
|
|
140
|
+
getNodeState(nodeId) {
|
|
141
|
+
if (!this.nodeStates.has(nodeId)) {
|
|
142
|
+
this.nodeStates.set(nodeId, createDefaultRuntimeState());
|
|
143
|
+
}
|
|
144
|
+
return this.nodeStates.get(nodeId);
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* 重置节点状态
|
|
148
|
+
*/
|
|
149
|
+
resetNodeState(nodeId) {
|
|
150
|
+
const state = this.getNodeState(nodeId);
|
|
151
|
+
state.status = TaskStatus.Invalid;
|
|
152
|
+
state.currentChildIndex = 0;
|
|
153
|
+
delete state.startTime;
|
|
154
|
+
delete state.lastExecutionTime;
|
|
155
|
+
delete state.repeatCount;
|
|
156
|
+
delete state.cachedResult;
|
|
157
|
+
delete state.shuffledIndices;
|
|
158
|
+
delete state.isAborted;
|
|
159
|
+
delete state.lastConditionResult;
|
|
160
|
+
delete state.observedKeys;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* 重置所有节点状态
|
|
164
|
+
*/
|
|
165
|
+
resetAllStates() {
|
|
166
|
+
this.nodeStates.clear();
|
|
167
|
+
this.activeNodeIds.clear();
|
|
168
|
+
this.executionOrderCounter = 0;
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* 获取黑板值
|
|
172
|
+
*/
|
|
173
|
+
getBlackboardValue(key) {
|
|
174
|
+
return this.blackboard.get(key);
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* 设置黑板值
|
|
178
|
+
*/
|
|
179
|
+
setBlackboardValue(key, value) {
|
|
180
|
+
const oldValue = this.blackboard.get(key);
|
|
181
|
+
this.blackboard.set(key, value);
|
|
182
|
+
if (oldValue !== value) {
|
|
183
|
+
this.notifyBlackboardChange(key, value, oldValue);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* 检查黑板是否有某个键
|
|
188
|
+
*/
|
|
189
|
+
hasBlackboardKey(key) {
|
|
190
|
+
return this.blackboard.has(key);
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* 初始化黑板(从树定义的默认值)
|
|
194
|
+
*/
|
|
195
|
+
initializeBlackboard(variables) {
|
|
196
|
+
if (variables) {
|
|
197
|
+
variables.forEach((value, key) => {
|
|
198
|
+
if (!this.blackboard.has(key)) {
|
|
199
|
+
this.blackboard.set(key, value);
|
|
200
|
+
}
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* 清空黑板
|
|
206
|
+
*/
|
|
207
|
+
clearBlackboard() {
|
|
208
|
+
this.blackboard.clear();
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* 启动行为树
|
|
212
|
+
*/
|
|
213
|
+
start() {
|
|
214
|
+
this.isRunning = true;
|
|
215
|
+
this.resetAllStates();
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* 停止行为树
|
|
219
|
+
*/
|
|
220
|
+
stop() {
|
|
221
|
+
this.isRunning = false;
|
|
222
|
+
this.activeNodeIds.clear();
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* 暂停行为树
|
|
226
|
+
*/
|
|
227
|
+
pause() {
|
|
228
|
+
this.isRunning = false;
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* 恢复行为树
|
|
232
|
+
*/
|
|
233
|
+
resume() {
|
|
234
|
+
this.isRunning = true;
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* 注册黑板观察者
|
|
238
|
+
*/
|
|
239
|
+
observeBlackboard(nodeId, keys, callback) {
|
|
240
|
+
const observer = {
|
|
241
|
+
nodeId,
|
|
242
|
+
keys: new Set(keys),
|
|
243
|
+
callback
|
|
244
|
+
};
|
|
245
|
+
for (const key of keys) {
|
|
246
|
+
if (!this.blackboardObservers.has(key)) {
|
|
247
|
+
this.blackboardObservers.set(key, []);
|
|
248
|
+
}
|
|
249
|
+
this.blackboardObservers.get(key).push(observer);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* 取消注册黑板观察者
|
|
254
|
+
*/
|
|
255
|
+
unobserveBlackboard(nodeId) {
|
|
256
|
+
for (const observers of this.blackboardObservers.values()) {
|
|
257
|
+
const index = observers.findIndex((o) => o.nodeId === nodeId);
|
|
258
|
+
if (index !== -1) {
|
|
259
|
+
observers.splice(index, 1);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* 通知黑板变化
|
|
265
|
+
*/
|
|
266
|
+
notifyBlackboardChange(key, newValue, oldValue) {
|
|
267
|
+
const observers = this.blackboardObservers.get(key);
|
|
268
|
+
if (!observers) return;
|
|
269
|
+
for (const observer of observers) {
|
|
270
|
+
try {
|
|
271
|
+
observer.callback(key, newValue, oldValue);
|
|
272
|
+
} catch (error) {
|
|
273
|
+
console.error(`\u9ED1\u677F\u89C2\u5BDF\u8005\u56DE\u8C03\u9519\u8BEF (\u8282\u70B9: ${observer.nodeId}):`, error);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* 请求中止节点
|
|
279
|
+
*/
|
|
280
|
+
requestAbort(nodeId) {
|
|
281
|
+
this.nodesToAbort.add(nodeId);
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* 检查节点是否需要中止
|
|
285
|
+
*/
|
|
286
|
+
shouldAbort(nodeId) {
|
|
287
|
+
return this.nodesToAbort.has(nodeId);
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* 清除中止请求
|
|
291
|
+
*/
|
|
292
|
+
clearAbortRequest(nodeId) {
|
|
293
|
+
this.nodesToAbort.delete(nodeId);
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* 清除所有中止请求
|
|
297
|
+
*/
|
|
298
|
+
clearAllAbortRequests() {
|
|
299
|
+
this.nodesToAbort.clear();
|
|
300
|
+
}
|
|
301
|
+
};
|
|
302
|
+
__name(_BehaviorTreeRuntimeComponent, "BehaviorTreeRuntimeComponent");
|
|
303
|
+
var BehaviorTreeRuntimeComponent = _BehaviorTreeRuntimeComponent;
|
|
304
|
+
_ts_decorate([
|
|
305
|
+
Serialize(),
|
|
306
|
+
Property({
|
|
307
|
+
type: "asset",
|
|
308
|
+
label: "Behavior Tree",
|
|
309
|
+
extensions: [
|
|
310
|
+
".btree"
|
|
311
|
+
]
|
|
312
|
+
}),
|
|
313
|
+
_ts_metadata("design:type", String)
|
|
314
|
+
], BehaviorTreeRuntimeComponent.prototype, "treeAssetId", void 0);
|
|
315
|
+
_ts_decorate([
|
|
316
|
+
Serialize(),
|
|
317
|
+
Property({
|
|
318
|
+
type: "boolean",
|
|
319
|
+
label: "Auto Start"
|
|
320
|
+
}),
|
|
321
|
+
_ts_metadata("design:type", Boolean)
|
|
322
|
+
], BehaviorTreeRuntimeComponent.prototype, "autoStart", void 0);
|
|
323
|
+
_ts_decorate([
|
|
324
|
+
IgnoreSerialization(),
|
|
325
|
+
_ts_metadata("design:type", Boolean)
|
|
326
|
+
], BehaviorTreeRuntimeComponent.prototype, "isRunning", void 0);
|
|
327
|
+
_ts_decorate([
|
|
328
|
+
IgnoreSerialization(),
|
|
329
|
+
_ts_metadata("design:type", typeof Map === "undefined" ? Object : Map)
|
|
330
|
+
], BehaviorTreeRuntimeComponent.prototype, "nodeStates", void 0);
|
|
331
|
+
_ts_decorate([
|
|
332
|
+
IgnoreSerialization(),
|
|
333
|
+
_ts_metadata("design:type", typeof Map === "undefined" ? Object : Map)
|
|
334
|
+
], BehaviorTreeRuntimeComponent.prototype, "blackboard", void 0);
|
|
335
|
+
_ts_decorate([
|
|
336
|
+
IgnoreSerialization(),
|
|
337
|
+
_ts_metadata("design:type", typeof Map === "undefined" ? Object : Map)
|
|
338
|
+
], BehaviorTreeRuntimeComponent.prototype, "blackboardObservers", void 0);
|
|
339
|
+
_ts_decorate([
|
|
340
|
+
IgnoreSerialization(),
|
|
341
|
+
_ts_metadata("design:type", typeof Set === "undefined" ? Object : Set)
|
|
342
|
+
], BehaviorTreeRuntimeComponent.prototype, "activeNodeIds", void 0);
|
|
343
|
+
_ts_decorate([
|
|
344
|
+
IgnoreSerialization(),
|
|
345
|
+
_ts_metadata("design:type", Boolean)
|
|
346
|
+
], BehaviorTreeRuntimeComponent.prototype, "needsReset", void 0);
|
|
347
|
+
_ts_decorate([
|
|
348
|
+
IgnoreSerialization(),
|
|
349
|
+
_ts_metadata("design:type", typeof Set === "undefined" ? Object : Set)
|
|
350
|
+
], BehaviorTreeRuntimeComponent.prototype, "nodesToAbort", void 0);
|
|
351
|
+
_ts_decorate([
|
|
352
|
+
IgnoreSerialization(),
|
|
353
|
+
_ts_metadata("design:type", Number)
|
|
354
|
+
], BehaviorTreeRuntimeComponent.prototype, "executionOrderCounter", void 0);
|
|
355
|
+
BehaviorTreeRuntimeComponent = _ts_decorate([
|
|
356
|
+
ECSComponent("BehaviorTreeRuntime"),
|
|
357
|
+
Serializable({
|
|
358
|
+
version: 1
|
|
359
|
+
})
|
|
360
|
+
], BehaviorTreeRuntimeComponent);
|
|
361
|
+
|
|
362
|
+
// src/execution/BehaviorTreeAssetManager.ts
|
|
363
|
+
import { createLogger } from "@esengine/ecs-framework";
|
|
364
|
+
|
|
365
|
+
// src/Serialization/EditorToBehaviorTreeDataConverter.ts
|
|
366
|
+
var _EditorToBehaviorTreeDataConverter = class _EditorToBehaviorTreeDataConverter {
|
|
367
|
+
/**
|
|
368
|
+
* 将编辑器 JSON 字符串转换为运行时 BehaviorTreeData
|
|
369
|
+
*/
|
|
370
|
+
static fromEditorJSON(json) {
|
|
371
|
+
const editorData = JSON.parse(json);
|
|
372
|
+
return this.convert(editorData);
|
|
373
|
+
}
|
|
374
|
+
/**
|
|
375
|
+
* 将编辑器数据对象转换为运行时 BehaviorTreeData
|
|
376
|
+
*/
|
|
377
|
+
static convert(editorData) {
|
|
378
|
+
const rootNode = editorData.nodes.find((n) => n.template.type === "root" || n.data["nodeType"] === "root");
|
|
379
|
+
if (!rootNode) {
|
|
380
|
+
throw new Error("Behavior tree must have a root node");
|
|
381
|
+
}
|
|
382
|
+
const propertyBindingsMap = this.buildPropertyBindingsMap(editorData);
|
|
383
|
+
const nodesMap = /* @__PURE__ */ new Map();
|
|
384
|
+
for (const editorNode of editorData.nodes) {
|
|
385
|
+
if (this.isNonExecutableNode(editorNode)) {
|
|
386
|
+
continue;
|
|
387
|
+
}
|
|
388
|
+
const propertyBindings = propertyBindingsMap.get(editorNode.id);
|
|
389
|
+
const behaviorNodeData = this.convertNode(editorNode, propertyBindings);
|
|
390
|
+
nodesMap.set(behaviorNodeData.id, behaviorNodeData);
|
|
391
|
+
}
|
|
392
|
+
const blackboardVariables = editorData.blackboard ? new Map(Object.entries(editorData.blackboard)) : /* @__PURE__ */ new Map();
|
|
393
|
+
return {
|
|
394
|
+
id: this.generateTreeId(editorData),
|
|
395
|
+
name: editorData.metadata?.name || "Untitled",
|
|
396
|
+
rootNodeId: rootNode.id,
|
|
397
|
+
nodes: nodesMap,
|
|
398
|
+
blackboardVariables
|
|
399
|
+
};
|
|
400
|
+
}
|
|
401
|
+
/**
|
|
402
|
+
* 从连接数据构建属性绑定映射
|
|
403
|
+
* 处理 connectionType === 'property' 的连接,将黑板变量节点连接到目标节点的属性
|
|
404
|
+
*/
|
|
405
|
+
static buildPropertyBindingsMap(editorData) {
|
|
406
|
+
const bindingsMap = /* @__PURE__ */ new Map();
|
|
407
|
+
if (!editorData.connections) {
|
|
408
|
+
return bindingsMap;
|
|
409
|
+
}
|
|
410
|
+
const nodeToVariableMap = /* @__PURE__ */ new Map();
|
|
411
|
+
for (const node of editorData.nodes) {
|
|
412
|
+
if (node.data["nodeType"] === "blackboard-variable" && node.data["variableName"]) {
|
|
413
|
+
nodeToVariableMap.set(node.id, node.data["variableName"]);
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
for (const conn of editorData.connections) {
|
|
417
|
+
if (conn.connectionType === "property" && conn.toProperty) {
|
|
418
|
+
const variableName = nodeToVariableMap.get(conn.from);
|
|
419
|
+
if (variableName) {
|
|
420
|
+
let bindings = bindingsMap.get(conn.to);
|
|
421
|
+
if (!bindings) {
|
|
422
|
+
bindings = {};
|
|
423
|
+
bindingsMap.set(conn.to, bindings);
|
|
424
|
+
}
|
|
425
|
+
bindings[conn.toProperty] = variableName;
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
return bindingsMap;
|
|
430
|
+
}
|
|
431
|
+
/**
|
|
432
|
+
* 转换单个节点
|
|
433
|
+
* @param editorNode 编辑器节点数据
|
|
434
|
+
* @param propertyBindings 从连接中提取的属性绑定(可选)
|
|
435
|
+
*/
|
|
436
|
+
static convertNode(editorNode, propertyBindings) {
|
|
437
|
+
const nodeType = this.mapNodeType(editorNode.template.type);
|
|
438
|
+
const config = this.extractConfig(editorNode.data);
|
|
439
|
+
const dataBindings = this.extractBindings(editorNode.data);
|
|
440
|
+
const bindings = {
|
|
441
|
+
...dataBindings,
|
|
442
|
+
...propertyBindings
|
|
443
|
+
};
|
|
444
|
+
const abortType = this.extractAbortType(editorNode.data);
|
|
445
|
+
let implementationType = editorNode.template.className;
|
|
446
|
+
if (!implementationType) {
|
|
447
|
+
implementationType = this.extractImplementationType(editorNode.data, nodeType);
|
|
448
|
+
}
|
|
449
|
+
if (!implementationType) {
|
|
450
|
+
console.warn(`[EditorToBehaviorTreeDataConverter] Node ${editorNode.id} has no implementationType, using fallback`);
|
|
451
|
+
implementationType = this.getDefaultImplementationType(nodeType);
|
|
452
|
+
}
|
|
453
|
+
return {
|
|
454
|
+
id: editorNode.id,
|
|
455
|
+
name: editorNode.template.displayName || editorNode.template.className || implementationType,
|
|
456
|
+
nodeType,
|
|
457
|
+
implementationType,
|
|
458
|
+
children: editorNode.children || [],
|
|
459
|
+
config,
|
|
460
|
+
...Object.keys(bindings).length > 0 && {
|
|
461
|
+
bindings
|
|
462
|
+
},
|
|
463
|
+
...abortType && {
|
|
464
|
+
abortType
|
|
465
|
+
}
|
|
466
|
+
};
|
|
467
|
+
}
|
|
468
|
+
/**
|
|
469
|
+
* 检查是否为不可执行的节点(如黑板变量节点)
|
|
470
|
+
* 这些节点只在编辑器中使用,不参与运行时执行
|
|
471
|
+
*/
|
|
472
|
+
static isNonExecutableNode(editorNode) {
|
|
473
|
+
const nodeType = editorNode.data["nodeType"];
|
|
474
|
+
return nodeType === "blackboard-variable";
|
|
475
|
+
}
|
|
476
|
+
/**
|
|
477
|
+
* 从节点数据中提取实现类型
|
|
478
|
+
*
|
|
479
|
+
* 优先级:
|
|
480
|
+
* 1. template.className(标准方式)
|
|
481
|
+
* 2. data 中的类型字段(compositeType, actionType 等)
|
|
482
|
+
* 3. 特殊节点类型的默认值(如 Root)
|
|
483
|
+
*/
|
|
484
|
+
static extractImplementationType(data, nodeType) {
|
|
485
|
+
const typeFieldMap = {
|
|
486
|
+
[NodeType.Composite]: "compositeType",
|
|
487
|
+
[NodeType.Decorator]: "decoratorType",
|
|
488
|
+
[NodeType.Action]: "actionType",
|
|
489
|
+
[NodeType.Condition]: "conditionType",
|
|
490
|
+
[NodeType.Root]: ""
|
|
491
|
+
};
|
|
492
|
+
const field = typeFieldMap[nodeType];
|
|
493
|
+
if (field && data[field]) {
|
|
494
|
+
return data[field];
|
|
495
|
+
}
|
|
496
|
+
if (nodeType === NodeType.Root) {
|
|
497
|
+
return "Root";
|
|
498
|
+
}
|
|
499
|
+
return void 0;
|
|
500
|
+
}
|
|
501
|
+
/**
|
|
502
|
+
* 获取节点类型的默认实现
|
|
503
|
+
* 当无法确定具体实现类型时使用
|
|
504
|
+
*/
|
|
505
|
+
static getDefaultImplementationType(nodeType) {
|
|
506
|
+
const defaultImplementations = {
|
|
507
|
+
[NodeType.Root]: "Root",
|
|
508
|
+
[NodeType.Composite]: "Sequence",
|
|
509
|
+
[NodeType.Decorator]: "Inverter",
|
|
510
|
+
[NodeType.Action]: "Wait",
|
|
511
|
+
[NodeType.Condition]: "AlwaysTrue"
|
|
512
|
+
};
|
|
513
|
+
return defaultImplementations[nodeType] || "Unknown";
|
|
514
|
+
}
|
|
515
|
+
/**
|
|
516
|
+
* 映射节点类型
|
|
517
|
+
*/
|
|
518
|
+
static mapNodeType(type) {
|
|
519
|
+
switch (type.toLowerCase()) {
|
|
520
|
+
case "root":
|
|
521
|
+
return NodeType.Root;
|
|
522
|
+
case "composite":
|
|
523
|
+
return NodeType.Composite;
|
|
524
|
+
case "decorator":
|
|
525
|
+
return NodeType.Decorator;
|
|
526
|
+
case "action":
|
|
527
|
+
return NodeType.Action;
|
|
528
|
+
case "condition":
|
|
529
|
+
return NodeType.Condition;
|
|
530
|
+
default:
|
|
531
|
+
throw new Error(`Unknown node type: ${type}`);
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
/**
|
|
535
|
+
* 提取节点配置(过滤掉内部字段和绑定字段)
|
|
536
|
+
*/
|
|
537
|
+
static extractConfig(data) {
|
|
538
|
+
const config = {};
|
|
539
|
+
const internalFields = /* @__PURE__ */ new Set([
|
|
540
|
+
"nodeType",
|
|
541
|
+
"abortType"
|
|
542
|
+
]);
|
|
543
|
+
for (const [key, value] of Object.entries(data)) {
|
|
544
|
+
if (internalFields.has(key)) {
|
|
545
|
+
continue;
|
|
546
|
+
}
|
|
547
|
+
if (this.isBinding(value)) {
|
|
548
|
+
continue;
|
|
549
|
+
}
|
|
550
|
+
config[key] = value;
|
|
551
|
+
}
|
|
552
|
+
return config;
|
|
553
|
+
}
|
|
554
|
+
/**
|
|
555
|
+
* 提取黑板变量绑定
|
|
556
|
+
*/
|
|
557
|
+
static extractBindings(data) {
|
|
558
|
+
const bindings = {};
|
|
559
|
+
for (const [key, value] of Object.entries(data)) {
|
|
560
|
+
if (this.isBinding(value)) {
|
|
561
|
+
bindings[key] = this.extractBindingKey(value);
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
return bindings;
|
|
565
|
+
}
|
|
566
|
+
/**
|
|
567
|
+
* 判断是否为黑板绑定
|
|
568
|
+
*/
|
|
569
|
+
static isBinding(value) {
|
|
570
|
+
if (typeof value === "object" && value !== null) {
|
|
571
|
+
return value._isBlackboardBinding === true || value.type === "blackboard" || value.blackboardKey !== void 0;
|
|
572
|
+
}
|
|
573
|
+
return false;
|
|
574
|
+
}
|
|
575
|
+
/**
|
|
576
|
+
* 提取黑板绑定的键名
|
|
577
|
+
*/
|
|
578
|
+
static extractBindingKey(binding) {
|
|
579
|
+
return binding.blackboardKey || binding.key || binding.value || "";
|
|
580
|
+
}
|
|
581
|
+
/**
|
|
582
|
+
* 提取中止类型(条件装饰器使用)
|
|
583
|
+
*/
|
|
584
|
+
static extractAbortType(data) {
|
|
585
|
+
if (!data["abortType"]) {
|
|
586
|
+
return void 0;
|
|
587
|
+
}
|
|
588
|
+
const abortTypeStr = String(data["abortType"]).toLowerCase();
|
|
589
|
+
switch (abortTypeStr) {
|
|
590
|
+
case "none":
|
|
591
|
+
return AbortType.None;
|
|
592
|
+
case "self":
|
|
593
|
+
return AbortType.Self;
|
|
594
|
+
case "lowerpriority":
|
|
595
|
+
case "lower_priority":
|
|
596
|
+
return AbortType.LowerPriority;
|
|
597
|
+
case "both":
|
|
598
|
+
return AbortType.Both;
|
|
599
|
+
default:
|
|
600
|
+
return AbortType.None;
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
/**
|
|
604
|
+
* 生成行为树ID
|
|
605
|
+
*/
|
|
606
|
+
static generateTreeId(editorData) {
|
|
607
|
+
if (editorData.metadata?.name) {
|
|
608
|
+
return editorData.metadata.name.replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
609
|
+
}
|
|
610
|
+
return `tree_${Date.now()}`;
|
|
611
|
+
}
|
|
612
|
+
/**
|
|
613
|
+
* 将运行时格式转换回编辑器格式(用于双向转换)
|
|
614
|
+
*/
|
|
615
|
+
static toEditorJSON(treeData) {
|
|
616
|
+
const editorData = this.convertToEditor(treeData);
|
|
617
|
+
return JSON.stringify(editorData, null, 2);
|
|
618
|
+
}
|
|
619
|
+
/**
|
|
620
|
+
* 将运行时 BehaviorTreeData 转换为编辑器格式
|
|
621
|
+
*/
|
|
622
|
+
static convertToEditor(treeData) {
|
|
623
|
+
const nodes = [];
|
|
624
|
+
for (const [_id, nodeData] of treeData.nodes) {
|
|
625
|
+
nodes.push(this.convertNodeToEditor(nodeData));
|
|
626
|
+
}
|
|
627
|
+
const blackboard = treeData.blackboardVariables ? Object.fromEntries(treeData.blackboardVariables) : {};
|
|
628
|
+
return {
|
|
629
|
+
version: "1.0.0",
|
|
630
|
+
metadata: {
|
|
631
|
+
name: treeData.name,
|
|
632
|
+
description: "",
|
|
633
|
+
modifiedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
634
|
+
},
|
|
635
|
+
nodes,
|
|
636
|
+
blackboard
|
|
637
|
+
};
|
|
638
|
+
}
|
|
639
|
+
/**
|
|
640
|
+
* 将运行时节点转换为编辑器节点
|
|
641
|
+
*/
|
|
642
|
+
static convertNodeToEditor(nodeData) {
|
|
643
|
+
const data = {
|
|
644
|
+
...nodeData.config
|
|
645
|
+
};
|
|
646
|
+
if (nodeData.bindings) {
|
|
647
|
+
for (const [key, blackboardKey] of Object.entries(nodeData.bindings)) {
|
|
648
|
+
data[key] = {
|
|
649
|
+
_isBlackboardBinding: true,
|
|
650
|
+
blackboardKey
|
|
651
|
+
};
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
if (nodeData.abortType !== void 0) {
|
|
655
|
+
data["abortType"] = nodeData.abortType;
|
|
656
|
+
}
|
|
657
|
+
let typeStr;
|
|
658
|
+
if (typeof nodeData.nodeType === "string") {
|
|
659
|
+
typeStr = nodeData.nodeType;
|
|
660
|
+
} else {
|
|
661
|
+
typeStr = "action";
|
|
662
|
+
}
|
|
663
|
+
const result = {
|
|
664
|
+
id: nodeData.id,
|
|
665
|
+
template: {
|
|
666
|
+
type: typeStr,
|
|
667
|
+
className: nodeData.implementationType,
|
|
668
|
+
displayName: nodeData.name
|
|
669
|
+
},
|
|
670
|
+
data
|
|
671
|
+
};
|
|
672
|
+
if (nodeData.children && nodeData.children.length > 0) {
|
|
673
|
+
result.children = nodeData.children;
|
|
674
|
+
}
|
|
675
|
+
return result;
|
|
676
|
+
}
|
|
677
|
+
};
|
|
678
|
+
__name(_EditorToBehaviorTreeDataConverter, "EditorToBehaviorTreeDataConverter");
|
|
679
|
+
var EditorToBehaviorTreeDataConverter = _EditorToBehaviorTreeDataConverter;
|
|
680
|
+
|
|
681
|
+
// src/execution/BehaviorTreeAssetManager.ts
|
|
682
|
+
var logger = createLogger("BehaviorTreeAssetManager");
|
|
683
|
+
var _BehaviorTreeAssetManager = class _BehaviorTreeAssetManager {
|
|
684
|
+
constructor() {
|
|
685
|
+
/**
|
|
686
|
+
* 已加载的行为树资产
|
|
687
|
+
*/
|
|
688
|
+
__publicField(this, "assets", /* @__PURE__ */ new Map());
|
|
689
|
+
}
|
|
690
|
+
/**
|
|
691
|
+
* 加载行为树资产
|
|
692
|
+
*/
|
|
693
|
+
loadAsset(asset) {
|
|
694
|
+
if (this.assets.has(asset.id)) {
|
|
695
|
+
logger.warn(`\u884C\u4E3A\u6811\u8D44\u4EA7\u5DF2\u5B58\u5728\uFF0C\u5C06\u88AB\u8986\u76D6: ${asset.id}`);
|
|
696
|
+
}
|
|
697
|
+
this.assets.set(asset.id, asset);
|
|
698
|
+
logger.info(`\u884C\u4E3A\u6811\u8D44\u4EA7\u5DF2\u52A0\u8F7D: ${asset.name} (${asset.nodes.size}\u4E2A\u8282\u70B9)`);
|
|
699
|
+
}
|
|
700
|
+
/**
|
|
701
|
+
* 从编辑器 JSON 格式加载行为树资产
|
|
702
|
+
*
|
|
703
|
+
* @param json 编辑器导出的 JSON 字符串
|
|
704
|
+
* @returns 加载的行为树数据
|
|
705
|
+
*
|
|
706
|
+
* @example
|
|
707
|
+
* ```typescript
|
|
708
|
+
* const assetManager = Core.services.resolve(BehaviorTreeAssetManager);
|
|
709
|
+
* const jsonContent = await readFile('path/to/tree.btree');
|
|
710
|
+
* const treeData = assetManager.loadFromEditorJSON(jsonContent);
|
|
711
|
+
* ```
|
|
712
|
+
*/
|
|
713
|
+
loadFromEditorJSON(json) {
|
|
714
|
+
try {
|
|
715
|
+
const treeData = EditorToBehaviorTreeDataConverter.fromEditorJSON(json);
|
|
716
|
+
this.loadAsset(treeData);
|
|
717
|
+
return treeData;
|
|
718
|
+
} catch (error) {
|
|
719
|
+
logger.error("\u4ECE\u7F16\u8F91\u5668JSON\u52A0\u8F7D\u5931\u8D25:", error);
|
|
720
|
+
throw error;
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
/**
|
|
724
|
+
* 批量加载多个行为树资产(从编辑器JSON)
|
|
725
|
+
*
|
|
726
|
+
* @param jsonDataList JSON字符串列表
|
|
727
|
+
* @returns 成功加载的资产数量
|
|
728
|
+
*/
|
|
729
|
+
loadMultipleFromEditorJSON(jsonDataList) {
|
|
730
|
+
let successCount = 0;
|
|
731
|
+
for (const json of jsonDataList) {
|
|
732
|
+
try {
|
|
733
|
+
this.loadFromEditorJSON(json);
|
|
734
|
+
successCount++;
|
|
735
|
+
} catch (error) {
|
|
736
|
+
logger.error("\u6279\u91CF\u52A0\u8F7D\u65F6\u51FA\u9519:", error);
|
|
737
|
+
}
|
|
738
|
+
}
|
|
739
|
+
logger.info(`\u6279\u91CF\u52A0\u8F7D\u5B8C\u6210: ${successCount}/${jsonDataList.length} \u4E2A\u8D44\u4EA7`);
|
|
740
|
+
return successCount;
|
|
741
|
+
}
|
|
742
|
+
/**
|
|
743
|
+
* 获取行为树资产
|
|
744
|
+
*/
|
|
745
|
+
getAsset(assetId) {
|
|
746
|
+
return this.assets.get(assetId);
|
|
747
|
+
}
|
|
748
|
+
/**
|
|
749
|
+
* 检查资产是否存在
|
|
750
|
+
*/
|
|
751
|
+
hasAsset(assetId) {
|
|
752
|
+
return this.assets.has(assetId);
|
|
753
|
+
}
|
|
754
|
+
/**
|
|
755
|
+
* 卸载行为树资产
|
|
756
|
+
*/
|
|
757
|
+
unloadAsset(assetId) {
|
|
758
|
+
const result = this.assets.delete(assetId);
|
|
759
|
+
if (result) {
|
|
760
|
+
logger.info(`\u884C\u4E3A\u6811\u8D44\u4EA7\u5DF2\u5378\u8F7D: ${assetId}`);
|
|
761
|
+
}
|
|
762
|
+
return result;
|
|
763
|
+
}
|
|
764
|
+
/**
|
|
765
|
+
* 清空所有资产
|
|
766
|
+
*/
|
|
767
|
+
clearAll() {
|
|
768
|
+
this.assets.clear();
|
|
769
|
+
logger.info("\u6240\u6709\u884C\u4E3A\u6811\u8D44\u4EA7\u5DF2\u6E05\u7A7A");
|
|
770
|
+
}
|
|
771
|
+
/**
|
|
772
|
+
* 获取已加载资产数量
|
|
773
|
+
*/
|
|
774
|
+
getAssetCount() {
|
|
775
|
+
return this.assets.size;
|
|
776
|
+
}
|
|
777
|
+
/**
|
|
778
|
+
* 获取所有资产ID
|
|
779
|
+
*/
|
|
780
|
+
getAllAssetIds() {
|
|
781
|
+
return Array.from(this.assets.keys());
|
|
782
|
+
}
|
|
783
|
+
/**
|
|
784
|
+
* 释放资源(实现IService接口)
|
|
785
|
+
*/
|
|
786
|
+
dispose() {
|
|
787
|
+
this.clearAll();
|
|
788
|
+
}
|
|
789
|
+
};
|
|
790
|
+
__name(_BehaviorTreeAssetManager, "BehaviorTreeAssetManager");
|
|
791
|
+
var BehaviorTreeAssetManager = _BehaviorTreeAssetManager;
|
|
792
|
+
|
|
793
|
+
// src/execution/NodeExecutor.ts
|
|
794
|
+
var _BindingHelper = class _BindingHelper {
|
|
795
|
+
/**
|
|
796
|
+
* 获取配置值(考虑黑板绑定)
|
|
797
|
+
*
|
|
798
|
+
* @param context 执行上下文
|
|
799
|
+
* @param configKey 配置键名
|
|
800
|
+
* @param defaultValue 默认值
|
|
801
|
+
* @returns 解析后的值
|
|
802
|
+
*/
|
|
803
|
+
static getValue(context, configKey, defaultValue) {
|
|
804
|
+
const { nodeData, runtime } = context;
|
|
805
|
+
if (nodeData.bindings && nodeData.bindings[configKey]) {
|
|
806
|
+
const blackboardKey = nodeData.bindings[configKey];
|
|
807
|
+
const boundValue = runtime.getBlackboardValue(blackboardKey);
|
|
808
|
+
return boundValue !== void 0 ? boundValue : defaultValue;
|
|
809
|
+
}
|
|
810
|
+
const configValue = nodeData.config[configKey];
|
|
811
|
+
return configValue !== void 0 ? configValue : defaultValue;
|
|
812
|
+
}
|
|
813
|
+
/**
|
|
814
|
+
* 检查配置是否绑定到黑板变量
|
|
815
|
+
*/
|
|
816
|
+
static hasBinding(context, configKey) {
|
|
817
|
+
return !!(context.nodeData.bindings && context.nodeData.bindings[configKey]);
|
|
818
|
+
}
|
|
819
|
+
/**
|
|
820
|
+
* 获取绑定的黑板变量名
|
|
821
|
+
*/
|
|
822
|
+
static getBindingKey(context, configKey) {
|
|
823
|
+
return context.nodeData.bindings?.[configKey];
|
|
824
|
+
}
|
|
825
|
+
};
|
|
826
|
+
__name(_BindingHelper, "BindingHelper");
|
|
827
|
+
var BindingHelper = _BindingHelper;
|
|
828
|
+
var _NodeExecutorRegistry = class _NodeExecutorRegistry {
|
|
829
|
+
constructor() {
|
|
830
|
+
__publicField(this, "executors", /* @__PURE__ */ new Map());
|
|
831
|
+
}
|
|
832
|
+
/**
|
|
833
|
+
* 注册执行器
|
|
834
|
+
*
|
|
835
|
+
* @param implementationType 节点实现类型(对应BehaviorNodeData.implementationType)
|
|
836
|
+
* @param executor 执行器实例
|
|
837
|
+
*/
|
|
838
|
+
register(implementationType, executor) {
|
|
839
|
+
if (this.executors.has(implementationType)) {
|
|
840
|
+
console.warn(`\u6267\u884C\u5668\u5DF2\u5B58\u5728\uFF0C\u5C06\u88AB\u8986\u76D6: ${implementationType}`);
|
|
841
|
+
}
|
|
842
|
+
this.executors.set(implementationType, executor);
|
|
843
|
+
}
|
|
844
|
+
/**
|
|
845
|
+
* 获取执行器
|
|
846
|
+
*/
|
|
847
|
+
get(implementationType) {
|
|
848
|
+
return this.executors.get(implementationType);
|
|
849
|
+
}
|
|
850
|
+
/**
|
|
851
|
+
* 检查是否有执行器
|
|
852
|
+
*/
|
|
853
|
+
has(implementationType) {
|
|
854
|
+
return this.executors.has(implementationType);
|
|
855
|
+
}
|
|
856
|
+
/**
|
|
857
|
+
* 注销执行器
|
|
858
|
+
*/
|
|
859
|
+
unregister(implementationType) {
|
|
860
|
+
return this.executors.delete(implementationType);
|
|
861
|
+
}
|
|
862
|
+
/**
|
|
863
|
+
* 清空所有执行器
|
|
864
|
+
*/
|
|
865
|
+
clear() {
|
|
866
|
+
this.executors.clear();
|
|
867
|
+
}
|
|
868
|
+
};
|
|
869
|
+
__name(_NodeExecutorRegistry, "NodeExecutorRegistry");
|
|
870
|
+
var NodeExecutorRegistry = _NodeExecutorRegistry;
|
|
871
|
+
|
|
872
|
+
// src/execution/BehaviorTreeExecutionSystem.ts
|
|
873
|
+
import { EntitySystem, Matcher, Time, Core as Core2, ECSSystem, ServiceContainer } from "@esengine/ecs-framework";
|
|
874
|
+
|
|
875
|
+
// src/execution/NodeMetadata.ts
|
|
876
|
+
var _NodeMetadataRegistry = class _NodeMetadataRegistry {
|
|
877
|
+
static register(target, metadata) {
|
|
878
|
+
this.metadataMap.set(metadata.implementationType, metadata);
|
|
879
|
+
this.executorClassMap.set(target, metadata.implementationType);
|
|
880
|
+
this.executorConstructors.set(metadata.implementationType, target);
|
|
881
|
+
}
|
|
882
|
+
static getMetadata(implementationType) {
|
|
883
|
+
return this.metadataMap.get(implementationType);
|
|
884
|
+
}
|
|
885
|
+
static getAllMetadata() {
|
|
886
|
+
return Array.from(this.metadataMap.values());
|
|
887
|
+
}
|
|
888
|
+
static getByCategory(category) {
|
|
889
|
+
return this.getAllMetadata().filter((m) => m.category === category);
|
|
890
|
+
}
|
|
891
|
+
static getByNodeType(nodeType) {
|
|
892
|
+
return this.getAllMetadata().filter((m) => m.nodeType === nodeType);
|
|
893
|
+
}
|
|
894
|
+
static getImplementationType(executorClass) {
|
|
895
|
+
return this.executorClassMap.get(executorClass);
|
|
896
|
+
}
|
|
897
|
+
static getExecutorConstructor(implementationType) {
|
|
898
|
+
return this.executorConstructors.get(implementationType);
|
|
899
|
+
}
|
|
900
|
+
static getAllExecutorConstructors() {
|
|
901
|
+
return new Map(this.executorConstructors);
|
|
902
|
+
}
|
|
903
|
+
};
|
|
904
|
+
__name(_NodeMetadataRegistry, "NodeMetadataRegistry");
|
|
905
|
+
__publicField(_NodeMetadataRegistry, "metadataMap", /* @__PURE__ */ new Map());
|
|
906
|
+
__publicField(_NodeMetadataRegistry, "executorClassMap", /* @__PURE__ */ new Map());
|
|
907
|
+
__publicField(_NodeMetadataRegistry, "executorConstructors", /* @__PURE__ */ new Map());
|
|
908
|
+
var NodeMetadataRegistry = _NodeMetadataRegistry;
|
|
909
|
+
function NodeExecutorMetadata(metadata) {
|
|
910
|
+
return function(target) {
|
|
911
|
+
NodeMetadataRegistry.register(target, metadata);
|
|
912
|
+
};
|
|
913
|
+
}
|
|
914
|
+
__name(NodeExecutorMetadata, "NodeExecutorMetadata");
|
|
915
|
+
|
|
916
|
+
// src/execution/Executors/RootExecutor.ts
|
|
917
|
+
function _ts_decorate2(decorators, target, key, desc) {
|
|
918
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
919
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
920
|
+
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;
|
|
921
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
922
|
+
}
|
|
923
|
+
__name(_ts_decorate2, "_ts_decorate");
|
|
924
|
+
var _RootExecutor = class _RootExecutor {
|
|
925
|
+
execute(context) {
|
|
926
|
+
const { nodeData } = context;
|
|
927
|
+
if (!nodeData.children || nodeData.children.length === 0) {
|
|
928
|
+
return TaskStatus.Failure;
|
|
929
|
+
}
|
|
930
|
+
const childId = nodeData.children[0];
|
|
931
|
+
return context.executeChild(childId);
|
|
932
|
+
}
|
|
933
|
+
reset(_context) {
|
|
934
|
+
}
|
|
935
|
+
};
|
|
936
|
+
__name(_RootExecutor, "RootExecutor");
|
|
937
|
+
var RootExecutor = _RootExecutor;
|
|
938
|
+
RootExecutor = _ts_decorate2([
|
|
939
|
+
NodeExecutorMetadata({
|
|
940
|
+
implementationType: "Root",
|
|
941
|
+
nodeType: NodeType.Root,
|
|
942
|
+
displayName: "\u6839\u8282\u70B9",
|
|
943
|
+
description: "\u884C\u4E3A\u6811\u7684\u5165\u53E3\u8282\u70B9",
|
|
944
|
+
category: "Root",
|
|
945
|
+
childrenConstraints: {
|
|
946
|
+
min: 1,
|
|
947
|
+
max: 1
|
|
948
|
+
}
|
|
949
|
+
})
|
|
950
|
+
], RootExecutor);
|
|
951
|
+
|
|
952
|
+
// src/execution/Executors/SequenceExecutor.ts
|
|
953
|
+
function _ts_decorate3(decorators, target, key, desc) {
|
|
954
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
955
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
956
|
+
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;
|
|
957
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
958
|
+
}
|
|
959
|
+
__name(_ts_decorate3, "_ts_decorate");
|
|
960
|
+
var _SequenceExecutor = class _SequenceExecutor {
|
|
961
|
+
execute(context) {
|
|
962
|
+
const { nodeData, state } = context;
|
|
963
|
+
if (!nodeData.children || nodeData.children.length === 0) {
|
|
964
|
+
return TaskStatus.Success;
|
|
965
|
+
}
|
|
966
|
+
while (state.currentChildIndex < nodeData.children.length) {
|
|
967
|
+
const childId = nodeData.children[state.currentChildIndex];
|
|
968
|
+
const status = context.executeChild(childId);
|
|
969
|
+
if (status === TaskStatus.Running) {
|
|
970
|
+
return TaskStatus.Running;
|
|
971
|
+
}
|
|
972
|
+
if (status === TaskStatus.Failure) {
|
|
973
|
+
state.currentChildIndex = 0;
|
|
974
|
+
return TaskStatus.Failure;
|
|
975
|
+
}
|
|
976
|
+
state.currentChildIndex++;
|
|
977
|
+
}
|
|
978
|
+
state.currentChildIndex = 0;
|
|
979
|
+
return TaskStatus.Success;
|
|
980
|
+
}
|
|
981
|
+
reset(context) {
|
|
982
|
+
context.state.currentChildIndex = 0;
|
|
983
|
+
}
|
|
984
|
+
};
|
|
985
|
+
__name(_SequenceExecutor, "SequenceExecutor");
|
|
986
|
+
var SequenceExecutor = _SequenceExecutor;
|
|
987
|
+
SequenceExecutor = _ts_decorate3([
|
|
988
|
+
NodeExecutorMetadata({
|
|
989
|
+
implementationType: "Sequence",
|
|
990
|
+
nodeType: NodeType.Composite,
|
|
991
|
+
displayName: "\u5E8F\u5217",
|
|
992
|
+
description: "\u6309\u987A\u5E8F\u6267\u884C\u5B50\u8282\u70B9\uFF0C\u5168\u90E8\u6210\u529F\u624D\u6210\u529F",
|
|
993
|
+
category: "Composite",
|
|
994
|
+
childrenConstraints: {
|
|
995
|
+
min: 1
|
|
996
|
+
}
|
|
997
|
+
})
|
|
998
|
+
], SequenceExecutor);
|
|
999
|
+
|
|
1000
|
+
// src/execution/Executors/SelectorExecutor.ts
|
|
1001
|
+
function _ts_decorate4(decorators, target, key, desc) {
|
|
1002
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1003
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
1004
|
+
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;
|
|
1005
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1006
|
+
}
|
|
1007
|
+
__name(_ts_decorate4, "_ts_decorate");
|
|
1008
|
+
var _SelectorExecutor = class _SelectorExecutor {
|
|
1009
|
+
execute(context) {
|
|
1010
|
+
const { nodeData, state } = context;
|
|
1011
|
+
if (!nodeData.children || nodeData.children.length === 0) {
|
|
1012
|
+
return TaskStatus.Failure;
|
|
1013
|
+
}
|
|
1014
|
+
while (state.currentChildIndex < nodeData.children.length) {
|
|
1015
|
+
const childId = nodeData.children[state.currentChildIndex];
|
|
1016
|
+
const status = context.executeChild(childId);
|
|
1017
|
+
if (status === TaskStatus.Running) {
|
|
1018
|
+
return TaskStatus.Running;
|
|
1019
|
+
}
|
|
1020
|
+
if (status === TaskStatus.Success) {
|
|
1021
|
+
state.currentChildIndex = 0;
|
|
1022
|
+
return TaskStatus.Success;
|
|
1023
|
+
}
|
|
1024
|
+
state.currentChildIndex++;
|
|
1025
|
+
}
|
|
1026
|
+
state.currentChildIndex = 0;
|
|
1027
|
+
return TaskStatus.Failure;
|
|
1028
|
+
}
|
|
1029
|
+
reset(context) {
|
|
1030
|
+
context.state.currentChildIndex = 0;
|
|
1031
|
+
}
|
|
1032
|
+
};
|
|
1033
|
+
__name(_SelectorExecutor, "SelectorExecutor");
|
|
1034
|
+
var SelectorExecutor = _SelectorExecutor;
|
|
1035
|
+
SelectorExecutor = _ts_decorate4([
|
|
1036
|
+
NodeExecutorMetadata({
|
|
1037
|
+
implementationType: "Selector",
|
|
1038
|
+
nodeType: NodeType.Composite,
|
|
1039
|
+
displayName: "\u9009\u62E9\u5668",
|
|
1040
|
+
description: "\u6309\u987A\u5E8F\u6267\u884C\u5B50\u8282\u70B9\uFF0C\u4EFB\u4E00\u6210\u529F\u5219\u6210\u529F",
|
|
1041
|
+
category: "Composite",
|
|
1042
|
+
childrenConstraints: {
|
|
1043
|
+
min: 1
|
|
1044
|
+
}
|
|
1045
|
+
})
|
|
1046
|
+
], SelectorExecutor);
|
|
1047
|
+
|
|
1048
|
+
// src/execution/Executors/ParallelExecutor.ts
|
|
1049
|
+
function _ts_decorate5(decorators, target, key, desc) {
|
|
1050
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1051
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
1052
|
+
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;
|
|
1053
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1054
|
+
}
|
|
1055
|
+
__name(_ts_decorate5, "_ts_decorate");
|
|
1056
|
+
var _ParallelExecutor = class _ParallelExecutor {
|
|
1057
|
+
execute(context) {
|
|
1058
|
+
const { nodeData } = context;
|
|
1059
|
+
const successPolicy = BindingHelper.getValue(context, "successPolicy", "all");
|
|
1060
|
+
const failurePolicy = BindingHelper.getValue(context, "failurePolicy", "one");
|
|
1061
|
+
if (!nodeData.children || nodeData.children.length === 0) {
|
|
1062
|
+
return TaskStatus.Success;
|
|
1063
|
+
}
|
|
1064
|
+
let hasRunning = false;
|
|
1065
|
+
let successCount = 0;
|
|
1066
|
+
let failureCount = 0;
|
|
1067
|
+
for (const childId of nodeData.children) {
|
|
1068
|
+
const status = context.executeChild(childId);
|
|
1069
|
+
if (status === TaskStatus.Running) {
|
|
1070
|
+
hasRunning = true;
|
|
1071
|
+
} else if (status === TaskStatus.Success) {
|
|
1072
|
+
successCount++;
|
|
1073
|
+
} else if (status === TaskStatus.Failure) {
|
|
1074
|
+
failureCount++;
|
|
1075
|
+
}
|
|
1076
|
+
}
|
|
1077
|
+
if (successPolicy === "one" && successCount > 0) {
|
|
1078
|
+
this.stopAllChildren(context);
|
|
1079
|
+
return TaskStatus.Success;
|
|
1080
|
+
}
|
|
1081
|
+
if (successPolicy === "all" && successCount === nodeData.children.length) {
|
|
1082
|
+
return TaskStatus.Success;
|
|
1083
|
+
}
|
|
1084
|
+
if (failurePolicy === "one" && failureCount > 0) {
|
|
1085
|
+
this.stopAllChildren(context);
|
|
1086
|
+
return TaskStatus.Failure;
|
|
1087
|
+
}
|
|
1088
|
+
if (failurePolicy === "all" && failureCount === nodeData.children.length) {
|
|
1089
|
+
return TaskStatus.Failure;
|
|
1090
|
+
}
|
|
1091
|
+
return hasRunning ? TaskStatus.Running : TaskStatus.Success;
|
|
1092
|
+
}
|
|
1093
|
+
stopAllChildren(context) {
|
|
1094
|
+
const { nodeData, runtime } = context;
|
|
1095
|
+
if (!nodeData.children) return;
|
|
1096
|
+
for (const childId of nodeData.children) {
|
|
1097
|
+
runtime.activeNodeIds.delete(childId);
|
|
1098
|
+
runtime.resetNodeState(childId);
|
|
1099
|
+
}
|
|
1100
|
+
}
|
|
1101
|
+
reset(context) {
|
|
1102
|
+
const { nodeData, runtime } = context;
|
|
1103
|
+
if (!nodeData.children) return;
|
|
1104
|
+
for (const childId of nodeData.children) {
|
|
1105
|
+
runtime.resetNodeState(childId);
|
|
1106
|
+
}
|
|
1107
|
+
}
|
|
1108
|
+
};
|
|
1109
|
+
__name(_ParallelExecutor, "ParallelExecutor");
|
|
1110
|
+
var ParallelExecutor = _ParallelExecutor;
|
|
1111
|
+
ParallelExecutor = _ts_decorate5([
|
|
1112
|
+
NodeExecutorMetadata({
|
|
1113
|
+
implementationType: "Parallel",
|
|
1114
|
+
nodeType: NodeType.Composite,
|
|
1115
|
+
displayName: "\u5E76\u884C",
|
|
1116
|
+
description: "\u540C\u65F6\u6267\u884C\u6240\u6709\u5B50\u8282\u70B9",
|
|
1117
|
+
category: "Composite",
|
|
1118
|
+
configSchema: {
|
|
1119
|
+
successPolicy: {
|
|
1120
|
+
type: "string",
|
|
1121
|
+
default: "all",
|
|
1122
|
+
description: "\u6210\u529F\u7B56\u7565",
|
|
1123
|
+
options: [
|
|
1124
|
+
"all",
|
|
1125
|
+
"one"
|
|
1126
|
+
]
|
|
1127
|
+
},
|
|
1128
|
+
failurePolicy: {
|
|
1129
|
+
type: "string",
|
|
1130
|
+
default: "one",
|
|
1131
|
+
description: "\u5931\u8D25\u7B56\u7565",
|
|
1132
|
+
options: [
|
|
1133
|
+
"all",
|
|
1134
|
+
"one"
|
|
1135
|
+
]
|
|
1136
|
+
}
|
|
1137
|
+
},
|
|
1138
|
+
childrenConstraints: {
|
|
1139
|
+
min: 2
|
|
1140
|
+
}
|
|
1141
|
+
})
|
|
1142
|
+
], ParallelExecutor);
|
|
1143
|
+
|
|
1144
|
+
// src/execution/Executors/ParallelSelectorExecutor.ts
|
|
1145
|
+
function _ts_decorate6(decorators, target, key, desc) {
|
|
1146
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1147
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
1148
|
+
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;
|
|
1149
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1150
|
+
}
|
|
1151
|
+
__name(_ts_decorate6, "_ts_decorate");
|
|
1152
|
+
var _ParallelSelectorExecutor = class _ParallelSelectorExecutor {
|
|
1153
|
+
execute(context) {
|
|
1154
|
+
const { nodeData } = context;
|
|
1155
|
+
const failurePolicy = BindingHelper.getValue(context, "failurePolicy", "all");
|
|
1156
|
+
if (!nodeData.children || nodeData.children.length === 0) {
|
|
1157
|
+
return TaskStatus.Failure;
|
|
1158
|
+
}
|
|
1159
|
+
let hasRunning = false;
|
|
1160
|
+
let successCount = 0;
|
|
1161
|
+
let failureCount = 0;
|
|
1162
|
+
for (const childId of nodeData.children) {
|
|
1163
|
+
const status = context.executeChild(childId);
|
|
1164
|
+
if (status === TaskStatus.Running) {
|
|
1165
|
+
hasRunning = true;
|
|
1166
|
+
} else if (status === TaskStatus.Success) {
|
|
1167
|
+
successCount++;
|
|
1168
|
+
} else if (status === TaskStatus.Failure) {
|
|
1169
|
+
failureCount++;
|
|
1170
|
+
}
|
|
1171
|
+
}
|
|
1172
|
+
if (successCount > 0) {
|
|
1173
|
+
this.stopAllChildren(context);
|
|
1174
|
+
return TaskStatus.Success;
|
|
1175
|
+
}
|
|
1176
|
+
if (failurePolicy === "one" && failureCount > 0) {
|
|
1177
|
+
this.stopAllChildren(context);
|
|
1178
|
+
return TaskStatus.Failure;
|
|
1179
|
+
}
|
|
1180
|
+
if (failurePolicy === "all" && failureCount === nodeData.children.length) {
|
|
1181
|
+
return TaskStatus.Failure;
|
|
1182
|
+
}
|
|
1183
|
+
return hasRunning ? TaskStatus.Running : TaskStatus.Failure;
|
|
1184
|
+
}
|
|
1185
|
+
stopAllChildren(context) {
|
|
1186
|
+
const { nodeData, runtime } = context;
|
|
1187
|
+
if (!nodeData.children) return;
|
|
1188
|
+
for (const childId of nodeData.children) {
|
|
1189
|
+
runtime.activeNodeIds.delete(childId);
|
|
1190
|
+
runtime.resetNodeState(childId);
|
|
1191
|
+
}
|
|
1192
|
+
}
|
|
1193
|
+
reset(context) {
|
|
1194
|
+
const { nodeData, runtime } = context;
|
|
1195
|
+
if (!nodeData.children) return;
|
|
1196
|
+
for (const childId of nodeData.children) {
|
|
1197
|
+
runtime.resetNodeState(childId);
|
|
1198
|
+
}
|
|
1199
|
+
}
|
|
1200
|
+
};
|
|
1201
|
+
__name(_ParallelSelectorExecutor, "ParallelSelectorExecutor");
|
|
1202
|
+
var ParallelSelectorExecutor = _ParallelSelectorExecutor;
|
|
1203
|
+
ParallelSelectorExecutor = _ts_decorate6([
|
|
1204
|
+
NodeExecutorMetadata({
|
|
1205
|
+
implementationType: "ParallelSelector",
|
|
1206
|
+
nodeType: NodeType.Composite,
|
|
1207
|
+
displayName: "\u5E76\u884C\u9009\u62E9\u5668",
|
|
1208
|
+
description: "\u5E76\u884C\u6267\u884C\u5B50\u8282\u70B9\uFF0C\u4EFB\u4E00\u6210\u529F\u5219\u6210\u529F",
|
|
1209
|
+
category: "Composite",
|
|
1210
|
+
configSchema: {
|
|
1211
|
+
failurePolicy: {
|
|
1212
|
+
type: "string",
|
|
1213
|
+
default: "all",
|
|
1214
|
+
description: "\u5931\u8D25\u7B56\u7565",
|
|
1215
|
+
options: [
|
|
1216
|
+
"all",
|
|
1217
|
+
"one"
|
|
1218
|
+
]
|
|
1219
|
+
}
|
|
1220
|
+
}
|
|
1221
|
+
})
|
|
1222
|
+
], ParallelSelectorExecutor);
|
|
1223
|
+
|
|
1224
|
+
// src/execution/Executors/RandomSequenceExecutor.ts
|
|
1225
|
+
function _ts_decorate7(decorators, target, key, desc) {
|
|
1226
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1227
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
1228
|
+
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;
|
|
1229
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1230
|
+
}
|
|
1231
|
+
__name(_ts_decorate7, "_ts_decorate");
|
|
1232
|
+
var _RandomSequenceExecutor = class _RandomSequenceExecutor {
|
|
1233
|
+
execute(context) {
|
|
1234
|
+
const { nodeData, state } = context;
|
|
1235
|
+
if (!nodeData.children || nodeData.children.length === 0) {
|
|
1236
|
+
return TaskStatus.Success;
|
|
1237
|
+
}
|
|
1238
|
+
if (!state.shuffledIndices || state.shuffledIndices.length === 0) {
|
|
1239
|
+
state.shuffledIndices = this.shuffleIndices(nodeData.children.length);
|
|
1240
|
+
}
|
|
1241
|
+
while (state.currentChildIndex < state.shuffledIndices.length) {
|
|
1242
|
+
const shuffledIndex = state.shuffledIndices[state.currentChildIndex];
|
|
1243
|
+
const childId = nodeData.children[shuffledIndex];
|
|
1244
|
+
const status = context.executeChild(childId);
|
|
1245
|
+
if (status === TaskStatus.Running) {
|
|
1246
|
+
return TaskStatus.Running;
|
|
1247
|
+
}
|
|
1248
|
+
if (status === TaskStatus.Failure) {
|
|
1249
|
+
state.currentChildIndex = 0;
|
|
1250
|
+
delete state.shuffledIndices;
|
|
1251
|
+
return TaskStatus.Failure;
|
|
1252
|
+
}
|
|
1253
|
+
state.currentChildIndex++;
|
|
1254
|
+
}
|
|
1255
|
+
state.currentChildIndex = 0;
|
|
1256
|
+
delete state.shuffledIndices;
|
|
1257
|
+
return TaskStatus.Success;
|
|
1258
|
+
}
|
|
1259
|
+
shuffleIndices(length) {
|
|
1260
|
+
const indices = Array.from({
|
|
1261
|
+
length
|
|
1262
|
+
}, (_, i) => i);
|
|
1263
|
+
for (let i = indices.length - 1; i > 0; i--) {
|
|
1264
|
+
const j = Math.floor(Math.random() * (i + 1));
|
|
1265
|
+
const temp = indices[i];
|
|
1266
|
+
indices[i] = indices[j];
|
|
1267
|
+
indices[j] = temp;
|
|
1268
|
+
}
|
|
1269
|
+
return indices;
|
|
1270
|
+
}
|
|
1271
|
+
reset(context) {
|
|
1272
|
+
context.state.currentChildIndex = 0;
|
|
1273
|
+
delete context.state.shuffledIndices;
|
|
1274
|
+
}
|
|
1275
|
+
};
|
|
1276
|
+
__name(_RandomSequenceExecutor, "RandomSequenceExecutor");
|
|
1277
|
+
var RandomSequenceExecutor = _RandomSequenceExecutor;
|
|
1278
|
+
RandomSequenceExecutor = _ts_decorate7([
|
|
1279
|
+
NodeExecutorMetadata({
|
|
1280
|
+
implementationType: "RandomSequence",
|
|
1281
|
+
nodeType: NodeType.Composite,
|
|
1282
|
+
displayName: "\u968F\u673A\u5E8F\u5217",
|
|
1283
|
+
description: "\u968F\u673A\u987A\u5E8F\u6267\u884C\u5B50\u8282\u70B9\uFF0C\u5168\u90E8\u6210\u529F\u624D\u6210\u529F",
|
|
1284
|
+
category: "Composite",
|
|
1285
|
+
childrenConstraints: {
|
|
1286
|
+
min: 1
|
|
1287
|
+
}
|
|
1288
|
+
})
|
|
1289
|
+
], RandomSequenceExecutor);
|
|
1290
|
+
|
|
1291
|
+
// src/execution/Executors/RandomSelectorExecutor.ts
|
|
1292
|
+
function _ts_decorate8(decorators, target, key, desc) {
|
|
1293
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1294
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
1295
|
+
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;
|
|
1296
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1297
|
+
}
|
|
1298
|
+
__name(_ts_decorate8, "_ts_decorate");
|
|
1299
|
+
var _RandomSelectorExecutor = class _RandomSelectorExecutor {
|
|
1300
|
+
execute(context) {
|
|
1301
|
+
const { nodeData, state } = context;
|
|
1302
|
+
if (!nodeData.children || nodeData.children.length === 0) {
|
|
1303
|
+
return TaskStatus.Failure;
|
|
1304
|
+
}
|
|
1305
|
+
if (!state.shuffledIndices || state.shuffledIndices.length === 0) {
|
|
1306
|
+
state.shuffledIndices = this.shuffleIndices(nodeData.children.length);
|
|
1307
|
+
}
|
|
1308
|
+
while (state.currentChildIndex < state.shuffledIndices.length) {
|
|
1309
|
+
const shuffledIndex = state.shuffledIndices[state.currentChildIndex];
|
|
1310
|
+
const childId = nodeData.children[shuffledIndex];
|
|
1311
|
+
const status = context.executeChild(childId);
|
|
1312
|
+
if (status === TaskStatus.Running) {
|
|
1313
|
+
return TaskStatus.Running;
|
|
1314
|
+
}
|
|
1315
|
+
if (status === TaskStatus.Success) {
|
|
1316
|
+
state.currentChildIndex = 0;
|
|
1317
|
+
delete state.shuffledIndices;
|
|
1318
|
+
return TaskStatus.Success;
|
|
1319
|
+
}
|
|
1320
|
+
state.currentChildIndex++;
|
|
1321
|
+
}
|
|
1322
|
+
state.currentChildIndex = 0;
|
|
1323
|
+
delete state.shuffledIndices;
|
|
1324
|
+
return TaskStatus.Failure;
|
|
1325
|
+
}
|
|
1326
|
+
shuffleIndices(length) {
|
|
1327
|
+
const indices = Array.from({
|
|
1328
|
+
length
|
|
1329
|
+
}, (_, i) => i);
|
|
1330
|
+
for (let i = indices.length - 1; i > 0; i--) {
|
|
1331
|
+
const j = Math.floor(Math.random() * (i + 1));
|
|
1332
|
+
const temp = indices[i];
|
|
1333
|
+
indices[i] = indices[j];
|
|
1334
|
+
indices[j] = temp;
|
|
1335
|
+
}
|
|
1336
|
+
return indices;
|
|
1337
|
+
}
|
|
1338
|
+
reset(context) {
|
|
1339
|
+
context.state.currentChildIndex = 0;
|
|
1340
|
+
delete context.state.shuffledIndices;
|
|
1341
|
+
}
|
|
1342
|
+
};
|
|
1343
|
+
__name(_RandomSelectorExecutor, "RandomSelectorExecutor");
|
|
1344
|
+
var RandomSelectorExecutor = _RandomSelectorExecutor;
|
|
1345
|
+
RandomSelectorExecutor = _ts_decorate8([
|
|
1346
|
+
NodeExecutorMetadata({
|
|
1347
|
+
implementationType: "RandomSelector",
|
|
1348
|
+
nodeType: NodeType.Composite,
|
|
1349
|
+
displayName: "\u968F\u673A\u9009\u62E9\u5668",
|
|
1350
|
+
description: "\u968F\u673A\u987A\u5E8F\u6267\u884C\u5B50\u8282\u70B9\uFF0C\u4EFB\u4E00\u6210\u529F\u5219\u6210\u529F",
|
|
1351
|
+
category: "Composite"
|
|
1352
|
+
})
|
|
1353
|
+
], RandomSelectorExecutor);
|
|
1354
|
+
|
|
1355
|
+
// src/execution/Executors/InverterExecutor.ts
|
|
1356
|
+
function _ts_decorate9(decorators, target, key, desc) {
|
|
1357
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1358
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
1359
|
+
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;
|
|
1360
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1361
|
+
}
|
|
1362
|
+
__name(_ts_decorate9, "_ts_decorate");
|
|
1363
|
+
var _InverterExecutor = class _InverterExecutor {
|
|
1364
|
+
execute(context) {
|
|
1365
|
+
const { nodeData } = context;
|
|
1366
|
+
if (!nodeData.children || nodeData.children.length === 0) {
|
|
1367
|
+
return TaskStatus.Failure;
|
|
1368
|
+
}
|
|
1369
|
+
const childId = nodeData.children[0];
|
|
1370
|
+
const status = context.executeChild(childId);
|
|
1371
|
+
if (status === TaskStatus.Running) {
|
|
1372
|
+
return TaskStatus.Running;
|
|
1373
|
+
}
|
|
1374
|
+
if (status === TaskStatus.Success) {
|
|
1375
|
+
return TaskStatus.Failure;
|
|
1376
|
+
}
|
|
1377
|
+
if (status === TaskStatus.Failure) {
|
|
1378
|
+
return TaskStatus.Success;
|
|
1379
|
+
}
|
|
1380
|
+
return TaskStatus.Failure;
|
|
1381
|
+
}
|
|
1382
|
+
reset(context) {
|
|
1383
|
+
if (context.nodeData.children && context.nodeData.children.length > 0) {
|
|
1384
|
+
context.runtime.resetNodeState(context.nodeData.children[0]);
|
|
1385
|
+
}
|
|
1386
|
+
}
|
|
1387
|
+
};
|
|
1388
|
+
__name(_InverterExecutor, "InverterExecutor");
|
|
1389
|
+
var InverterExecutor = _InverterExecutor;
|
|
1390
|
+
InverterExecutor = _ts_decorate9([
|
|
1391
|
+
NodeExecutorMetadata({
|
|
1392
|
+
implementationType: "Inverter",
|
|
1393
|
+
nodeType: NodeType.Decorator,
|
|
1394
|
+
displayName: "\u53CD\u8F6C",
|
|
1395
|
+
description: "\u53CD\u8F6C\u5B50\u8282\u70B9\u7684\u6267\u884C\u7ED3\u679C",
|
|
1396
|
+
category: "Decorator",
|
|
1397
|
+
childrenConstraints: {
|
|
1398
|
+
min: 1,
|
|
1399
|
+
max: 1
|
|
1400
|
+
}
|
|
1401
|
+
})
|
|
1402
|
+
], InverterExecutor);
|
|
1403
|
+
|
|
1404
|
+
// src/execution/Executors/RepeaterExecutor.ts
|
|
1405
|
+
function _ts_decorate10(decorators, target, key, desc) {
|
|
1406
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1407
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
1408
|
+
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;
|
|
1409
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1410
|
+
}
|
|
1411
|
+
__name(_ts_decorate10, "_ts_decorate");
|
|
1412
|
+
var _RepeaterExecutor = class _RepeaterExecutor {
|
|
1413
|
+
execute(context) {
|
|
1414
|
+
const { nodeData, state, runtime } = context;
|
|
1415
|
+
const repeatCount = BindingHelper.getValue(context, "repeatCount", 1);
|
|
1416
|
+
const endOnFailure = BindingHelper.getValue(context, "endOnFailure", false);
|
|
1417
|
+
if (!nodeData.children || nodeData.children.length === 0) {
|
|
1418
|
+
return TaskStatus.Success;
|
|
1419
|
+
}
|
|
1420
|
+
const childId = nodeData.children[0];
|
|
1421
|
+
if (!state.repeatCount) {
|
|
1422
|
+
state.repeatCount = 0;
|
|
1423
|
+
}
|
|
1424
|
+
const status = context.executeChild(childId);
|
|
1425
|
+
if (status === TaskStatus.Running) {
|
|
1426
|
+
return TaskStatus.Running;
|
|
1427
|
+
}
|
|
1428
|
+
if (status === TaskStatus.Failure && endOnFailure) {
|
|
1429
|
+
state.repeatCount = 0;
|
|
1430
|
+
return TaskStatus.Failure;
|
|
1431
|
+
}
|
|
1432
|
+
state.repeatCount++;
|
|
1433
|
+
runtime.resetNodeState(childId);
|
|
1434
|
+
const shouldContinue = repeatCount === -1 || state.repeatCount < repeatCount;
|
|
1435
|
+
if (shouldContinue) {
|
|
1436
|
+
return TaskStatus.Running;
|
|
1437
|
+
} else {
|
|
1438
|
+
state.repeatCount = 0;
|
|
1439
|
+
return TaskStatus.Success;
|
|
1440
|
+
}
|
|
1441
|
+
}
|
|
1442
|
+
reset(context) {
|
|
1443
|
+
delete context.state.repeatCount;
|
|
1444
|
+
if (context.nodeData.children && context.nodeData.children.length > 0) {
|
|
1445
|
+
context.runtime.resetNodeState(context.nodeData.children[0]);
|
|
1446
|
+
}
|
|
1447
|
+
}
|
|
1448
|
+
};
|
|
1449
|
+
__name(_RepeaterExecutor, "RepeaterExecutor");
|
|
1450
|
+
var RepeaterExecutor = _RepeaterExecutor;
|
|
1451
|
+
RepeaterExecutor = _ts_decorate10([
|
|
1452
|
+
NodeExecutorMetadata({
|
|
1453
|
+
implementationType: "Repeater",
|
|
1454
|
+
nodeType: NodeType.Decorator,
|
|
1455
|
+
displayName: "\u91CD\u590D",
|
|
1456
|
+
description: "\u91CD\u590D\u6267\u884C\u5B50\u8282\u70B9\u6307\u5B9A\u6B21\u6570",
|
|
1457
|
+
category: "Decorator",
|
|
1458
|
+
configSchema: {
|
|
1459
|
+
repeatCount: {
|
|
1460
|
+
type: "number",
|
|
1461
|
+
default: 1,
|
|
1462
|
+
description: "\u91CD\u590D\u6B21\u6570\uFF08-1\u8868\u793A\u65E0\u9650\u5FAA\u73AF\uFF09",
|
|
1463
|
+
supportBinding: true
|
|
1464
|
+
},
|
|
1465
|
+
endOnFailure: {
|
|
1466
|
+
type: "boolean",
|
|
1467
|
+
default: false,
|
|
1468
|
+
description: "\u5B50\u8282\u70B9\u5931\u8D25\u65F6\u662F\u5426\u7ED3\u675F"
|
|
1469
|
+
}
|
|
1470
|
+
},
|
|
1471
|
+
childrenConstraints: {
|
|
1472
|
+
min: 1,
|
|
1473
|
+
max: 1
|
|
1474
|
+
}
|
|
1475
|
+
})
|
|
1476
|
+
], RepeaterExecutor);
|
|
1477
|
+
|
|
1478
|
+
// src/execution/Executors/AlwaysSucceedExecutor.ts
|
|
1479
|
+
function _ts_decorate11(decorators, target, key, desc) {
|
|
1480
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1481
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
1482
|
+
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;
|
|
1483
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1484
|
+
}
|
|
1485
|
+
__name(_ts_decorate11, "_ts_decorate");
|
|
1486
|
+
var _AlwaysSucceedExecutor = class _AlwaysSucceedExecutor {
|
|
1487
|
+
execute(context) {
|
|
1488
|
+
const { nodeData } = context;
|
|
1489
|
+
if (!nodeData.children || nodeData.children.length === 0) {
|
|
1490
|
+
return TaskStatus.Success;
|
|
1491
|
+
}
|
|
1492
|
+
const childId = nodeData.children[0];
|
|
1493
|
+
const status = context.executeChild(childId);
|
|
1494
|
+
if (status === TaskStatus.Running) {
|
|
1495
|
+
return TaskStatus.Running;
|
|
1496
|
+
}
|
|
1497
|
+
return TaskStatus.Success;
|
|
1498
|
+
}
|
|
1499
|
+
reset(context) {
|
|
1500
|
+
if (context.nodeData.children && context.nodeData.children.length > 0) {
|
|
1501
|
+
context.runtime.resetNodeState(context.nodeData.children[0]);
|
|
1502
|
+
}
|
|
1503
|
+
}
|
|
1504
|
+
};
|
|
1505
|
+
__name(_AlwaysSucceedExecutor, "AlwaysSucceedExecutor");
|
|
1506
|
+
var AlwaysSucceedExecutor = _AlwaysSucceedExecutor;
|
|
1507
|
+
AlwaysSucceedExecutor = _ts_decorate11([
|
|
1508
|
+
NodeExecutorMetadata({
|
|
1509
|
+
implementationType: "AlwaysSucceed",
|
|
1510
|
+
nodeType: NodeType.Decorator,
|
|
1511
|
+
displayName: "\u603B\u662F\u6210\u529F",
|
|
1512
|
+
description: "\u65E0\u8BBA\u5B50\u8282\u70B9\u7ED3\u679C\u5982\u4F55\u90FD\u8FD4\u56DE\u6210\u529F",
|
|
1513
|
+
category: "Decorator"
|
|
1514
|
+
})
|
|
1515
|
+
], AlwaysSucceedExecutor);
|
|
1516
|
+
|
|
1517
|
+
// src/execution/Executors/AlwaysFailExecutor.ts
|
|
1518
|
+
function _ts_decorate12(decorators, target, key, desc) {
|
|
1519
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1520
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
1521
|
+
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;
|
|
1522
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1523
|
+
}
|
|
1524
|
+
__name(_ts_decorate12, "_ts_decorate");
|
|
1525
|
+
var _AlwaysFailExecutor = class _AlwaysFailExecutor {
|
|
1526
|
+
execute(context) {
|
|
1527
|
+
const { nodeData } = context;
|
|
1528
|
+
if (!nodeData.children || nodeData.children.length === 0) {
|
|
1529
|
+
return TaskStatus.Failure;
|
|
1530
|
+
}
|
|
1531
|
+
const childId = nodeData.children[0];
|
|
1532
|
+
const status = context.executeChild(childId);
|
|
1533
|
+
if (status === TaskStatus.Running) {
|
|
1534
|
+
return TaskStatus.Running;
|
|
1535
|
+
}
|
|
1536
|
+
return TaskStatus.Failure;
|
|
1537
|
+
}
|
|
1538
|
+
reset(context) {
|
|
1539
|
+
if (context.nodeData.children && context.nodeData.children.length > 0) {
|
|
1540
|
+
context.runtime.resetNodeState(context.nodeData.children[0]);
|
|
1541
|
+
}
|
|
1542
|
+
}
|
|
1543
|
+
};
|
|
1544
|
+
__name(_AlwaysFailExecutor, "AlwaysFailExecutor");
|
|
1545
|
+
var AlwaysFailExecutor = _AlwaysFailExecutor;
|
|
1546
|
+
AlwaysFailExecutor = _ts_decorate12([
|
|
1547
|
+
NodeExecutorMetadata({
|
|
1548
|
+
implementationType: "AlwaysFail",
|
|
1549
|
+
nodeType: NodeType.Decorator,
|
|
1550
|
+
displayName: "\u603B\u662F\u5931\u8D25",
|
|
1551
|
+
description: "\u65E0\u8BBA\u5B50\u8282\u70B9\u7ED3\u679C\u5982\u4F55\u90FD\u8FD4\u56DE\u5931\u8D25",
|
|
1552
|
+
category: "Decorator"
|
|
1553
|
+
})
|
|
1554
|
+
], AlwaysFailExecutor);
|
|
1555
|
+
|
|
1556
|
+
// src/execution/Executors/UntilSuccessExecutor.ts
|
|
1557
|
+
function _ts_decorate13(decorators, target, key, desc) {
|
|
1558
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1559
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
1560
|
+
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;
|
|
1561
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1562
|
+
}
|
|
1563
|
+
__name(_ts_decorate13, "_ts_decorate");
|
|
1564
|
+
var _UntilSuccessExecutor = class _UntilSuccessExecutor {
|
|
1565
|
+
execute(context) {
|
|
1566
|
+
const { nodeData, runtime } = context;
|
|
1567
|
+
if (!nodeData.children || nodeData.children.length === 0) {
|
|
1568
|
+
return TaskStatus.Failure;
|
|
1569
|
+
}
|
|
1570
|
+
const childId = nodeData.children[0];
|
|
1571
|
+
const status = context.executeChild(childId);
|
|
1572
|
+
if (status === TaskStatus.Running) {
|
|
1573
|
+
return TaskStatus.Running;
|
|
1574
|
+
}
|
|
1575
|
+
if (status === TaskStatus.Success) {
|
|
1576
|
+
return TaskStatus.Success;
|
|
1577
|
+
}
|
|
1578
|
+
runtime.resetNodeState(childId);
|
|
1579
|
+
return TaskStatus.Running;
|
|
1580
|
+
}
|
|
1581
|
+
reset(context) {
|
|
1582
|
+
if (context.nodeData.children && context.nodeData.children.length > 0) {
|
|
1583
|
+
context.runtime.resetNodeState(context.nodeData.children[0]);
|
|
1584
|
+
}
|
|
1585
|
+
}
|
|
1586
|
+
};
|
|
1587
|
+
__name(_UntilSuccessExecutor, "UntilSuccessExecutor");
|
|
1588
|
+
var UntilSuccessExecutor = _UntilSuccessExecutor;
|
|
1589
|
+
UntilSuccessExecutor = _ts_decorate13([
|
|
1590
|
+
NodeExecutorMetadata({
|
|
1591
|
+
implementationType: "UntilSuccess",
|
|
1592
|
+
nodeType: NodeType.Decorator,
|
|
1593
|
+
displayName: "\u76F4\u5230\u6210\u529F",
|
|
1594
|
+
description: "\u91CD\u590D\u6267\u884C\u5B50\u8282\u70B9\u76F4\u5230\u6210\u529F",
|
|
1595
|
+
category: "Decorator"
|
|
1596
|
+
})
|
|
1597
|
+
], UntilSuccessExecutor);
|
|
1598
|
+
|
|
1599
|
+
// src/execution/Executors/UntilFailExecutor.ts
|
|
1600
|
+
function _ts_decorate14(decorators, target, key, desc) {
|
|
1601
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1602
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
1603
|
+
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;
|
|
1604
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1605
|
+
}
|
|
1606
|
+
__name(_ts_decorate14, "_ts_decorate");
|
|
1607
|
+
var _UntilFailExecutor = class _UntilFailExecutor {
|
|
1608
|
+
execute(context) {
|
|
1609
|
+
const { nodeData, runtime } = context;
|
|
1610
|
+
if (!nodeData.children || nodeData.children.length === 0) {
|
|
1611
|
+
return TaskStatus.Success;
|
|
1612
|
+
}
|
|
1613
|
+
const childId = nodeData.children[0];
|
|
1614
|
+
const status = context.executeChild(childId);
|
|
1615
|
+
if (status === TaskStatus.Running) {
|
|
1616
|
+
return TaskStatus.Running;
|
|
1617
|
+
}
|
|
1618
|
+
if (status === TaskStatus.Failure) {
|
|
1619
|
+
return TaskStatus.Failure;
|
|
1620
|
+
}
|
|
1621
|
+
runtime.resetNodeState(childId);
|
|
1622
|
+
return TaskStatus.Running;
|
|
1623
|
+
}
|
|
1624
|
+
reset(context) {
|
|
1625
|
+
if (context.nodeData.children && context.nodeData.children.length > 0) {
|
|
1626
|
+
context.runtime.resetNodeState(context.nodeData.children[0]);
|
|
1627
|
+
}
|
|
1628
|
+
}
|
|
1629
|
+
};
|
|
1630
|
+
__name(_UntilFailExecutor, "UntilFailExecutor");
|
|
1631
|
+
var UntilFailExecutor = _UntilFailExecutor;
|
|
1632
|
+
UntilFailExecutor = _ts_decorate14([
|
|
1633
|
+
NodeExecutorMetadata({
|
|
1634
|
+
implementationType: "UntilFail",
|
|
1635
|
+
nodeType: NodeType.Decorator,
|
|
1636
|
+
displayName: "\u76F4\u5230\u5931\u8D25",
|
|
1637
|
+
description: "\u91CD\u590D\u6267\u884C\u5B50\u8282\u70B9\u76F4\u5230\u5931\u8D25",
|
|
1638
|
+
category: "Decorator"
|
|
1639
|
+
})
|
|
1640
|
+
], UntilFailExecutor);
|
|
1641
|
+
|
|
1642
|
+
// src/execution/Executors/ConditionalExecutor.ts
|
|
1643
|
+
function _ts_decorate15(decorators, target, key, desc) {
|
|
1644
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1645
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
1646
|
+
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;
|
|
1647
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1648
|
+
}
|
|
1649
|
+
__name(_ts_decorate15, "_ts_decorate");
|
|
1650
|
+
var _ConditionalExecutor = class _ConditionalExecutor {
|
|
1651
|
+
execute(context) {
|
|
1652
|
+
const { nodeData, runtime, state } = context;
|
|
1653
|
+
if (!nodeData.children || nodeData.children.length === 0) {
|
|
1654
|
+
return TaskStatus.Failure;
|
|
1655
|
+
}
|
|
1656
|
+
const blackboardKey = BindingHelper.getValue(context, "blackboardKey", "");
|
|
1657
|
+
const expectedValue = BindingHelper.getValue(context, "expectedValue");
|
|
1658
|
+
const operator = BindingHelper.getValue(context, "operator", "equals");
|
|
1659
|
+
const abortType = nodeData.abortType || AbortType.None;
|
|
1660
|
+
if (!blackboardKey) {
|
|
1661
|
+
return TaskStatus.Failure;
|
|
1662
|
+
}
|
|
1663
|
+
const actualValue = runtime.getBlackboardValue(blackboardKey);
|
|
1664
|
+
const conditionMet = this.evaluateCondition(actualValue, expectedValue, operator);
|
|
1665
|
+
const wasRunning = state.status === TaskStatus.Running;
|
|
1666
|
+
if (abortType !== AbortType.None) {
|
|
1667
|
+
if (!state.observedKeys || state.observedKeys.length === 0) {
|
|
1668
|
+
state.observedKeys = [
|
|
1669
|
+
blackboardKey
|
|
1670
|
+
];
|
|
1671
|
+
this.setupObserver(context, blackboardKey, expectedValue, operator, abortType);
|
|
1672
|
+
}
|
|
1673
|
+
if (state.lastConditionResult !== void 0 && state.lastConditionResult !== conditionMet) {
|
|
1674
|
+
if (conditionMet) {
|
|
1675
|
+
this.handleConditionBecameTrue(context, abortType);
|
|
1676
|
+
} else if (wasRunning) {
|
|
1677
|
+
this.handleConditionBecameFalse(context, abortType);
|
|
1678
|
+
}
|
|
1679
|
+
}
|
|
1680
|
+
}
|
|
1681
|
+
state.lastConditionResult = conditionMet;
|
|
1682
|
+
if (!conditionMet) {
|
|
1683
|
+
return TaskStatus.Failure;
|
|
1684
|
+
}
|
|
1685
|
+
const childId = nodeData.children[0];
|
|
1686
|
+
const status = context.executeChild(childId);
|
|
1687
|
+
return status;
|
|
1688
|
+
}
|
|
1689
|
+
evaluateCondition(actualValue, expectedValue, operator) {
|
|
1690
|
+
switch (operator) {
|
|
1691
|
+
case "equals":
|
|
1692
|
+
return actualValue === expectedValue;
|
|
1693
|
+
case "notEquals":
|
|
1694
|
+
return actualValue !== expectedValue;
|
|
1695
|
+
case "greaterThan":
|
|
1696
|
+
return actualValue > expectedValue;
|
|
1697
|
+
case "lessThan":
|
|
1698
|
+
return actualValue < expectedValue;
|
|
1699
|
+
case "greaterOrEqual":
|
|
1700
|
+
return actualValue >= expectedValue;
|
|
1701
|
+
case "lessOrEqual":
|
|
1702
|
+
return actualValue <= expectedValue;
|
|
1703
|
+
default:
|
|
1704
|
+
return false;
|
|
1705
|
+
}
|
|
1706
|
+
}
|
|
1707
|
+
/**
|
|
1708
|
+
* 设置黑板观察者
|
|
1709
|
+
*/
|
|
1710
|
+
setupObserver(context, blackboardKey, expectedValue, operator, abortType) {
|
|
1711
|
+
const { nodeData, runtime } = context;
|
|
1712
|
+
runtime.observeBlackboard(nodeData.id, [
|
|
1713
|
+
blackboardKey
|
|
1714
|
+
], (_key, newValue) => {
|
|
1715
|
+
const conditionMet = this.evaluateCondition(newValue, expectedValue, operator);
|
|
1716
|
+
const lastResult = context.state.lastConditionResult;
|
|
1717
|
+
if (lastResult !== void 0 && lastResult !== conditionMet) {
|
|
1718
|
+
if (conditionMet) {
|
|
1719
|
+
this.handleConditionBecameTrue(context, abortType);
|
|
1720
|
+
} else {
|
|
1721
|
+
this.handleConditionBecameFalse(context, abortType);
|
|
1722
|
+
}
|
|
1723
|
+
}
|
|
1724
|
+
context.state.lastConditionResult = conditionMet;
|
|
1725
|
+
});
|
|
1726
|
+
}
|
|
1727
|
+
/**
|
|
1728
|
+
* 处理条件变为true
|
|
1729
|
+
*/
|
|
1730
|
+
handleConditionBecameTrue(context, abortType) {
|
|
1731
|
+
if (abortType === AbortType.LowerPriority || abortType === AbortType.Both) {
|
|
1732
|
+
this.requestAbortLowerPriority(context);
|
|
1733
|
+
}
|
|
1734
|
+
}
|
|
1735
|
+
/**
|
|
1736
|
+
* 处理条件变为false
|
|
1737
|
+
*/
|
|
1738
|
+
handleConditionBecameFalse(context, abortType) {
|
|
1739
|
+
const { nodeData, runtime } = context;
|
|
1740
|
+
if (abortType === AbortType.Self || abortType === AbortType.Both) {
|
|
1741
|
+
if (nodeData.children && nodeData.children.length > 0) {
|
|
1742
|
+
runtime.requestAbort(nodeData.children[0]);
|
|
1743
|
+
}
|
|
1744
|
+
}
|
|
1745
|
+
}
|
|
1746
|
+
/**
|
|
1747
|
+
* 请求中止低优先级节点
|
|
1748
|
+
*/
|
|
1749
|
+
requestAbortLowerPriority(context) {
|
|
1750
|
+
const { runtime } = context;
|
|
1751
|
+
runtime.requestAbort("__lower_priority__");
|
|
1752
|
+
}
|
|
1753
|
+
reset(context) {
|
|
1754
|
+
const { nodeData, runtime, state } = context;
|
|
1755
|
+
if (state.observedKeys && state.observedKeys.length > 0) {
|
|
1756
|
+
runtime.unobserveBlackboard(nodeData.id);
|
|
1757
|
+
delete state.observedKeys;
|
|
1758
|
+
}
|
|
1759
|
+
delete state.lastConditionResult;
|
|
1760
|
+
if (nodeData.children && nodeData.children.length > 0) {
|
|
1761
|
+
runtime.resetNodeState(nodeData.children[0]);
|
|
1762
|
+
}
|
|
1763
|
+
}
|
|
1764
|
+
};
|
|
1765
|
+
__name(_ConditionalExecutor, "ConditionalExecutor");
|
|
1766
|
+
var ConditionalExecutor = _ConditionalExecutor;
|
|
1767
|
+
ConditionalExecutor = _ts_decorate15([
|
|
1768
|
+
NodeExecutorMetadata({
|
|
1769
|
+
implementationType: "Conditional",
|
|
1770
|
+
nodeType: NodeType.Decorator,
|
|
1771
|
+
displayName: "\u6761\u4EF6",
|
|
1772
|
+
description: "\u6839\u636E\u6761\u4EF6\u51B3\u5B9A\u662F\u5426\u6267\u884C\u5B50\u8282\u70B9",
|
|
1773
|
+
category: "Decorator",
|
|
1774
|
+
configSchema: {
|
|
1775
|
+
blackboardKey: {
|
|
1776
|
+
type: "string",
|
|
1777
|
+
default: "",
|
|
1778
|
+
description: "\u9ED1\u677F\u53D8\u91CF\u540D"
|
|
1779
|
+
},
|
|
1780
|
+
expectedValue: {
|
|
1781
|
+
type: "object",
|
|
1782
|
+
description: "\u671F\u671B\u503C",
|
|
1783
|
+
supportBinding: true
|
|
1784
|
+
},
|
|
1785
|
+
operator: {
|
|
1786
|
+
type: "string",
|
|
1787
|
+
default: "equals",
|
|
1788
|
+
description: "\u6BD4\u8F83\u8FD0\u7B97\u7B26",
|
|
1789
|
+
options: [
|
|
1790
|
+
"equals",
|
|
1791
|
+
"notEquals",
|
|
1792
|
+
"greaterThan",
|
|
1793
|
+
"lessThan",
|
|
1794
|
+
"greaterOrEqual",
|
|
1795
|
+
"lessOrEqual"
|
|
1796
|
+
]
|
|
1797
|
+
},
|
|
1798
|
+
abortType: {
|
|
1799
|
+
type: "string",
|
|
1800
|
+
default: "none",
|
|
1801
|
+
description: "\u4E2D\u6B62\u7C7B\u578B",
|
|
1802
|
+
options: [
|
|
1803
|
+
"none",
|
|
1804
|
+
"self",
|
|
1805
|
+
"lower-priority",
|
|
1806
|
+
"both"
|
|
1807
|
+
]
|
|
1808
|
+
}
|
|
1809
|
+
}
|
|
1810
|
+
})
|
|
1811
|
+
], ConditionalExecutor);
|
|
1812
|
+
|
|
1813
|
+
// src/execution/Executors/CooldownExecutor.ts
|
|
1814
|
+
function _ts_decorate16(decorators, target, key, desc) {
|
|
1815
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1816
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
1817
|
+
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;
|
|
1818
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1819
|
+
}
|
|
1820
|
+
__name(_ts_decorate16, "_ts_decorate");
|
|
1821
|
+
var _CooldownExecutor = class _CooldownExecutor {
|
|
1822
|
+
execute(context) {
|
|
1823
|
+
const { nodeData, state, totalTime } = context;
|
|
1824
|
+
if (!nodeData.children || nodeData.children.length === 0) {
|
|
1825
|
+
return TaskStatus.Failure;
|
|
1826
|
+
}
|
|
1827
|
+
const cooldownTime = BindingHelper.getValue(context, "cooldownTime", 1);
|
|
1828
|
+
if (state.lastExecutionTime !== void 0) {
|
|
1829
|
+
const timeSinceLastExecution = totalTime - state.lastExecutionTime;
|
|
1830
|
+
if (timeSinceLastExecution < cooldownTime) {
|
|
1831
|
+
return TaskStatus.Failure;
|
|
1832
|
+
}
|
|
1833
|
+
}
|
|
1834
|
+
const childId = nodeData.children[0];
|
|
1835
|
+
const status = context.executeChild(childId);
|
|
1836
|
+
if (status === TaskStatus.Running) {
|
|
1837
|
+
return TaskStatus.Running;
|
|
1838
|
+
}
|
|
1839
|
+
if (status === TaskStatus.Success) {
|
|
1840
|
+
state.lastExecutionTime = totalTime;
|
|
1841
|
+
return TaskStatus.Success;
|
|
1842
|
+
}
|
|
1843
|
+
return TaskStatus.Failure;
|
|
1844
|
+
}
|
|
1845
|
+
reset(context) {
|
|
1846
|
+
delete context.state.lastExecutionTime;
|
|
1847
|
+
if (context.nodeData.children && context.nodeData.children.length > 0) {
|
|
1848
|
+
context.runtime.resetNodeState(context.nodeData.children[0]);
|
|
1849
|
+
}
|
|
1850
|
+
}
|
|
1851
|
+
};
|
|
1852
|
+
__name(_CooldownExecutor, "CooldownExecutor");
|
|
1853
|
+
var CooldownExecutor = _CooldownExecutor;
|
|
1854
|
+
CooldownExecutor = _ts_decorate16([
|
|
1855
|
+
NodeExecutorMetadata({
|
|
1856
|
+
implementationType: "Cooldown",
|
|
1857
|
+
nodeType: NodeType.Decorator,
|
|
1858
|
+
displayName: "\u51B7\u5374",
|
|
1859
|
+
description: "\u5B50\u8282\u70B9\u6267\u884C\u6210\u529F\u540E\u8FDB\u5165\u51B7\u5374\u65F6\u95F4",
|
|
1860
|
+
category: "Decorator",
|
|
1861
|
+
configSchema: {
|
|
1862
|
+
cooldownTime: {
|
|
1863
|
+
type: "number",
|
|
1864
|
+
default: 1,
|
|
1865
|
+
description: "\u51B7\u5374\u65F6\u95F4\uFF08\u79D2\uFF09",
|
|
1866
|
+
min: 0,
|
|
1867
|
+
supportBinding: true
|
|
1868
|
+
}
|
|
1869
|
+
}
|
|
1870
|
+
})
|
|
1871
|
+
], CooldownExecutor);
|
|
1872
|
+
|
|
1873
|
+
// src/execution/Executors/TimeoutExecutor.ts
|
|
1874
|
+
function _ts_decorate17(decorators, target, key, desc) {
|
|
1875
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1876
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
1877
|
+
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;
|
|
1878
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1879
|
+
}
|
|
1880
|
+
__name(_ts_decorate17, "_ts_decorate");
|
|
1881
|
+
var _TimeoutExecutor = class _TimeoutExecutor {
|
|
1882
|
+
execute(context) {
|
|
1883
|
+
const { nodeData, state, totalTime } = context;
|
|
1884
|
+
if (!nodeData.children || nodeData.children.length === 0) {
|
|
1885
|
+
return TaskStatus.Failure;
|
|
1886
|
+
}
|
|
1887
|
+
const timeout = BindingHelper.getValue(context, "timeout", 1);
|
|
1888
|
+
if (state.startTime === void 0) {
|
|
1889
|
+
state.startTime = totalTime;
|
|
1890
|
+
}
|
|
1891
|
+
const elapsedTime = totalTime - state.startTime;
|
|
1892
|
+
if (elapsedTime >= timeout) {
|
|
1893
|
+
delete state.startTime;
|
|
1894
|
+
return TaskStatus.Failure;
|
|
1895
|
+
}
|
|
1896
|
+
const childId = nodeData.children[0];
|
|
1897
|
+
const status = context.executeChild(childId);
|
|
1898
|
+
if (status === TaskStatus.Running) {
|
|
1899
|
+
return TaskStatus.Running;
|
|
1900
|
+
}
|
|
1901
|
+
delete state.startTime;
|
|
1902
|
+
return status;
|
|
1903
|
+
}
|
|
1904
|
+
reset(context) {
|
|
1905
|
+
delete context.state.startTime;
|
|
1906
|
+
if (context.nodeData.children && context.nodeData.children.length > 0) {
|
|
1907
|
+
context.runtime.resetNodeState(context.nodeData.children[0]);
|
|
1908
|
+
}
|
|
1909
|
+
}
|
|
1910
|
+
};
|
|
1911
|
+
__name(_TimeoutExecutor, "TimeoutExecutor");
|
|
1912
|
+
var TimeoutExecutor = _TimeoutExecutor;
|
|
1913
|
+
TimeoutExecutor = _ts_decorate17([
|
|
1914
|
+
NodeExecutorMetadata({
|
|
1915
|
+
implementationType: "Timeout",
|
|
1916
|
+
nodeType: NodeType.Decorator,
|
|
1917
|
+
displayName: "\u8D85\u65F6",
|
|
1918
|
+
description: "\u9650\u5236\u5B50\u8282\u70B9\u7684\u6267\u884C\u65F6\u95F4",
|
|
1919
|
+
category: "Decorator",
|
|
1920
|
+
configSchema: {
|
|
1921
|
+
timeout: {
|
|
1922
|
+
type: "number",
|
|
1923
|
+
default: 1,
|
|
1924
|
+
description: "\u8D85\u65F6\u65F6\u95F4\uFF08\u79D2\uFF09",
|
|
1925
|
+
min: 0,
|
|
1926
|
+
supportBinding: true
|
|
1927
|
+
}
|
|
1928
|
+
}
|
|
1929
|
+
})
|
|
1930
|
+
], TimeoutExecutor);
|
|
1931
|
+
|
|
1932
|
+
// src/execution/Executors/ServiceDecorator.ts
|
|
1933
|
+
function _ts_decorate18(decorators, target, key, desc) {
|
|
1934
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1935
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
1936
|
+
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;
|
|
1937
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1938
|
+
}
|
|
1939
|
+
__name(_ts_decorate18, "_ts_decorate");
|
|
1940
|
+
var _a;
|
|
1941
|
+
var ServiceRegistry = (_a = class {
|
|
1942
|
+
static register(name, service) {
|
|
1943
|
+
this.services.set(name, service);
|
|
1944
|
+
}
|
|
1945
|
+
static get(name) {
|
|
1946
|
+
return this.services.get(name);
|
|
1947
|
+
}
|
|
1948
|
+
static has(name) {
|
|
1949
|
+
return this.services.has(name);
|
|
1950
|
+
}
|
|
1951
|
+
static unregister(name) {
|
|
1952
|
+
return this.services.delete(name);
|
|
1953
|
+
}
|
|
1954
|
+
}, __name(_a, "ServiceRegistry"), __publicField(_a, "services", /* @__PURE__ */ new Map()), _a);
|
|
1955
|
+
var _ServiceDecorator = class _ServiceDecorator {
|
|
1956
|
+
execute(context) {
|
|
1957
|
+
const { nodeData, state, totalTime } = context;
|
|
1958
|
+
if (!nodeData.children || nodeData.children.length === 0) {
|
|
1959
|
+
return TaskStatus.Failure;
|
|
1960
|
+
}
|
|
1961
|
+
const serviceName = BindingHelper.getValue(context, "serviceName", "");
|
|
1962
|
+
const tickInterval = BindingHelper.getValue(context, "tickInterval", 0);
|
|
1963
|
+
if (!serviceName) {
|
|
1964
|
+
return TaskStatus.Failure;
|
|
1965
|
+
}
|
|
1966
|
+
const service = ServiceRegistry.get(serviceName);
|
|
1967
|
+
if (!service) {
|
|
1968
|
+
console.warn(`\u672A\u627E\u5230Service: ${serviceName}`);
|
|
1969
|
+
return TaskStatus.Failure;
|
|
1970
|
+
}
|
|
1971
|
+
if (state.status !== TaskStatus.Running) {
|
|
1972
|
+
state.startTime = totalTime;
|
|
1973
|
+
state.lastExecutionTime = totalTime;
|
|
1974
|
+
if (service.onServiceStart) {
|
|
1975
|
+
service.onServiceStart(context);
|
|
1976
|
+
}
|
|
1977
|
+
}
|
|
1978
|
+
const shouldTick = tickInterval === 0 || state.lastExecutionTime !== void 0 && totalTime - state.lastExecutionTime >= tickInterval;
|
|
1979
|
+
if (shouldTick) {
|
|
1980
|
+
service.onServiceTick(context);
|
|
1981
|
+
state.lastExecutionTime = totalTime;
|
|
1982
|
+
}
|
|
1983
|
+
const childId = nodeData.children[0];
|
|
1984
|
+
const childStatus = context.executeChild(childId);
|
|
1985
|
+
if (childStatus !== TaskStatus.Running) {
|
|
1986
|
+
if (service.onServiceEnd) {
|
|
1987
|
+
service.onServiceEnd(context);
|
|
1988
|
+
}
|
|
1989
|
+
}
|
|
1990
|
+
return childStatus;
|
|
1991
|
+
}
|
|
1992
|
+
reset(context) {
|
|
1993
|
+
const { nodeData, runtime, state } = context;
|
|
1994
|
+
const serviceName = BindingHelper.getValue(context, "serviceName", "");
|
|
1995
|
+
if (serviceName) {
|
|
1996
|
+
const service = ServiceRegistry.get(serviceName);
|
|
1997
|
+
if (service && service.onServiceEnd) {
|
|
1998
|
+
service.onServiceEnd(context);
|
|
1999
|
+
}
|
|
2000
|
+
}
|
|
2001
|
+
delete state.startTime;
|
|
2002
|
+
delete state.lastExecutionTime;
|
|
2003
|
+
if (nodeData.children && nodeData.children.length > 0) {
|
|
2004
|
+
runtime.resetNodeState(nodeData.children[0]);
|
|
2005
|
+
}
|
|
2006
|
+
}
|
|
2007
|
+
};
|
|
2008
|
+
__name(_ServiceDecorator, "ServiceDecorator");
|
|
2009
|
+
var ServiceDecorator = _ServiceDecorator;
|
|
2010
|
+
ServiceDecorator = _ts_decorate18([
|
|
2011
|
+
NodeExecutorMetadata({
|
|
2012
|
+
implementationType: "Service",
|
|
2013
|
+
nodeType: NodeType.Decorator,
|
|
2014
|
+
displayName: "Service",
|
|
2015
|
+
description: "\u5728\u5B50\u8282\u70B9\u6267\u884C\u671F\u95F4\u6301\u7EED\u8FD0\u884C\u540E\u53F0\u903B\u8F91",
|
|
2016
|
+
category: "Decorator",
|
|
2017
|
+
configSchema: {
|
|
2018
|
+
serviceName: {
|
|
2019
|
+
type: "string",
|
|
2020
|
+
default: "",
|
|
2021
|
+
description: "Service\u540D\u79F0"
|
|
2022
|
+
},
|
|
2023
|
+
tickInterval: {
|
|
2024
|
+
type: "number",
|
|
2025
|
+
default: 0,
|
|
2026
|
+
description: "Service\u66F4\u65B0\u95F4\u9694\uFF08\u79D2\uFF0C0\u8868\u793A\u6BCF\u5E27\u66F4\u65B0\uFF09",
|
|
2027
|
+
supportBinding: true
|
|
2028
|
+
}
|
|
2029
|
+
}
|
|
2030
|
+
})
|
|
2031
|
+
], ServiceDecorator);
|
|
2032
|
+
|
|
2033
|
+
// src/execution/Executors/WaitAction.ts
|
|
2034
|
+
function _ts_decorate19(decorators, target, key, desc) {
|
|
2035
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2036
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
2037
|
+
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;
|
|
2038
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2039
|
+
}
|
|
2040
|
+
__name(_ts_decorate19, "_ts_decorate");
|
|
2041
|
+
var _WaitAction = class _WaitAction {
|
|
2042
|
+
execute(context) {
|
|
2043
|
+
const { state, totalTime } = context;
|
|
2044
|
+
const duration = BindingHelper.getValue(context, "duration", 1);
|
|
2045
|
+
if (!state.startTime) {
|
|
2046
|
+
state.startTime = totalTime;
|
|
2047
|
+
return TaskStatus.Running;
|
|
2048
|
+
}
|
|
2049
|
+
if (totalTime - state.startTime >= duration) {
|
|
2050
|
+
return TaskStatus.Success;
|
|
2051
|
+
}
|
|
2052
|
+
return TaskStatus.Running;
|
|
2053
|
+
}
|
|
2054
|
+
reset(context) {
|
|
2055
|
+
delete context.state.startTime;
|
|
2056
|
+
}
|
|
2057
|
+
};
|
|
2058
|
+
__name(_WaitAction, "WaitAction");
|
|
2059
|
+
var WaitAction = _WaitAction;
|
|
2060
|
+
WaitAction = _ts_decorate19([
|
|
2061
|
+
NodeExecutorMetadata({
|
|
2062
|
+
implementationType: "Wait",
|
|
2063
|
+
nodeType: NodeType.Action,
|
|
2064
|
+
displayName: "\u7B49\u5F85",
|
|
2065
|
+
description: "\u7B49\u5F85\u6307\u5B9A\u65F6\u95F4\u540E\u8FD4\u56DE\u6210\u529F",
|
|
2066
|
+
category: "Action",
|
|
2067
|
+
configSchema: {
|
|
2068
|
+
duration: {
|
|
2069
|
+
type: "number",
|
|
2070
|
+
default: 1,
|
|
2071
|
+
description: "\u7B49\u5F85\u65F6\u957F\uFF08\u79D2\uFF09",
|
|
2072
|
+
min: 0,
|
|
2073
|
+
supportBinding: true
|
|
2074
|
+
}
|
|
2075
|
+
}
|
|
2076
|
+
})
|
|
2077
|
+
], WaitAction);
|
|
2078
|
+
|
|
2079
|
+
// src/execution/Executors/LogAction.ts
|
|
2080
|
+
function _ts_decorate20(decorators, target, key, desc) {
|
|
2081
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2082
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
2083
|
+
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;
|
|
2084
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2085
|
+
}
|
|
2086
|
+
__name(_ts_decorate20, "_ts_decorate");
|
|
2087
|
+
var _LogAction = class _LogAction {
|
|
2088
|
+
execute(context) {
|
|
2089
|
+
const { runtime } = context;
|
|
2090
|
+
const message = BindingHelper.getValue(context, "message", "");
|
|
2091
|
+
const logLevel = BindingHelper.getValue(context, "logLevel", "info");
|
|
2092
|
+
const finalMessage = this.replaceBlackboardVariables(message, runtime);
|
|
2093
|
+
this.log(finalMessage, logLevel);
|
|
2094
|
+
return TaskStatus.Success;
|
|
2095
|
+
}
|
|
2096
|
+
replaceBlackboardVariables(message, runtime) {
|
|
2097
|
+
if (!message.includes("{") || !message.includes("}")) {
|
|
2098
|
+
return message;
|
|
2099
|
+
}
|
|
2100
|
+
return message.replace(/\{([\w.]{1,100})\}/g, (_, key) => {
|
|
2101
|
+
const value = runtime.getBlackboardValue(key.trim());
|
|
2102
|
+
return value !== void 0 ? String(value) : `{${key}}`;
|
|
2103
|
+
});
|
|
2104
|
+
}
|
|
2105
|
+
log(message, level) {
|
|
2106
|
+
switch (level) {
|
|
2107
|
+
case "error":
|
|
2108
|
+
console.error(message);
|
|
2109
|
+
break;
|
|
2110
|
+
case "warn":
|
|
2111
|
+
console.warn(message);
|
|
2112
|
+
break;
|
|
2113
|
+
case "info":
|
|
2114
|
+
default:
|
|
2115
|
+
console.log(message);
|
|
2116
|
+
break;
|
|
2117
|
+
}
|
|
2118
|
+
}
|
|
2119
|
+
};
|
|
2120
|
+
__name(_LogAction, "LogAction");
|
|
2121
|
+
var LogAction = _LogAction;
|
|
2122
|
+
LogAction = _ts_decorate20([
|
|
2123
|
+
NodeExecutorMetadata({
|
|
2124
|
+
implementationType: "Log",
|
|
2125
|
+
nodeType: NodeType.Action,
|
|
2126
|
+
displayName: "\u65E5\u5FD7",
|
|
2127
|
+
description: "\u8F93\u51FA\u65E5\u5FD7\u4FE1\u606F",
|
|
2128
|
+
category: "Action",
|
|
2129
|
+
configSchema: {
|
|
2130
|
+
message: {
|
|
2131
|
+
type: "string",
|
|
2132
|
+
default: "",
|
|
2133
|
+
description: "\u65E5\u5FD7\u6D88\u606F\uFF0C\u652F\u6301{key}\u5360\u4F4D\u7B26\u5F15\u7528\u9ED1\u677F\u53D8\u91CF",
|
|
2134
|
+
supportBinding: true
|
|
2135
|
+
},
|
|
2136
|
+
logLevel: {
|
|
2137
|
+
type: "string",
|
|
2138
|
+
default: "info",
|
|
2139
|
+
description: "\u65E5\u5FD7\u7EA7\u522B",
|
|
2140
|
+
options: [
|
|
2141
|
+
"info",
|
|
2142
|
+
"warn",
|
|
2143
|
+
"error"
|
|
2144
|
+
]
|
|
2145
|
+
}
|
|
2146
|
+
}
|
|
2147
|
+
})
|
|
2148
|
+
], LogAction);
|
|
2149
|
+
|
|
2150
|
+
// src/execution/Executors/SetBlackboardValue.ts
|
|
2151
|
+
function _ts_decorate21(decorators, target, key, desc) {
|
|
2152
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2153
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
2154
|
+
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;
|
|
2155
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2156
|
+
}
|
|
2157
|
+
__name(_ts_decorate21, "_ts_decorate");
|
|
2158
|
+
var _SetBlackboardValue = class _SetBlackboardValue {
|
|
2159
|
+
execute(context) {
|
|
2160
|
+
const { runtime } = context;
|
|
2161
|
+
const key = BindingHelper.getValue(context, "key", "");
|
|
2162
|
+
const value = BindingHelper.getValue(context, "value");
|
|
2163
|
+
if (!key) {
|
|
2164
|
+
return TaskStatus.Failure;
|
|
2165
|
+
}
|
|
2166
|
+
runtime.setBlackboardValue(key, value);
|
|
2167
|
+
return TaskStatus.Success;
|
|
2168
|
+
}
|
|
2169
|
+
};
|
|
2170
|
+
__name(_SetBlackboardValue, "SetBlackboardValue");
|
|
2171
|
+
var SetBlackboardValue = _SetBlackboardValue;
|
|
2172
|
+
SetBlackboardValue = _ts_decorate21([
|
|
2173
|
+
NodeExecutorMetadata({
|
|
2174
|
+
implementationType: "SetBlackboardValue",
|
|
2175
|
+
nodeType: NodeType.Action,
|
|
2176
|
+
displayName: "\u8BBE\u7F6E\u9ED1\u677F\u503C",
|
|
2177
|
+
description: "\u8BBE\u7F6E\u9ED1\u677F\u4E2D\u7684\u53D8\u91CF\u503C",
|
|
2178
|
+
category: "Action",
|
|
2179
|
+
configSchema: {
|
|
2180
|
+
key: {
|
|
2181
|
+
type: "string",
|
|
2182
|
+
default: "",
|
|
2183
|
+
description: "\u9ED1\u677F\u53D8\u91CF\u540D"
|
|
2184
|
+
},
|
|
2185
|
+
value: {
|
|
2186
|
+
type: "object",
|
|
2187
|
+
description: "\u8981\u8BBE\u7F6E\u7684\u503C",
|
|
2188
|
+
supportBinding: true
|
|
2189
|
+
}
|
|
2190
|
+
}
|
|
2191
|
+
})
|
|
2192
|
+
], SetBlackboardValue);
|
|
2193
|
+
|
|
2194
|
+
// src/execution/Executors/ModifyBlackboardValue.ts
|
|
2195
|
+
function _ts_decorate22(decorators, target, key, desc) {
|
|
2196
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2197
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
2198
|
+
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;
|
|
2199
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2200
|
+
}
|
|
2201
|
+
__name(_ts_decorate22, "_ts_decorate");
|
|
2202
|
+
var _ModifyBlackboardValue = class _ModifyBlackboardValue {
|
|
2203
|
+
execute(context) {
|
|
2204
|
+
const { runtime } = context;
|
|
2205
|
+
const key = BindingHelper.getValue(context, "key", "");
|
|
2206
|
+
const operation = BindingHelper.getValue(context, "operation", "add");
|
|
2207
|
+
const value = BindingHelper.getValue(context, "value", 0);
|
|
2208
|
+
if (!key) {
|
|
2209
|
+
return TaskStatus.Failure;
|
|
2210
|
+
}
|
|
2211
|
+
const currentValue = runtime.getBlackboardValue(key) || 0;
|
|
2212
|
+
let newValue;
|
|
2213
|
+
switch (operation) {
|
|
2214
|
+
case "add":
|
|
2215
|
+
newValue = currentValue + value;
|
|
2216
|
+
break;
|
|
2217
|
+
case "subtract":
|
|
2218
|
+
newValue = currentValue - value;
|
|
2219
|
+
break;
|
|
2220
|
+
case "multiply":
|
|
2221
|
+
newValue = currentValue * value;
|
|
2222
|
+
break;
|
|
2223
|
+
case "divide":
|
|
2224
|
+
newValue = value !== 0 ? currentValue / value : currentValue;
|
|
2225
|
+
break;
|
|
2226
|
+
case "set":
|
|
2227
|
+
newValue = value;
|
|
2228
|
+
break;
|
|
2229
|
+
default:
|
|
2230
|
+
return TaskStatus.Failure;
|
|
2231
|
+
}
|
|
2232
|
+
runtime.setBlackboardValue(key, newValue);
|
|
2233
|
+
return TaskStatus.Success;
|
|
2234
|
+
}
|
|
2235
|
+
};
|
|
2236
|
+
__name(_ModifyBlackboardValue, "ModifyBlackboardValue");
|
|
2237
|
+
var ModifyBlackboardValue = _ModifyBlackboardValue;
|
|
2238
|
+
ModifyBlackboardValue = _ts_decorate22([
|
|
2239
|
+
NodeExecutorMetadata({
|
|
2240
|
+
implementationType: "ModifyBlackboardValue",
|
|
2241
|
+
nodeType: NodeType.Action,
|
|
2242
|
+
displayName: "\u4FEE\u6539\u9ED1\u677F\u503C",
|
|
2243
|
+
description: "\u5BF9\u9ED1\u677F\u4E2D\u7684\u6570\u503C\u8FDB\u884C\u8FD0\u7B97",
|
|
2244
|
+
category: "Action",
|
|
2245
|
+
configSchema: {
|
|
2246
|
+
key: {
|
|
2247
|
+
type: "string",
|
|
2248
|
+
default: "",
|
|
2249
|
+
description: "\u9ED1\u677F\u53D8\u91CF\u540D"
|
|
2250
|
+
},
|
|
2251
|
+
operation: {
|
|
2252
|
+
type: "string",
|
|
2253
|
+
default: "add",
|
|
2254
|
+
description: "\u8FD0\u7B97\u7C7B\u578B",
|
|
2255
|
+
options: [
|
|
2256
|
+
"add",
|
|
2257
|
+
"subtract",
|
|
2258
|
+
"multiply",
|
|
2259
|
+
"divide",
|
|
2260
|
+
"set"
|
|
2261
|
+
]
|
|
2262
|
+
},
|
|
2263
|
+
value: {
|
|
2264
|
+
type: "number",
|
|
2265
|
+
default: 0,
|
|
2266
|
+
description: "\u64CD\u4F5C\u6570",
|
|
2267
|
+
supportBinding: true
|
|
2268
|
+
}
|
|
2269
|
+
}
|
|
2270
|
+
})
|
|
2271
|
+
], ModifyBlackboardValue);
|
|
2272
|
+
|
|
2273
|
+
// src/execution/Executors/ExecuteAction.ts
|
|
2274
|
+
function _ts_decorate23(decorators, target, key, desc) {
|
|
2275
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2276
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
2277
|
+
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;
|
|
2278
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2279
|
+
}
|
|
2280
|
+
__name(_ts_decorate23, "_ts_decorate");
|
|
2281
|
+
var _ExecuteAction = class _ExecuteAction {
|
|
2282
|
+
execute(context) {
|
|
2283
|
+
const { runtime, entity } = context;
|
|
2284
|
+
const actionName = BindingHelper.getValue(context, "actionName", "");
|
|
2285
|
+
if (!actionName) {
|
|
2286
|
+
return TaskStatus.Failure;
|
|
2287
|
+
}
|
|
2288
|
+
const actionFunction = runtime.getBlackboardValue(`action_${actionName}`);
|
|
2289
|
+
if (!actionFunction || typeof actionFunction !== "function") {
|
|
2290
|
+
return TaskStatus.Failure;
|
|
2291
|
+
}
|
|
2292
|
+
try {
|
|
2293
|
+
return actionFunction(entity);
|
|
2294
|
+
} catch (error) {
|
|
2295
|
+
console.error(`ExecuteAction failed: ${error}`);
|
|
2296
|
+
return TaskStatus.Failure;
|
|
2297
|
+
}
|
|
2298
|
+
}
|
|
2299
|
+
};
|
|
2300
|
+
__name(_ExecuteAction, "ExecuteAction");
|
|
2301
|
+
var ExecuteAction = _ExecuteAction;
|
|
2302
|
+
ExecuteAction = _ts_decorate23([
|
|
2303
|
+
NodeExecutorMetadata({
|
|
2304
|
+
implementationType: "ExecuteAction",
|
|
2305
|
+
nodeType: NodeType.Action,
|
|
2306
|
+
displayName: "\u6267\u884C\u52A8\u4F5C",
|
|
2307
|
+
description: "\u6267\u884C\u81EA\u5B9A\u4E49\u52A8\u4F5C\u903B\u8F91",
|
|
2308
|
+
category: "Action",
|
|
2309
|
+
configSchema: {
|
|
2310
|
+
actionName: {
|
|
2311
|
+
type: "string",
|
|
2312
|
+
default: "",
|
|
2313
|
+
description: "\u52A8\u4F5C\u540D\u79F0\uFF08\u9ED1\u677F\u4E2Daction_\u524D\u7F00\u7684\u51FD\u6570\uFF09"
|
|
2314
|
+
}
|
|
2315
|
+
}
|
|
2316
|
+
})
|
|
2317
|
+
], ExecuteAction);
|
|
2318
|
+
|
|
2319
|
+
// src/execution/Executors/SubTreeExecutor.ts
|
|
2320
|
+
import { Core } from "@esengine/ecs-framework";
|
|
2321
|
+
function _ts_decorate24(decorators, target, key, desc) {
|
|
2322
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2323
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
2324
|
+
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;
|
|
2325
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2326
|
+
}
|
|
2327
|
+
__name(_ts_decorate24, "_ts_decorate");
|
|
2328
|
+
var _SubTreeExecutor = class _SubTreeExecutor {
|
|
2329
|
+
constructor() {
|
|
2330
|
+
__publicField(this, "assetManager", null);
|
|
2331
|
+
}
|
|
2332
|
+
getAssetManager() {
|
|
2333
|
+
if (!this.assetManager) {
|
|
2334
|
+
this.assetManager = Core.services.resolve(BehaviorTreeAssetManager);
|
|
2335
|
+
}
|
|
2336
|
+
return this.assetManager;
|
|
2337
|
+
}
|
|
2338
|
+
execute(context) {
|
|
2339
|
+
const { runtime, state, entity } = context;
|
|
2340
|
+
const treeAssetId = BindingHelper.getValue(context, "treeAssetId", "");
|
|
2341
|
+
const shareBlackboard = BindingHelper.getValue(context, "shareBlackboard", true);
|
|
2342
|
+
if (!treeAssetId) {
|
|
2343
|
+
return TaskStatus.Failure;
|
|
2344
|
+
}
|
|
2345
|
+
const assetManager = this.getAssetManager();
|
|
2346
|
+
const subTreeData = assetManager.getAsset(treeAssetId);
|
|
2347
|
+
if (!subTreeData) {
|
|
2348
|
+
console.warn(`\u672A\u627E\u5230\u5B50\u6811\u8D44\u4EA7: ${treeAssetId}`);
|
|
2349
|
+
return TaskStatus.Failure;
|
|
2350
|
+
}
|
|
2351
|
+
const rootNode = subTreeData.nodes.get(subTreeData.rootNodeId);
|
|
2352
|
+
if (!rootNode) {
|
|
2353
|
+
console.warn(`\u5B50\u6811\u6839\u8282\u70B9\u672A\u627E\u5230: ${subTreeData.rootNodeId}`);
|
|
2354
|
+
return TaskStatus.Failure;
|
|
2355
|
+
}
|
|
2356
|
+
if (!shareBlackboard && state.status !== TaskStatus.Running) {
|
|
2357
|
+
if (subTreeData.blackboardVariables) {
|
|
2358
|
+
for (const [key, value] of subTreeData.blackboardVariables.entries()) {
|
|
2359
|
+
if (!runtime.hasBlackboardKey(key)) {
|
|
2360
|
+
runtime.setBlackboardValue(key, value);
|
|
2361
|
+
}
|
|
2362
|
+
}
|
|
2363
|
+
}
|
|
2364
|
+
}
|
|
2365
|
+
const subTreeContext = {
|
|
2366
|
+
entity,
|
|
2367
|
+
nodeData: rootNode,
|
|
2368
|
+
state: runtime.getNodeState(rootNode.id),
|
|
2369
|
+
runtime,
|
|
2370
|
+
treeData: subTreeData,
|
|
2371
|
+
deltaTime: context.deltaTime,
|
|
2372
|
+
totalTime: context.totalTime,
|
|
2373
|
+
executeChild: /* @__PURE__ */ __name((childId) => {
|
|
2374
|
+
const childData = subTreeData.nodes.get(childId);
|
|
2375
|
+
if (!childData) {
|
|
2376
|
+
console.warn(`\u5B50\u6811\u8282\u70B9\u672A\u627E\u5230: ${childId}`);
|
|
2377
|
+
return TaskStatus.Failure;
|
|
2378
|
+
}
|
|
2379
|
+
const childContext = {
|
|
2380
|
+
entity,
|
|
2381
|
+
nodeData: childData,
|
|
2382
|
+
state: runtime.getNodeState(childId),
|
|
2383
|
+
runtime,
|
|
2384
|
+
treeData: subTreeData,
|
|
2385
|
+
deltaTime: context.deltaTime,
|
|
2386
|
+
totalTime: context.totalTime,
|
|
2387
|
+
executeChild: subTreeContext.executeChild
|
|
2388
|
+
};
|
|
2389
|
+
return this.executeSubTreeNode(childContext);
|
|
2390
|
+
}, "executeChild")
|
|
2391
|
+
};
|
|
2392
|
+
return this.executeSubTreeNode(subTreeContext);
|
|
2393
|
+
}
|
|
2394
|
+
executeSubTreeNode(context) {
|
|
2395
|
+
const { nodeData, runtime } = context;
|
|
2396
|
+
const state = runtime.getNodeState(nodeData.id);
|
|
2397
|
+
if (!nodeData.children || nodeData.children.length === 0) {
|
|
2398
|
+
return TaskStatus.Success;
|
|
2399
|
+
}
|
|
2400
|
+
const childId = nodeData.children[state.currentChildIndex];
|
|
2401
|
+
const childStatus = context.executeChild(childId);
|
|
2402
|
+
if (childStatus === TaskStatus.Running) {
|
|
2403
|
+
return TaskStatus.Running;
|
|
2404
|
+
}
|
|
2405
|
+
if (childStatus === TaskStatus.Failure) {
|
|
2406
|
+
state.currentChildIndex = 0;
|
|
2407
|
+
return TaskStatus.Failure;
|
|
2408
|
+
}
|
|
2409
|
+
state.currentChildIndex++;
|
|
2410
|
+
if (state.currentChildIndex >= nodeData.children.length) {
|
|
2411
|
+
state.currentChildIndex = 0;
|
|
2412
|
+
return TaskStatus.Success;
|
|
2413
|
+
}
|
|
2414
|
+
return TaskStatus.Running;
|
|
2415
|
+
}
|
|
2416
|
+
reset(context) {
|
|
2417
|
+
const treeAssetId = BindingHelper.getValue(context, "treeAssetId", "");
|
|
2418
|
+
if (treeAssetId) {
|
|
2419
|
+
const assetManager = this.getAssetManager();
|
|
2420
|
+
const subTreeData = assetManager.getAsset(treeAssetId);
|
|
2421
|
+
if (subTreeData) {
|
|
2422
|
+
const rootNode = subTreeData.nodes.get(subTreeData.rootNodeId);
|
|
2423
|
+
if (rootNode) {
|
|
2424
|
+
context.runtime.resetNodeState(rootNode.id);
|
|
2425
|
+
if (rootNode.children) {
|
|
2426
|
+
for (const childId of rootNode.children) {
|
|
2427
|
+
context.runtime.resetNodeState(childId);
|
|
2428
|
+
}
|
|
2429
|
+
}
|
|
2430
|
+
}
|
|
2431
|
+
}
|
|
2432
|
+
}
|
|
2433
|
+
}
|
|
2434
|
+
};
|
|
2435
|
+
__name(_SubTreeExecutor, "SubTreeExecutor");
|
|
2436
|
+
var SubTreeExecutor = _SubTreeExecutor;
|
|
2437
|
+
SubTreeExecutor = _ts_decorate24([
|
|
2438
|
+
NodeExecutorMetadata({
|
|
2439
|
+
implementationType: "SubTree",
|
|
2440
|
+
nodeType: NodeType.Action,
|
|
2441
|
+
displayName: "\u5B50\u6811",
|
|
2442
|
+
description: "\u5F15\u7528\u5E76\u6267\u884C\u5176\u4ED6\u884C\u4E3A\u6811",
|
|
2443
|
+
category: "Special",
|
|
2444
|
+
configSchema: {
|
|
2445
|
+
treeAssetId: {
|
|
2446
|
+
type: "string",
|
|
2447
|
+
default: "",
|
|
2448
|
+
description: "\u8981\u6267\u884C\u7684\u884C\u4E3A\u6811\u8D44\u4EA7ID",
|
|
2449
|
+
supportBinding: true
|
|
2450
|
+
},
|
|
2451
|
+
shareBlackboard: {
|
|
2452
|
+
type: "boolean",
|
|
2453
|
+
default: true,
|
|
2454
|
+
description: "\u662F\u5426\u5171\u4EAB\u9ED1\u677F\u6570\u636E"
|
|
2455
|
+
}
|
|
2456
|
+
}
|
|
2457
|
+
})
|
|
2458
|
+
], SubTreeExecutor);
|
|
2459
|
+
|
|
2460
|
+
// src/execution/Executors/BlackboardCompare.ts
|
|
2461
|
+
function _ts_decorate25(decorators, target, key, desc) {
|
|
2462
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2463
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
2464
|
+
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;
|
|
2465
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2466
|
+
}
|
|
2467
|
+
__name(_ts_decorate25, "_ts_decorate");
|
|
2468
|
+
var _BlackboardCompare = class _BlackboardCompare {
|
|
2469
|
+
execute(context) {
|
|
2470
|
+
const { runtime } = context;
|
|
2471
|
+
const key = BindingHelper.getValue(context, "key", "");
|
|
2472
|
+
const compareValue = BindingHelper.getValue(context, "compareValue");
|
|
2473
|
+
const operator = BindingHelper.getValue(context, "operator", "equals");
|
|
2474
|
+
if (!key) {
|
|
2475
|
+
return TaskStatus.Failure;
|
|
2476
|
+
}
|
|
2477
|
+
const actualValue = runtime.getBlackboardValue(key);
|
|
2478
|
+
if (this.compare(actualValue, compareValue, operator)) {
|
|
2479
|
+
return TaskStatus.Success;
|
|
2480
|
+
}
|
|
2481
|
+
return TaskStatus.Failure;
|
|
2482
|
+
}
|
|
2483
|
+
compare(actualValue, compareValue, operator) {
|
|
2484
|
+
switch (operator) {
|
|
2485
|
+
case "equals":
|
|
2486
|
+
return actualValue === compareValue;
|
|
2487
|
+
case "notEquals":
|
|
2488
|
+
return actualValue !== compareValue;
|
|
2489
|
+
case "greaterThan":
|
|
2490
|
+
return actualValue > compareValue;
|
|
2491
|
+
case "lessThan":
|
|
2492
|
+
return actualValue < compareValue;
|
|
2493
|
+
case "greaterOrEqual":
|
|
2494
|
+
return actualValue >= compareValue;
|
|
2495
|
+
case "lessOrEqual":
|
|
2496
|
+
return actualValue <= compareValue;
|
|
2497
|
+
default:
|
|
2498
|
+
return false;
|
|
2499
|
+
}
|
|
2500
|
+
}
|
|
2501
|
+
};
|
|
2502
|
+
__name(_BlackboardCompare, "BlackboardCompare");
|
|
2503
|
+
var BlackboardCompare = _BlackboardCompare;
|
|
2504
|
+
BlackboardCompare = _ts_decorate25([
|
|
2505
|
+
NodeExecutorMetadata({
|
|
2506
|
+
implementationType: "BlackboardCompare",
|
|
2507
|
+
nodeType: NodeType.Condition,
|
|
2508
|
+
displayName: "\u9ED1\u677F\u6BD4\u8F83",
|
|
2509
|
+
description: "\u6BD4\u8F83\u9ED1\u677F\u4E2D\u7684\u503C",
|
|
2510
|
+
category: "Condition",
|
|
2511
|
+
configSchema: {
|
|
2512
|
+
key: {
|
|
2513
|
+
type: "string",
|
|
2514
|
+
default: "",
|
|
2515
|
+
description: "\u9ED1\u677F\u53D8\u91CF\u540D"
|
|
2516
|
+
},
|
|
2517
|
+
compareValue: {
|
|
2518
|
+
type: "object",
|
|
2519
|
+
description: "\u6BD4\u8F83\u503C",
|
|
2520
|
+
supportBinding: true
|
|
2521
|
+
},
|
|
2522
|
+
operator: {
|
|
2523
|
+
type: "string",
|
|
2524
|
+
default: "equals",
|
|
2525
|
+
description: "\u6BD4\u8F83\u8FD0\u7B97\u7B26",
|
|
2526
|
+
options: [
|
|
2527
|
+
"equals",
|
|
2528
|
+
"notEquals",
|
|
2529
|
+
"greaterThan",
|
|
2530
|
+
"lessThan",
|
|
2531
|
+
"greaterOrEqual",
|
|
2532
|
+
"lessOrEqual"
|
|
2533
|
+
]
|
|
2534
|
+
}
|
|
2535
|
+
}
|
|
2536
|
+
})
|
|
2537
|
+
], BlackboardCompare);
|
|
2538
|
+
|
|
2539
|
+
// src/execution/Executors/BlackboardExists.ts
|
|
2540
|
+
function _ts_decorate26(decorators, target, key, desc) {
|
|
2541
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2542
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
2543
|
+
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;
|
|
2544
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2545
|
+
}
|
|
2546
|
+
__name(_ts_decorate26, "_ts_decorate");
|
|
2547
|
+
var _BlackboardExists = class _BlackboardExists {
|
|
2548
|
+
execute(context) {
|
|
2549
|
+
const { runtime } = context;
|
|
2550
|
+
const key = BindingHelper.getValue(context, "key", "");
|
|
2551
|
+
const checkNull = BindingHelper.getValue(context, "checkNull", false);
|
|
2552
|
+
if (!key) {
|
|
2553
|
+
return TaskStatus.Failure;
|
|
2554
|
+
}
|
|
2555
|
+
const value = runtime.getBlackboardValue(key);
|
|
2556
|
+
if (value === void 0) {
|
|
2557
|
+
return TaskStatus.Failure;
|
|
2558
|
+
}
|
|
2559
|
+
if (checkNull && value === null) {
|
|
2560
|
+
return TaskStatus.Failure;
|
|
2561
|
+
}
|
|
2562
|
+
return TaskStatus.Success;
|
|
2563
|
+
}
|
|
2564
|
+
};
|
|
2565
|
+
__name(_BlackboardExists, "BlackboardExists");
|
|
2566
|
+
var BlackboardExists = _BlackboardExists;
|
|
2567
|
+
BlackboardExists = _ts_decorate26([
|
|
2568
|
+
NodeExecutorMetadata({
|
|
2569
|
+
implementationType: "BlackboardExists",
|
|
2570
|
+
nodeType: NodeType.Condition,
|
|
2571
|
+
displayName: "\u9ED1\u677F\u5B58\u5728",
|
|
2572
|
+
description: "\u68C0\u67E5\u9ED1\u677F\u4E2D\u662F\u5426\u5B58\u5728\u6307\u5B9A\u7684\u952E",
|
|
2573
|
+
category: "Condition",
|
|
2574
|
+
configSchema: {
|
|
2575
|
+
key: {
|
|
2576
|
+
type: "string",
|
|
2577
|
+
default: "",
|
|
2578
|
+
description: "\u9ED1\u677F\u53D8\u91CF\u540D"
|
|
2579
|
+
},
|
|
2580
|
+
checkNull: {
|
|
2581
|
+
type: "boolean",
|
|
2582
|
+
default: false,
|
|
2583
|
+
description: "\u68C0\u67E5\u662F\u5426\u4E3Anull"
|
|
2584
|
+
}
|
|
2585
|
+
}
|
|
2586
|
+
})
|
|
2587
|
+
], BlackboardExists);
|
|
2588
|
+
|
|
2589
|
+
// src/execution/Executors/RandomProbability.ts
|
|
2590
|
+
function _ts_decorate27(decorators, target, key, desc) {
|
|
2591
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2592
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
2593
|
+
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;
|
|
2594
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2595
|
+
}
|
|
2596
|
+
__name(_ts_decorate27, "_ts_decorate");
|
|
2597
|
+
var _RandomProbability = class _RandomProbability {
|
|
2598
|
+
execute(context) {
|
|
2599
|
+
const probability = BindingHelper.getValue(context, "probability", 0.5);
|
|
2600
|
+
const clampedProbability = Math.max(0, Math.min(1, probability));
|
|
2601
|
+
if (Math.random() < clampedProbability) {
|
|
2602
|
+
return TaskStatus.Success;
|
|
2603
|
+
}
|
|
2604
|
+
return TaskStatus.Failure;
|
|
2605
|
+
}
|
|
2606
|
+
};
|
|
2607
|
+
__name(_RandomProbability, "RandomProbability");
|
|
2608
|
+
var RandomProbability = _RandomProbability;
|
|
2609
|
+
RandomProbability = _ts_decorate27([
|
|
2610
|
+
NodeExecutorMetadata({
|
|
2611
|
+
implementationType: "RandomProbability",
|
|
2612
|
+
nodeType: NodeType.Condition,
|
|
2613
|
+
displayName: "\u968F\u673A\u6982\u7387",
|
|
2614
|
+
description: "\u6839\u636E\u6982\u7387\u8FD4\u56DE\u6210\u529F\u6216\u5931\u8D25",
|
|
2615
|
+
category: "Condition",
|
|
2616
|
+
configSchema: {
|
|
2617
|
+
probability: {
|
|
2618
|
+
type: "number",
|
|
2619
|
+
default: 0.5,
|
|
2620
|
+
description: "\u6210\u529F\u6982\u7387\uFF080-1\uFF09",
|
|
2621
|
+
min: 0,
|
|
2622
|
+
max: 1,
|
|
2623
|
+
supportBinding: true
|
|
2624
|
+
}
|
|
2625
|
+
}
|
|
2626
|
+
})
|
|
2627
|
+
], RandomProbability);
|
|
2628
|
+
|
|
2629
|
+
// src/execution/Executors/ExecuteCondition.ts
|
|
2630
|
+
function _ts_decorate28(decorators, target, key, desc) {
|
|
2631
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2632
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
2633
|
+
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;
|
|
2634
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2635
|
+
}
|
|
2636
|
+
__name(_ts_decorate28, "_ts_decorate");
|
|
2637
|
+
var _ExecuteCondition = class _ExecuteCondition {
|
|
2638
|
+
execute(context) {
|
|
2639
|
+
const { runtime, entity } = context;
|
|
2640
|
+
const conditionName = BindingHelper.getValue(context, "conditionName", "");
|
|
2641
|
+
if (!conditionName) {
|
|
2642
|
+
return TaskStatus.Failure;
|
|
2643
|
+
}
|
|
2644
|
+
const conditionFunction = runtime.getBlackboardValue(`condition_${conditionName}`);
|
|
2645
|
+
if (!conditionFunction || typeof conditionFunction !== "function") {
|
|
2646
|
+
return TaskStatus.Failure;
|
|
2647
|
+
}
|
|
2648
|
+
try {
|
|
2649
|
+
return conditionFunction(entity) ? TaskStatus.Success : TaskStatus.Failure;
|
|
2650
|
+
} catch (error) {
|
|
2651
|
+
console.error(`ExecuteCondition failed: ${error}`);
|
|
2652
|
+
return TaskStatus.Failure;
|
|
2653
|
+
}
|
|
2654
|
+
}
|
|
2655
|
+
};
|
|
2656
|
+
__name(_ExecuteCondition, "ExecuteCondition");
|
|
2657
|
+
var ExecuteCondition = _ExecuteCondition;
|
|
2658
|
+
ExecuteCondition = _ts_decorate28([
|
|
2659
|
+
NodeExecutorMetadata({
|
|
2660
|
+
implementationType: "ExecuteCondition",
|
|
2661
|
+
nodeType: NodeType.Condition,
|
|
2662
|
+
displayName: "\u6267\u884C\u6761\u4EF6",
|
|
2663
|
+
description: "\u6267\u884C\u81EA\u5B9A\u4E49\u6761\u4EF6\u903B\u8F91",
|
|
2664
|
+
category: "Condition",
|
|
2665
|
+
configSchema: {
|
|
2666
|
+
conditionName: {
|
|
2667
|
+
type: "string",
|
|
2668
|
+
default: "",
|
|
2669
|
+
description: "\u6761\u4EF6\u540D\u79F0\uFF08\u9ED1\u677F\u4E2Dcondition_\u524D\u7F00\u7684\u51FD\u6570\uFF09"
|
|
2670
|
+
}
|
|
2671
|
+
}
|
|
2672
|
+
})
|
|
2673
|
+
], ExecuteCondition);
|
|
2674
|
+
|
|
2675
|
+
// src/execution/BehaviorTreeExecutionSystem.ts
|
|
2676
|
+
function _ts_decorate29(decorators, target, key, desc) {
|
|
2677
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2678
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
2679
|
+
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;
|
|
2680
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2681
|
+
}
|
|
2682
|
+
__name(_ts_decorate29, "_ts_decorate");
|
|
2683
|
+
function _ts_metadata2(k, v) {
|
|
2684
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
2685
|
+
}
|
|
2686
|
+
__name(_ts_metadata2, "_ts_metadata");
|
|
2687
|
+
var _BehaviorTreeExecutionSystem = class _BehaviorTreeExecutionSystem extends EntitySystem {
|
|
2688
|
+
constructor(services) {
|
|
2689
|
+
super(Matcher.empty().all(BehaviorTreeRuntimeComponent));
|
|
2690
|
+
__publicField(this, "btAssetManager", null);
|
|
2691
|
+
__publicField(this, "executorRegistry");
|
|
2692
|
+
__publicField(this, "_services", null);
|
|
2693
|
+
/** 引用外部资产管理器(可选,由外部模块设置) */
|
|
2694
|
+
__publicField(this, "_assetManager", null);
|
|
2695
|
+
/** 已警告过的缺失资产,避免重复警告 */
|
|
2696
|
+
__publicField(this, "_warnedMissingAssets", /* @__PURE__ */ new Set());
|
|
2697
|
+
this._services = services || null;
|
|
2698
|
+
this.executorRegistry = new NodeExecutorRegistry();
|
|
2699
|
+
this.registerBuiltInExecutors();
|
|
2700
|
+
}
|
|
2701
|
+
/**
|
|
2702
|
+
* @zh 设置外部资产管理器引用(可选)
|
|
2703
|
+
* @en Set external asset manager reference (optional)
|
|
2704
|
+
*
|
|
2705
|
+
* @zh 当与 ESEngine 集成时,由 BehaviorTreeRuntimeModule 调用。
|
|
2706
|
+
* 不使用 ESEngine 时,可以不调用此方法,
|
|
2707
|
+
* 直接使用 BehaviorTreeAssetManager.loadFromEditorJSON() 加载资产。
|
|
2708
|
+
*
|
|
2709
|
+
* @en Called by BehaviorTreeRuntimeModule when integrating with ESEngine.
|
|
2710
|
+
* When not using ESEngine, you can skip this and use
|
|
2711
|
+
* BehaviorTreeAssetManager.loadFromEditorJSON() to load assets directly.
|
|
2712
|
+
*/
|
|
2713
|
+
setAssetManager(assetManager) {
|
|
2714
|
+
this._assetManager = assetManager;
|
|
2715
|
+
}
|
|
2716
|
+
/**
|
|
2717
|
+
* 启动所有 autoStart 的行为树(用于预览模式)
|
|
2718
|
+
* Start all autoStart behavior trees (for preview mode)
|
|
2719
|
+
*
|
|
2720
|
+
* 由于编辑器模式下系统默认禁用,实体添加时 onAdded 不会处理自动启动。
|
|
2721
|
+
* 预览开始时需要手动调用此方法来启动所有需要自动启动的行为树。
|
|
2722
|
+
*/
|
|
2723
|
+
startAllAutoStartTrees() {
|
|
2724
|
+
if (!this.scene) {
|
|
2725
|
+
this.logger.warn("Scene not available, cannot start auto-start trees");
|
|
2726
|
+
return;
|
|
2727
|
+
}
|
|
2728
|
+
const entities = this.scene.entities.findEntitiesWithComponent(BehaviorTreeRuntimeComponent);
|
|
2729
|
+
for (const entity of entities) {
|
|
2730
|
+
const runtime = entity.getComponent(BehaviorTreeRuntimeComponent);
|
|
2731
|
+
if (runtime && runtime.autoStart && runtime.treeAssetId && !runtime.isRunning) {
|
|
2732
|
+
this.ensureAssetLoaded(runtime.treeAssetId).then(() => {
|
|
2733
|
+
if (runtime && runtime.autoStart && !runtime.isRunning) {
|
|
2734
|
+
runtime.start();
|
|
2735
|
+
this.logger.debug(`Auto-started behavior tree for entity: ${entity.name}`);
|
|
2736
|
+
}
|
|
2737
|
+
}).catch((e) => {
|
|
2738
|
+
this.logger.error(`Failed to load behavior tree for entity ${entity.name}:`, e);
|
|
2739
|
+
});
|
|
2740
|
+
}
|
|
2741
|
+
}
|
|
2742
|
+
}
|
|
2743
|
+
/**
|
|
2744
|
+
* 当实体添加到系统时,处理自动启动
|
|
2745
|
+
* Handle auto-start when entity is added to system
|
|
2746
|
+
*/
|
|
2747
|
+
onAdded(entity) {
|
|
2748
|
+
if (!this.enabled) return;
|
|
2749
|
+
const runtime = entity.getComponent(BehaviorTreeRuntimeComponent);
|
|
2750
|
+
if (runtime && runtime.autoStart && runtime.treeAssetId && !runtime.isRunning) {
|
|
2751
|
+
this.ensureAssetLoaded(runtime.treeAssetId).then(() => {
|
|
2752
|
+
if (runtime && runtime.autoStart && !runtime.isRunning) {
|
|
2753
|
+
runtime.start();
|
|
2754
|
+
this.logger.debug(`Auto-started behavior tree for entity: ${entity.name}`);
|
|
2755
|
+
}
|
|
2756
|
+
}).catch((e) => {
|
|
2757
|
+
this.logger.error(`Failed to load behavior tree for entity ${entity.name}:`, e);
|
|
2758
|
+
});
|
|
2759
|
+
}
|
|
2760
|
+
}
|
|
2761
|
+
/**
|
|
2762
|
+
* 确保行为树资产已加载
|
|
2763
|
+
* Ensure behavior tree asset is loaded
|
|
2764
|
+
*/
|
|
2765
|
+
async ensureAssetLoaded(assetGuid) {
|
|
2766
|
+
const btAssetManager = this.getBTAssetManager();
|
|
2767
|
+
if (btAssetManager.hasAsset(assetGuid)) {
|
|
2768
|
+
return;
|
|
2769
|
+
}
|
|
2770
|
+
if (!this._assetManager) {
|
|
2771
|
+
this.logger.warn(`AssetManager not set, cannot load: ${assetGuid}`);
|
|
2772
|
+
return;
|
|
2773
|
+
}
|
|
2774
|
+
try {
|
|
2775
|
+
const result = await this._assetManager.loadAsset(assetGuid);
|
|
2776
|
+
if (result && result.asset) {
|
|
2777
|
+
this.logger.debug(`Behavior tree loaded via AssetManager: ${assetGuid}`);
|
|
2778
|
+
}
|
|
2779
|
+
} catch (e) {
|
|
2780
|
+
this.logger.warn(`Failed to load via AssetManager: ${assetGuid}`, e);
|
|
2781
|
+
}
|
|
2782
|
+
}
|
|
2783
|
+
getBTAssetManager() {
|
|
2784
|
+
if (!this.btAssetManager) {
|
|
2785
|
+
const services = this._services || Core2.services;
|
|
2786
|
+
if (!services) {
|
|
2787
|
+
throw new Error("ServiceContainer is not available. Ensure Core.create() was called.");
|
|
2788
|
+
}
|
|
2789
|
+
this.btAssetManager = services.resolve(BehaviorTreeAssetManager);
|
|
2790
|
+
}
|
|
2791
|
+
return this.btAssetManager;
|
|
2792
|
+
}
|
|
2793
|
+
/**
|
|
2794
|
+
* 获取行为树数据
|
|
2795
|
+
* Get behavior tree data from AssetManager or BehaviorTreeAssetManager
|
|
2796
|
+
*
|
|
2797
|
+
* 优先从 AssetManager 获取(新方式),如果没有再从 BehaviorTreeAssetManager 获取(兼容旧方式)
|
|
2798
|
+
*/
|
|
2799
|
+
getTreeData(assetGuid) {
|
|
2800
|
+
if (this._assetManager) {
|
|
2801
|
+
const cachedAsset = this._assetManager.getAsset(assetGuid);
|
|
2802
|
+
if (cachedAsset?.data) {
|
|
2803
|
+
return cachedAsset.data;
|
|
2804
|
+
}
|
|
2805
|
+
}
|
|
2806
|
+
return this.getBTAssetManager().getAsset(assetGuid);
|
|
2807
|
+
}
|
|
2808
|
+
/**
|
|
2809
|
+
* 注册所有执行器(包括内置和插件提供的)
|
|
2810
|
+
*/
|
|
2811
|
+
registerBuiltInExecutors() {
|
|
2812
|
+
const constructors = NodeMetadataRegistry.getAllExecutorConstructors();
|
|
2813
|
+
for (const [implementationType, ExecutorClass] of constructors) {
|
|
2814
|
+
try {
|
|
2815
|
+
const instance = new ExecutorClass();
|
|
2816
|
+
this.executorRegistry.register(implementationType, instance);
|
|
2817
|
+
} catch (error) {
|
|
2818
|
+
this.logger.error(`\u6CE8\u518C\u6267\u884C\u5668\u5931\u8D25: ${implementationType}`, error);
|
|
2819
|
+
}
|
|
2820
|
+
}
|
|
2821
|
+
}
|
|
2822
|
+
/**
|
|
2823
|
+
* 获取执行器注册表
|
|
2824
|
+
*/
|
|
2825
|
+
getExecutorRegistry() {
|
|
2826
|
+
return this.executorRegistry;
|
|
2827
|
+
}
|
|
2828
|
+
process(entities) {
|
|
2829
|
+
for (const entity of entities) {
|
|
2830
|
+
const runtime = entity.getComponent(BehaviorTreeRuntimeComponent);
|
|
2831
|
+
if (!runtime.isRunning) {
|
|
2832
|
+
continue;
|
|
2833
|
+
}
|
|
2834
|
+
const treeData = this.getTreeData(runtime.treeAssetId);
|
|
2835
|
+
if (!treeData) {
|
|
2836
|
+
if (!this._warnedMissingAssets.has(runtime.treeAssetId)) {
|
|
2837
|
+
this._warnedMissingAssets.add(runtime.treeAssetId);
|
|
2838
|
+
this.logger.warn(`\u672A\u627E\u5230\u884C\u4E3A\u6811\u8D44\u4EA7: ${runtime.treeAssetId}`);
|
|
2839
|
+
}
|
|
2840
|
+
continue;
|
|
2841
|
+
}
|
|
2842
|
+
if (runtime.needsReset) {
|
|
2843
|
+
runtime.resetAllStates();
|
|
2844
|
+
runtime.needsReset = false;
|
|
2845
|
+
}
|
|
2846
|
+
if (treeData.blackboardVariables && treeData.blackboardVariables.size > 0) {
|
|
2847
|
+
runtime.initializeBlackboard(treeData.blackboardVariables);
|
|
2848
|
+
}
|
|
2849
|
+
this.executeTree(entity, runtime, treeData);
|
|
2850
|
+
}
|
|
2851
|
+
}
|
|
2852
|
+
/**
|
|
2853
|
+
* 执行整个行为树
|
|
2854
|
+
*/
|
|
2855
|
+
executeTree(entity, runtime, treeData) {
|
|
2856
|
+
const rootNode = treeData.nodes.get(treeData.rootNodeId);
|
|
2857
|
+
if (!rootNode) {
|
|
2858
|
+
this.logger.error(`\u672A\u627E\u5230\u6839\u8282\u70B9: ${treeData.rootNodeId}`);
|
|
2859
|
+
return;
|
|
2860
|
+
}
|
|
2861
|
+
const status = this.executeNode(entity, runtime, rootNode, treeData);
|
|
2862
|
+
if (status !== TaskStatus.Running) {
|
|
2863
|
+
runtime.needsReset = true;
|
|
2864
|
+
} else {
|
|
2865
|
+
runtime.needsReset = false;
|
|
2866
|
+
}
|
|
2867
|
+
}
|
|
2868
|
+
/**
|
|
2869
|
+
* 执行单个节点
|
|
2870
|
+
*/
|
|
2871
|
+
executeNode(entity, runtime, nodeData, treeData) {
|
|
2872
|
+
const state = runtime.getNodeState(nodeData.id);
|
|
2873
|
+
if (runtime.shouldAbort(nodeData.id)) {
|
|
2874
|
+
runtime.clearAbortRequest(nodeData.id);
|
|
2875
|
+
state.isAborted = true;
|
|
2876
|
+
const executor2 = this.executorRegistry.get(nodeData.implementationType);
|
|
2877
|
+
if (executor2 && executor2.reset) {
|
|
2878
|
+
const context2 = this.createContext(entity, runtime, nodeData, treeData);
|
|
2879
|
+
executor2.reset(context2);
|
|
2880
|
+
}
|
|
2881
|
+
runtime.activeNodeIds.delete(nodeData.id);
|
|
2882
|
+
state.status = TaskStatus.Failure;
|
|
2883
|
+
return TaskStatus.Failure;
|
|
2884
|
+
}
|
|
2885
|
+
runtime.activeNodeIds.add(nodeData.id);
|
|
2886
|
+
state.isAborted = false;
|
|
2887
|
+
if (state.executionOrder === void 0) {
|
|
2888
|
+
runtime.executionOrderCounter++;
|
|
2889
|
+
state.executionOrder = runtime.executionOrderCounter;
|
|
2890
|
+
}
|
|
2891
|
+
const executor = this.executorRegistry.get(nodeData.implementationType);
|
|
2892
|
+
if (!executor) {
|
|
2893
|
+
this.logger.error(`\u672A\u627E\u5230\u6267\u884C\u5668: ${nodeData.implementationType}`);
|
|
2894
|
+
state.status = TaskStatus.Failure;
|
|
2895
|
+
return TaskStatus.Failure;
|
|
2896
|
+
}
|
|
2897
|
+
const context = this.createContext(entity, runtime, nodeData, treeData);
|
|
2898
|
+
try {
|
|
2899
|
+
const status = executor.execute(context);
|
|
2900
|
+
state.status = status;
|
|
2901
|
+
if (status !== TaskStatus.Running) {
|
|
2902
|
+
runtime.activeNodeIds.delete(nodeData.id);
|
|
2903
|
+
if (executor.reset) {
|
|
2904
|
+
executor.reset(context);
|
|
2905
|
+
}
|
|
2906
|
+
}
|
|
2907
|
+
return status;
|
|
2908
|
+
} catch (error) {
|
|
2909
|
+
this.logger.error(`\u6267\u884C\u8282\u70B9\u65F6\u53D1\u751F\u9519\u8BEF: ${nodeData.name}`, error);
|
|
2910
|
+
state.status = TaskStatus.Failure;
|
|
2911
|
+
runtime.activeNodeIds.delete(nodeData.id);
|
|
2912
|
+
return TaskStatus.Failure;
|
|
2913
|
+
}
|
|
2914
|
+
}
|
|
2915
|
+
/**
|
|
2916
|
+
* 创建执行上下文
|
|
2917
|
+
*/
|
|
2918
|
+
createContext(entity, runtime, nodeData, treeData) {
|
|
2919
|
+
return {
|
|
2920
|
+
entity,
|
|
2921
|
+
nodeData,
|
|
2922
|
+
state: runtime.getNodeState(nodeData.id),
|
|
2923
|
+
runtime,
|
|
2924
|
+
treeData,
|
|
2925
|
+
deltaTime: Time.deltaTime,
|
|
2926
|
+
totalTime: Time.totalTime,
|
|
2927
|
+
executeChild: /* @__PURE__ */ __name((childId) => {
|
|
2928
|
+
const childData = treeData.nodes.get(childId);
|
|
2929
|
+
if (!childData) {
|
|
2930
|
+
this.logger.warn(`\u672A\u627E\u5230\u5B50\u8282\u70B9: ${childId}`);
|
|
2931
|
+
return TaskStatus.Failure;
|
|
2932
|
+
}
|
|
2933
|
+
return this.executeNode(entity, runtime, childData, treeData);
|
|
2934
|
+
}, "executeChild")
|
|
2935
|
+
};
|
|
2936
|
+
}
|
|
2937
|
+
/**
|
|
2938
|
+
* 执行子节点列表
|
|
2939
|
+
*/
|
|
2940
|
+
executeChildren(context, childIndices) {
|
|
2941
|
+
const { nodeData, treeData, entity, runtime } = context;
|
|
2942
|
+
if (!nodeData.children || nodeData.children.length === 0) {
|
|
2943
|
+
return [];
|
|
2944
|
+
}
|
|
2945
|
+
const results = [];
|
|
2946
|
+
const indicesToExecute = childIndices || Array.from({
|
|
2947
|
+
length: nodeData.children.length
|
|
2948
|
+
}, (_, i) => i);
|
|
2949
|
+
for (const index of indicesToExecute) {
|
|
2950
|
+
if (index >= nodeData.children.length) {
|
|
2951
|
+
continue;
|
|
2952
|
+
}
|
|
2953
|
+
const childId = nodeData.children[index];
|
|
2954
|
+
const childData = treeData.nodes.get(childId);
|
|
2955
|
+
if (!childData) {
|
|
2956
|
+
this.logger.warn(`\u672A\u627E\u5230\u5B50\u8282\u70B9: ${childId}`);
|
|
2957
|
+
results.push(TaskStatus.Failure);
|
|
2958
|
+
continue;
|
|
2959
|
+
}
|
|
2960
|
+
const status = this.executeNode(entity, runtime, childData, treeData);
|
|
2961
|
+
results.push(status);
|
|
2962
|
+
}
|
|
2963
|
+
return results;
|
|
2964
|
+
}
|
|
2965
|
+
};
|
|
2966
|
+
__name(_BehaviorTreeExecutionSystem, "BehaviorTreeExecutionSystem");
|
|
2967
|
+
var BehaviorTreeExecutionSystem = _BehaviorTreeExecutionSystem;
|
|
2968
|
+
BehaviorTreeExecutionSystem = _ts_decorate29([
|
|
2969
|
+
ECSSystem("BehaviorTreeExecution"),
|
|
2970
|
+
_ts_metadata2("design:type", Function),
|
|
2971
|
+
_ts_metadata2("design:paramtypes", [
|
|
2972
|
+
typeof ServiceContainer === "undefined" ? Object : ServiceContainer
|
|
2973
|
+
])
|
|
2974
|
+
], BehaviorTreeExecutionSystem);
|
|
2975
|
+
|
|
2976
|
+
// src/BehaviorTreeStarter.ts
|
|
2977
|
+
import { Core as Core3 } from "@esengine/ecs-framework";
|
|
2978
|
+
var _BehaviorTreeStarter = class _BehaviorTreeStarter {
|
|
2979
|
+
/**
|
|
2980
|
+
* 启动行为树
|
|
2981
|
+
*
|
|
2982
|
+
* @param entity 游戏实体
|
|
2983
|
+
* @param treeData 行为树数据
|
|
2984
|
+
* @param autoStart 是否自动开始执行
|
|
2985
|
+
*/
|
|
2986
|
+
static start(entity, treeData, autoStart = true) {
|
|
2987
|
+
const assetManager = Core3.services.resolve(BehaviorTreeAssetManager);
|
|
2988
|
+
assetManager.loadAsset(treeData);
|
|
2989
|
+
let runtime = entity.getComponent(BehaviorTreeRuntimeComponent);
|
|
2990
|
+
if (!runtime) {
|
|
2991
|
+
runtime = new BehaviorTreeRuntimeComponent();
|
|
2992
|
+
entity.addComponent(runtime);
|
|
2993
|
+
}
|
|
2994
|
+
runtime.treeAssetId = treeData.id;
|
|
2995
|
+
runtime.autoStart = autoStart;
|
|
2996
|
+
if (treeData.blackboardVariables) {
|
|
2997
|
+
for (const [key, value] of treeData.blackboardVariables.entries()) {
|
|
2998
|
+
runtime.setBlackboardValue(key, value);
|
|
2999
|
+
}
|
|
3000
|
+
}
|
|
3001
|
+
if (autoStart) {
|
|
3002
|
+
runtime.isRunning = true;
|
|
3003
|
+
}
|
|
3004
|
+
}
|
|
3005
|
+
/**
|
|
3006
|
+
* 停止行为树
|
|
3007
|
+
*
|
|
3008
|
+
* @param entity 游戏实体
|
|
3009
|
+
*/
|
|
3010
|
+
static stop(entity) {
|
|
3011
|
+
const runtime = entity.getComponent(BehaviorTreeRuntimeComponent);
|
|
3012
|
+
if (runtime) {
|
|
3013
|
+
runtime.isRunning = false;
|
|
3014
|
+
runtime.resetAllStates();
|
|
3015
|
+
}
|
|
3016
|
+
}
|
|
3017
|
+
/**
|
|
3018
|
+
* 暂停行为树
|
|
3019
|
+
*
|
|
3020
|
+
* @param entity 游戏实体
|
|
3021
|
+
*/
|
|
3022
|
+
static pause(entity) {
|
|
3023
|
+
const runtime = entity.getComponent(BehaviorTreeRuntimeComponent);
|
|
3024
|
+
if (runtime) {
|
|
3025
|
+
runtime.isRunning = false;
|
|
3026
|
+
}
|
|
3027
|
+
}
|
|
3028
|
+
/**
|
|
3029
|
+
* 恢复行为树
|
|
3030
|
+
*
|
|
3031
|
+
* @param entity 游戏实体
|
|
3032
|
+
*/
|
|
3033
|
+
static resume(entity) {
|
|
3034
|
+
const runtime = entity.getComponent(BehaviorTreeRuntimeComponent);
|
|
3035
|
+
if (runtime) {
|
|
3036
|
+
runtime.isRunning = true;
|
|
3037
|
+
}
|
|
3038
|
+
}
|
|
3039
|
+
/**
|
|
3040
|
+
* 重启行为树
|
|
3041
|
+
*
|
|
3042
|
+
* @param entity 游戏实体
|
|
3043
|
+
*/
|
|
3044
|
+
static restart(entity) {
|
|
3045
|
+
const runtime = entity.getComponent(BehaviorTreeRuntimeComponent);
|
|
3046
|
+
if (runtime) {
|
|
3047
|
+
runtime.resetAllStates();
|
|
3048
|
+
runtime.isRunning = true;
|
|
3049
|
+
}
|
|
3050
|
+
}
|
|
3051
|
+
};
|
|
3052
|
+
__name(_BehaviorTreeStarter, "BehaviorTreeStarter");
|
|
3053
|
+
var BehaviorTreeStarter = _BehaviorTreeStarter;
|
|
3054
|
+
|
|
3055
|
+
// src/BehaviorTreeBuilder.ts
|
|
3056
|
+
var _BehaviorTreeBuilder = class _BehaviorTreeBuilder {
|
|
3057
|
+
constructor(treeName) {
|
|
3058
|
+
__publicField(this, "treeData");
|
|
3059
|
+
__publicField(this, "nodeStack", []);
|
|
3060
|
+
__publicField(this, "nodeIdCounter", 0);
|
|
3061
|
+
this.treeData = {
|
|
3062
|
+
id: `tree_${Date.now()}`,
|
|
3063
|
+
name: treeName,
|
|
3064
|
+
rootNodeId: "",
|
|
3065
|
+
nodes: /* @__PURE__ */ new Map(),
|
|
3066
|
+
blackboardVariables: /* @__PURE__ */ new Map()
|
|
3067
|
+
};
|
|
3068
|
+
}
|
|
3069
|
+
/**
|
|
3070
|
+
* 创建构建器
|
|
3071
|
+
*/
|
|
3072
|
+
static create(treeName = "BehaviorTree") {
|
|
3073
|
+
return new _BehaviorTreeBuilder(treeName);
|
|
3074
|
+
}
|
|
3075
|
+
/**
|
|
3076
|
+
* 定义黑板变量
|
|
3077
|
+
*/
|
|
3078
|
+
defineBlackboardVariable(key, initialValue) {
|
|
3079
|
+
if (!this.treeData.blackboardVariables) {
|
|
3080
|
+
this.treeData.blackboardVariables = /* @__PURE__ */ new Map();
|
|
3081
|
+
}
|
|
3082
|
+
this.treeData.blackboardVariables.set(key, initialValue);
|
|
3083
|
+
return this;
|
|
3084
|
+
}
|
|
3085
|
+
/**
|
|
3086
|
+
* 添加序列节点
|
|
3087
|
+
*/
|
|
3088
|
+
sequence(name) {
|
|
3089
|
+
return this.addCompositeNode("Sequence", name || "Sequence");
|
|
3090
|
+
}
|
|
3091
|
+
/**
|
|
3092
|
+
* 添加选择器节点
|
|
3093
|
+
*/
|
|
3094
|
+
selector(name) {
|
|
3095
|
+
return this.addCompositeNode("Selector", name || "Selector");
|
|
3096
|
+
}
|
|
3097
|
+
/**
|
|
3098
|
+
* 添加并行节点
|
|
3099
|
+
*/
|
|
3100
|
+
parallel(name, config) {
|
|
3101
|
+
return this.addCompositeNode("Parallel", name || "Parallel", config);
|
|
3102
|
+
}
|
|
3103
|
+
/**
|
|
3104
|
+
* 添加并行选择器节点
|
|
3105
|
+
*/
|
|
3106
|
+
parallelSelector(name, config) {
|
|
3107
|
+
return this.addCompositeNode("ParallelSelector", name || "ParallelSelector", config);
|
|
3108
|
+
}
|
|
3109
|
+
/**
|
|
3110
|
+
* 添加随机序列节点
|
|
3111
|
+
*/
|
|
3112
|
+
randomSequence(name) {
|
|
3113
|
+
return this.addCompositeNode("RandomSequence", name || "RandomSequence");
|
|
3114
|
+
}
|
|
3115
|
+
/**
|
|
3116
|
+
* 添加随机选择器节点
|
|
3117
|
+
*/
|
|
3118
|
+
randomSelector(name) {
|
|
3119
|
+
return this.addCompositeNode("RandomSelector", name || "RandomSelector");
|
|
3120
|
+
}
|
|
3121
|
+
/**
|
|
3122
|
+
* 添加反转装饰器
|
|
3123
|
+
*/
|
|
3124
|
+
inverter(name) {
|
|
3125
|
+
return this.addDecoratorNode("Inverter", name || "Inverter");
|
|
3126
|
+
}
|
|
3127
|
+
/**
|
|
3128
|
+
* 添加重复装饰器
|
|
3129
|
+
*/
|
|
3130
|
+
repeater(repeatCount, name) {
|
|
3131
|
+
return this.addDecoratorNode("Repeater", name || "Repeater", {
|
|
3132
|
+
repeatCount
|
|
3133
|
+
});
|
|
3134
|
+
}
|
|
3135
|
+
/**
|
|
3136
|
+
* 添加总是成功装饰器
|
|
3137
|
+
*/
|
|
3138
|
+
alwaysSucceed(name) {
|
|
3139
|
+
return this.addDecoratorNode("AlwaysSucceed", name || "AlwaysSucceed");
|
|
3140
|
+
}
|
|
3141
|
+
/**
|
|
3142
|
+
* 添加总是失败装饰器
|
|
3143
|
+
*/
|
|
3144
|
+
alwaysFail(name) {
|
|
3145
|
+
return this.addDecoratorNode("AlwaysFail", name || "AlwaysFail");
|
|
3146
|
+
}
|
|
3147
|
+
/**
|
|
3148
|
+
* 添加直到成功装饰器
|
|
3149
|
+
*/
|
|
3150
|
+
untilSuccess(name) {
|
|
3151
|
+
return this.addDecoratorNode("UntilSuccess", name || "UntilSuccess");
|
|
3152
|
+
}
|
|
3153
|
+
/**
|
|
3154
|
+
* 添加直到失败装饰器
|
|
3155
|
+
*/
|
|
3156
|
+
untilFail(name) {
|
|
3157
|
+
return this.addDecoratorNode("UntilFail", name || "UntilFail");
|
|
3158
|
+
}
|
|
3159
|
+
/**
|
|
3160
|
+
* 添加条件装饰器
|
|
3161
|
+
*/
|
|
3162
|
+
conditional(blackboardKey, expectedValue, operator, name) {
|
|
3163
|
+
return this.addDecoratorNode("Conditional", name || "Conditional", {
|
|
3164
|
+
blackboardKey,
|
|
3165
|
+
expectedValue,
|
|
3166
|
+
operator: operator || "equals"
|
|
3167
|
+
});
|
|
3168
|
+
}
|
|
3169
|
+
/**
|
|
3170
|
+
* 添加冷却装饰器
|
|
3171
|
+
*/
|
|
3172
|
+
cooldown(cooldownTime, name) {
|
|
3173
|
+
return this.addDecoratorNode("Cooldown", name || "Cooldown", {
|
|
3174
|
+
cooldownTime
|
|
3175
|
+
});
|
|
3176
|
+
}
|
|
3177
|
+
/**
|
|
3178
|
+
* 添加超时装饰器
|
|
3179
|
+
*/
|
|
3180
|
+
timeout(timeout, name) {
|
|
3181
|
+
return this.addDecoratorNode("Timeout", name || "Timeout", {
|
|
3182
|
+
timeout
|
|
3183
|
+
});
|
|
3184
|
+
}
|
|
3185
|
+
/**
|
|
3186
|
+
* 添加等待动作
|
|
3187
|
+
*/
|
|
3188
|
+
wait(duration, name) {
|
|
3189
|
+
return this.addActionNode("Wait", name || "Wait", {
|
|
3190
|
+
duration
|
|
3191
|
+
});
|
|
3192
|
+
}
|
|
3193
|
+
/**
|
|
3194
|
+
* 添加日志动作
|
|
3195
|
+
*/
|
|
3196
|
+
log(message, name) {
|
|
3197
|
+
return this.addActionNode("Log", name || "Log", {
|
|
3198
|
+
message
|
|
3199
|
+
});
|
|
3200
|
+
}
|
|
3201
|
+
/**
|
|
3202
|
+
* 添加设置黑板值动作
|
|
3203
|
+
*/
|
|
3204
|
+
setBlackboardValue(key, value, name) {
|
|
3205
|
+
return this.addActionNode("SetBlackboardValue", name || "SetBlackboardValue", {
|
|
3206
|
+
key,
|
|
3207
|
+
value
|
|
3208
|
+
});
|
|
3209
|
+
}
|
|
3210
|
+
/**
|
|
3211
|
+
* 添加修改黑板值动作
|
|
3212
|
+
*/
|
|
3213
|
+
modifyBlackboardValue(key, operation, value, name) {
|
|
3214
|
+
return this.addActionNode("ModifyBlackboardValue", name || "ModifyBlackboardValue", {
|
|
3215
|
+
key,
|
|
3216
|
+
operation,
|
|
3217
|
+
value
|
|
3218
|
+
});
|
|
3219
|
+
}
|
|
3220
|
+
/**
|
|
3221
|
+
* 添加执行动作
|
|
3222
|
+
*/
|
|
3223
|
+
executeAction(actionName, name) {
|
|
3224
|
+
return this.addActionNode("ExecuteAction", name || "ExecuteAction", {
|
|
3225
|
+
actionName
|
|
3226
|
+
});
|
|
3227
|
+
}
|
|
3228
|
+
/**
|
|
3229
|
+
* 添加黑板比较条件
|
|
3230
|
+
*/
|
|
3231
|
+
blackboardCompare(key, compareValue, operator, name) {
|
|
3232
|
+
return this.addConditionNode("BlackboardCompare", name || "BlackboardCompare", {
|
|
3233
|
+
key,
|
|
3234
|
+
compareValue,
|
|
3235
|
+
operator: operator || "equals"
|
|
3236
|
+
});
|
|
3237
|
+
}
|
|
3238
|
+
/**
|
|
3239
|
+
* 添加黑板存在检查条件
|
|
3240
|
+
*/
|
|
3241
|
+
blackboardExists(key, name) {
|
|
3242
|
+
return this.addConditionNode("BlackboardExists", name || "BlackboardExists", {
|
|
3243
|
+
key
|
|
3244
|
+
});
|
|
3245
|
+
}
|
|
3246
|
+
/**
|
|
3247
|
+
* 添加随机概率条件
|
|
3248
|
+
*/
|
|
3249
|
+
randomProbability(probability, name) {
|
|
3250
|
+
return this.addConditionNode("RandomProbability", name || "RandomProbability", {
|
|
3251
|
+
probability
|
|
3252
|
+
});
|
|
3253
|
+
}
|
|
3254
|
+
/**
|
|
3255
|
+
* 添加执行条件
|
|
3256
|
+
*/
|
|
3257
|
+
executeCondition(conditionName, name) {
|
|
3258
|
+
return this.addConditionNode("ExecuteCondition", name || "ExecuteCondition", {
|
|
3259
|
+
conditionName
|
|
3260
|
+
});
|
|
3261
|
+
}
|
|
3262
|
+
/**
|
|
3263
|
+
* 结束当前节点,返回父节点
|
|
3264
|
+
*/
|
|
3265
|
+
end() {
|
|
3266
|
+
if (this.nodeStack.length > 0) {
|
|
3267
|
+
this.nodeStack.pop();
|
|
3268
|
+
}
|
|
3269
|
+
return this;
|
|
3270
|
+
}
|
|
3271
|
+
/**
|
|
3272
|
+
* 构建行为树数据
|
|
3273
|
+
*/
|
|
3274
|
+
build() {
|
|
3275
|
+
if (!this.treeData.rootNodeId) {
|
|
3276
|
+
throw new Error("No root node defined. Add at least one node to the tree.");
|
|
3277
|
+
}
|
|
3278
|
+
return this.treeData;
|
|
3279
|
+
}
|
|
3280
|
+
addCompositeNode(implementationType, name, config = {}) {
|
|
3281
|
+
const nodeId = this.generateNodeId();
|
|
3282
|
+
const node = {
|
|
3283
|
+
id: nodeId,
|
|
3284
|
+
name,
|
|
3285
|
+
nodeType: NodeType.Composite,
|
|
3286
|
+
implementationType,
|
|
3287
|
+
children: [],
|
|
3288
|
+
config
|
|
3289
|
+
};
|
|
3290
|
+
this.treeData.nodes.set(nodeId, node);
|
|
3291
|
+
if (!this.treeData.rootNodeId) {
|
|
3292
|
+
this.treeData.rootNodeId = nodeId;
|
|
3293
|
+
}
|
|
3294
|
+
if (this.nodeStack.length > 0) {
|
|
3295
|
+
const parentId = this.nodeStack[this.nodeStack.length - 1];
|
|
3296
|
+
const parentNode = this.treeData.nodes.get(parentId);
|
|
3297
|
+
if (parentNode && parentNode.children) {
|
|
3298
|
+
parentNode.children.push(nodeId);
|
|
3299
|
+
}
|
|
3300
|
+
}
|
|
3301
|
+
this.nodeStack.push(nodeId);
|
|
3302
|
+
return this;
|
|
3303
|
+
}
|
|
3304
|
+
addDecoratorNode(implementationType, name, config = {}) {
|
|
3305
|
+
const nodeId = this.generateNodeId();
|
|
3306
|
+
const node = {
|
|
3307
|
+
id: nodeId,
|
|
3308
|
+
name,
|
|
3309
|
+
nodeType: NodeType.Decorator,
|
|
3310
|
+
implementationType,
|
|
3311
|
+
children: [],
|
|
3312
|
+
config
|
|
3313
|
+
};
|
|
3314
|
+
this.treeData.nodes.set(nodeId, node);
|
|
3315
|
+
if (!this.treeData.rootNodeId) {
|
|
3316
|
+
this.treeData.rootNodeId = nodeId;
|
|
3317
|
+
}
|
|
3318
|
+
if (this.nodeStack.length > 0) {
|
|
3319
|
+
const parentId = this.nodeStack[this.nodeStack.length - 1];
|
|
3320
|
+
const parentNode = this.treeData.nodes.get(parentId);
|
|
3321
|
+
if (parentNode && parentNode.children) {
|
|
3322
|
+
parentNode.children.push(nodeId);
|
|
3323
|
+
}
|
|
3324
|
+
}
|
|
3325
|
+
this.nodeStack.push(nodeId);
|
|
3326
|
+
return this;
|
|
3327
|
+
}
|
|
3328
|
+
addActionNode(implementationType, name, config = {}) {
|
|
3329
|
+
const nodeId = this.generateNodeId();
|
|
3330
|
+
const node = {
|
|
3331
|
+
id: nodeId,
|
|
3332
|
+
name,
|
|
3333
|
+
nodeType: NodeType.Action,
|
|
3334
|
+
implementationType,
|
|
3335
|
+
config
|
|
3336
|
+
};
|
|
3337
|
+
this.treeData.nodes.set(nodeId, node);
|
|
3338
|
+
if (!this.treeData.rootNodeId) {
|
|
3339
|
+
this.treeData.rootNodeId = nodeId;
|
|
3340
|
+
}
|
|
3341
|
+
if (this.nodeStack.length > 0) {
|
|
3342
|
+
const parentId = this.nodeStack[this.nodeStack.length - 1];
|
|
3343
|
+
const parentNode = this.treeData.nodes.get(parentId);
|
|
3344
|
+
if (parentNode && parentNode.children) {
|
|
3345
|
+
parentNode.children.push(nodeId);
|
|
3346
|
+
}
|
|
3347
|
+
}
|
|
3348
|
+
return this;
|
|
3349
|
+
}
|
|
3350
|
+
addConditionNode(implementationType, name, config = {}) {
|
|
3351
|
+
const nodeId = this.generateNodeId();
|
|
3352
|
+
const node = {
|
|
3353
|
+
id: nodeId,
|
|
3354
|
+
name,
|
|
3355
|
+
nodeType: NodeType.Condition,
|
|
3356
|
+
implementationType,
|
|
3357
|
+
config
|
|
3358
|
+
};
|
|
3359
|
+
this.treeData.nodes.set(nodeId, node);
|
|
3360
|
+
if (!this.treeData.rootNodeId) {
|
|
3361
|
+
this.treeData.rootNodeId = nodeId;
|
|
3362
|
+
}
|
|
3363
|
+
if (this.nodeStack.length > 0) {
|
|
3364
|
+
const parentId = this.nodeStack[this.nodeStack.length - 1];
|
|
3365
|
+
const parentNode = this.treeData.nodes.get(parentId);
|
|
3366
|
+
if (parentNode && parentNode.children) {
|
|
3367
|
+
parentNode.children.push(nodeId);
|
|
3368
|
+
}
|
|
3369
|
+
}
|
|
3370
|
+
return this;
|
|
3371
|
+
}
|
|
3372
|
+
generateNodeId() {
|
|
3373
|
+
return `node_${this.nodeIdCounter++}`;
|
|
3374
|
+
}
|
|
3375
|
+
};
|
|
3376
|
+
__name(_BehaviorTreeBuilder, "BehaviorTreeBuilder");
|
|
3377
|
+
var BehaviorTreeBuilder = _BehaviorTreeBuilder;
|
|
3378
|
+
|
|
3379
|
+
// src/Serialization/NodeTemplates.ts
|
|
3380
|
+
var NodePropertyType = {
|
|
3381
|
+
/** 字符串 */
|
|
3382
|
+
String: "string",
|
|
3383
|
+
/** 数值 */
|
|
3384
|
+
Number: "number",
|
|
3385
|
+
/** 布尔值 */
|
|
3386
|
+
Boolean: "boolean",
|
|
3387
|
+
/** 选择框 */
|
|
3388
|
+
Select: "select",
|
|
3389
|
+
/** 黑板变量引用 */
|
|
3390
|
+
Blackboard: "blackboard",
|
|
3391
|
+
/** 代码编辑器 */
|
|
3392
|
+
Code: "code",
|
|
3393
|
+
/** 变量引用 */
|
|
3394
|
+
Variable: "variable",
|
|
3395
|
+
/** 资产引用 */
|
|
3396
|
+
Asset: "asset"
|
|
3397
|
+
};
|
|
3398
|
+
var _NodeTemplates = class _NodeTemplates {
|
|
3399
|
+
/**
|
|
3400
|
+
* 获取所有节点模板
|
|
3401
|
+
*/
|
|
3402
|
+
static getAllTemplates() {
|
|
3403
|
+
const allMetadata = NodeMetadataRegistry.getAllMetadata();
|
|
3404
|
+
return allMetadata.map((metadata) => this.convertMetadataToTemplate(metadata));
|
|
3405
|
+
}
|
|
3406
|
+
/**
|
|
3407
|
+
* 根据类型和子类型获取模板
|
|
3408
|
+
*/
|
|
3409
|
+
static getTemplate(type, subType) {
|
|
3410
|
+
return this.getAllTemplates().find((t) => {
|
|
3411
|
+
if (t.type !== type) return false;
|
|
3412
|
+
const config = t.defaultConfig;
|
|
3413
|
+
switch (type) {
|
|
3414
|
+
case NodeType.Composite:
|
|
3415
|
+
return config.compositeType === subType;
|
|
3416
|
+
case NodeType.Decorator:
|
|
3417
|
+
return config.decoratorType === subType;
|
|
3418
|
+
case NodeType.Action:
|
|
3419
|
+
return config.actionType === subType;
|
|
3420
|
+
case NodeType.Condition:
|
|
3421
|
+
return config.conditionType === subType;
|
|
3422
|
+
default:
|
|
3423
|
+
return false;
|
|
3424
|
+
}
|
|
3425
|
+
});
|
|
3426
|
+
}
|
|
3427
|
+
/**
|
|
3428
|
+
* 将NodeMetadata转换为NodeTemplate
|
|
3429
|
+
*/
|
|
3430
|
+
static convertMetadataToTemplate(metadata) {
|
|
3431
|
+
const properties = this.convertConfigSchemaToProperties(metadata.configSchema || {});
|
|
3432
|
+
const defaultConfig = {
|
|
3433
|
+
nodeType: this.nodeTypeToString(metadata.nodeType)
|
|
3434
|
+
};
|
|
3435
|
+
switch (metadata.nodeType) {
|
|
3436
|
+
case NodeType.Composite:
|
|
3437
|
+
defaultConfig.compositeType = metadata.implementationType;
|
|
3438
|
+
break;
|
|
3439
|
+
case NodeType.Decorator:
|
|
3440
|
+
defaultConfig.decoratorType = metadata.implementationType;
|
|
3441
|
+
break;
|
|
3442
|
+
case NodeType.Action:
|
|
3443
|
+
defaultConfig.actionType = metadata.implementationType;
|
|
3444
|
+
break;
|
|
3445
|
+
case NodeType.Condition:
|
|
3446
|
+
defaultConfig.conditionType = metadata.implementationType;
|
|
3447
|
+
break;
|
|
3448
|
+
}
|
|
3449
|
+
if (metadata.configSchema) {
|
|
3450
|
+
for (const [key, field] of Object.entries(metadata.configSchema)) {
|
|
3451
|
+
const fieldDef = field;
|
|
3452
|
+
if (fieldDef.default !== void 0) {
|
|
3453
|
+
defaultConfig[key] = fieldDef.default;
|
|
3454
|
+
}
|
|
3455
|
+
}
|
|
3456
|
+
}
|
|
3457
|
+
const { icon, color } = this.getIconAndColorByType(metadata.nodeType, metadata.category || "");
|
|
3458
|
+
const constraints = metadata.childrenConstraints || this.getDefaultConstraintsByNodeType(metadata.nodeType);
|
|
3459
|
+
const template = {
|
|
3460
|
+
type: metadata.nodeType,
|
|
3461
|
+
displayName: metadata.displayName,
|
|
3462
|
+
category: metadata.category || this.getCategoryByNodeType(metadata.nodeType),
|
|
3463
|
+
description: metadata.description || "",
|
|
3464
|
+
className: metadata.implementationType,
|
|
3465
|
+
icon,
|
|
3466
|
+
color,
|
|
3467
|
+
defaultConfig,
|
|
3468
|
+
properties
|
|
3469
|
+
};
|
|
3470
|
+
if (constraints) {
|
|
3471
|
+
if (constraints.min !== void 0) {
|
|
3472
|
+
template.minChildren = constraints.min;
|
|
3473
|
+
template.requiresChildren = constraints.min > 0;
|
|
3474
|
+
}
|
|
3475
|
+
if (constraints.max !== void 0) {
|
|
3476
|
+
template.maxChildren = constraints.max;
|
|
3477
|
+
}
|
|
3478
|
+
}
|
|
3479
|
+
return template;
|
|
3480
|
+
}
|
|
3481
|
+
/**
|
|
3482
|
+
* 获取节点类型的默认约束
|
|
3483
|
+
*/
|
|
3484
|
+
static getDefaultConstraintsByNodeType(nodeType) {
|
|
3485
|
+
switch (nodeType) {
|
|
3486
|
+
case NodeType.Composite:
|
|
3487
|
+
return {
|
|
3488
|
+
min: 1
|
|
3489
|
+
};
|
|
3490
|
+
case NodeType.Decorator:
|
|
3491
|
+
return {
|
|
3492
|
+
min: 1,
|
|
3493
|
+
max: 1
|
|
3494
|
+
};
|
|
3495
|
+
case NodeType.Action:
|
|
3496
|
+
case NodeType.Condition:
|
|
3497
|
+
return {
|
|
3498
|
+
max: 0
|
|
3499
|
+
};
|
|
3500
|
+
default:
|
|
3501
|
+
return void 0;
|
|
3502
|
+
}
|
|
3503
|
+
}
|
|
3504
|
+
/**
|
|
3505
|
+
* 将ConfigSchema转换为PropertyDefinition数组
|
|
3506
|
+
*/
|
|
3507
|
+
static convertConfigSchemaToProperties(configSchema) {
|
|
3508
|
+
const properties = [];
|
|
3509
|
+
for (const [name, field] of Object.entries(configSchema)) {
|
|
3510
|
+
const property = {
|
|
3511
|
+
name,
|
|
3512
|
+
type: this.mapFieldTypeToPropertyType(field),
|
|
3513
|
+
label: name
|
|
3514
|
+
};
|
|
3515
|
+
if (field.description !== void 0) {
|
|
3516
|
+
property.description = field.description;
|
|
3517
|
+
}
|
|
3518
|
+
if (field.default !== void 0) {
|
|
3519
|
+
property.defaultValue = field.default;
|
|
3520
|
+
}
|
|
3521
|
+
if (field.min !== void 0) {
|
|
3522
|
+
property.min = field.min;
|
|
3523
|
+
}
|
|
3524
|
+
if (field.max !== void 0) {
|
|
3525
|
+
property.max = field.max;
|
|
3526
|
+
}
|
|
3527
|
+
if (field.allowMultipleConnections !== void 0) {
|
|
3528
|
+
property.allowMultipleConnections = field.allowMultipleConnections;
|
|
3529
|
+
}
|
|
3530
|
+
if (field.options) {
|
|
3531
|
+
property.options = field.options.map((opt) => ({
|
|
3532
|
+
label: opt,
|
|
3533
|
+
value: opt
|
|
3534
|
+
}));
|
|
3535
|
+
}
|
|
3536
|
+
if (field.supportBinding) {
|
|
3537
|
+
property.renderConfig = {
|
|
3538
|
+
component: "BindableInput",
|
|
3539
|
+
props: {
|
|
3540
|
+
supportBinding: true
|
|
3541
|
+
}
|
|
3542
|
+
};
|
|
3543
|
+
}
|
|
3544
|
+
properties.push(property);
|
|
3545
|
+
}
|
|
3546
|
+
return properties;
|
|
3547
|
+
}
|
|
3548
|
+
/**
|
|
3549
|
+
* 映射字段类型到属性类型
|
|
3550
|
+
*/
|
|
3551
|
+
static mapFieldTypeToPropertyType(field) {
|
|
3552
|
+
if (field.options && field.options.length > 0) {
|
|
3553
|
+
return NodePropertyType.Select;
|
|
3554
|
+
}
|
|
3555
|
+
switch (field.type) {
|
|
3556
|
+
case "string":
|
|
3557
|
+
return NodePropertyType.String;
|
|
3558
|
+
case "number":
|
|
3559
|
+
return NodePropertyType.Number;
|
|
3560
|
+
case "boolean":
|
|
3561
|
+
return NodePropertyType.Boolean;
|
|
3562
|
+
case "array":
|
|
3563
|
+
case "object":
|
|
3564
|
+
default:
|
|
3565
|
+
return NodePropertyType.String;
|
|
3566
|
+
}
|
|
3567
|
+
}
|
|
3568
|
+
/**
|
|
3569
|
+
* NodeType转字符串
|
|
3570
|
+
*/
|
|
3571
|
+
static nodeTypeToString(nodeType) {
|
|
3572
|
+
switch (nodeType) {
|
|
3573
|
+
case NodeType.Composite:
|
|
3574
|
+
return "composite";
|
|
3575
|
+
case NodeType.Decorator:
|
|
3576
|
+
return "decorator";
|
|
3577
|
+
case NodeType.Action:
|
|
3578
|
+
return "action";
|
|
3579
|
+
case NodeType.Condition:
|
|
3580
|
+
return "condition";
|
|
3581
|
+
default:
|
|
3582
|
+
return "unknown";
|
|
3583
|
+
}
|
|
3584
|
+
}
|
|
3585
|
+
/**
|
|
3586
|
+
* 根据NodeType获取默认分类
|
|
3587
|
+
*/
|
|
3588
|
+
static getCategoryByNodeType(nodeType) {
|
|
3589
|
+
switch (nodeType) {
|
|
3590
|
+
case NodeType.Composite:
|
|
3591
|
+
return "\u7EC4\u5408";
|
|
3592
|
+
case NodeType.Decorator:
|
|
3593
|
+
return "\u88C5\u9970\u5668";
|
|
3594
|
+
case NodeType.Action:
|
|
3595
|
+
return "\u52A8\u4F5C";
|
|
3596
|
+
case NodeType.Condition:
|
|
3597
|
+
return "\u6761\u4EF6";
|
|
3598
|
+
default:
|
|
3599
|
+
return "\u5176\u4ED6";
|
|
3600
|
+
}
|
|
3601
|
+
}
|
|
3602
|
+
/**
|
|
3603
|
+
* 根据节点类型获取默认图标和颜色
|
|
3604
|
+
*/
|
|
3605
|
+
static getIconAndColorByType(nodeType, _category) {
|
|
3606
|
+
switch (nodeType) {
|
|
3607
|
+
case NodeType.Composite:
|
|
3608
|
+
return {
|
|
3609
|
+
icon: "GitBranch",
|
|
3610
|
+
color: "#1976d2"
|
|
3611
|
+
};
|
|
3612
|
+
// 蓝色
|
|
3613
|
+
case NodeType.Decorator:
|
|
3614
|
+
return {
|
|
3615
|
+
icon: "Settings",
|
|
3616
|
+
color: "#fb8c00"
|
|
3617
|
+
};
|
|
3618
|
+
// 橙色
|
|
3619
|
+
case NodeType.Action:
|
|
3620
|
+
return {
|
|
3621
|
+
icon: "Play",
|
|
3622
|
+
color: "#388e3c"
|
|
3623
|
+
};
|
|
3624
|
+
// 绿色
|
|
3625
|
+
case NodeType.Condition:
|
|
3626
|
+
return {
|
|
3627
|
+
icon: "HelpCircle",
|
|
3628
|
+
color: "#d32f2f"
|
|
3629
|
+
};
|
|
3630
|
+
// 红色
|
|
3631
|
+
default:
|
|
3632
|
+
return {
|
|
3633
|
+
icon: "Circle",
|
|
3634
|
+
color: "#757575"
|
|
3635
|
+
};
|
|
3636
|
+
}
|
|
3637
|
+
}
|
|
3638
|
+
};
|
|
3639
|
+
__name(_NodeTemplates, "NodeTemplates");
|
|
3640
|
+
var NodeTemplates = _NodeTemplates;
|
|
3641
|
+
|
|
3642
|
+
// src/Serialization/BehaviorTreeAsset.ts
|
|
3643
|
+
var _BehaviorTreeAssetValidator = class _BehaviorTreeAssetValidator {
|
|
3644
|
+
/**
|
|
3645
|
+
* 验证资产数据的完整性和正确性
|
|
3646
|
+
*/
|
|
3647
|
+
static validate(asset) {
|
|
3648
|
+
const errors = [];
|
|
3649
|
+
const warnings = [];
|
|
3650
|
+
if (!asset.version) {
|
|
3651
|
+
errors.push("Missing version field");
|
|
3652
|
+
}
|
|
3653
|
+
if (!asset.metadata || !asset.metadata.name) {
|
|
3654
|
+
errors.push("Missing or invalid metadata");
|
|
3655
|
+
}
|
|
3656
|
+
if (!asset.rootNodeId) {
|
|
3657
|
+
errors.push("Missing rootNodeId");
|
|
3658
|
+
}
|
|
3659
|
+
if (!asset.nodes || !Array.isArray(asset.nodes)) {
|
|
3660
|
+
errors.push("Missing or invalid nodes array");
|
|
3661
|
+
} else {
|
|
3662
|
+
const nodeIds = /* @__PURE__ */ new Set();
|
|
3663
|
+
const rootNode = asset.nodes.find((n) => n.id === asset.rootNodeId);
|
|
3664
|
+
if (!rootNode) {
|
|
3665
|
+
errors.push(`Root node '${asset.rootNodeId}' not found in nodes array`);
|
|
3666
|
+
}
|
|
3667
|
+
for (const node of asset.nodes) {
|
|
3668
|
+
if (!node.id) {
|
|
3669
|
+
errors.push("Node missing id field");
|
|
3670
|
+
continue;
|
|
3671
|
+
}
|
|
3672
|
+
if (nodeIds.has(node.id)) {
|
|
3673
|
+
errors.push(`Duplicate node id: ${node.id}`);
|
|
3674
|
+
}
|
|
3675
|
+
nodeIds.add(node.id);
|
|
3676
|
+
if (!node.nodeType) {
|
|
3677
|
+
errors.push(`Node ${node.id} missing nodeType`);
|
|
3678
|
+
}
|
|
3679
|
+
if (node.children) {
|
|
3680
|
+
for (const childId of node.children) {
|
|
3681
|
+
if (!asset.nodes.find((n) => n.id === childId)) {
|
|
3682
|
+
errors.push(`Node ${node.id} references non-existent child: ${childId}`);
|
|
3683
|
+
}
|
|
3684
|
+
}
|
|
3685
|
+
}
|
|
3686
|
+
}
|
|
3687
|
+
const referencedNodes = /* @__PURE__ */ new Set([
|
|
3688
|
+
asset.rootNodeId
|
|
3689
|
+
]);
|
|
3690
|
+
const collectReferencedNodes = /* @__PURE__ */ __name((nodeId) => {
|
|
3691
|
+
const node = asset.nodes.find((n) => n.id === nodeId);
|
|
3692
|
+
if (node && node.children) {
|
|
3693
|
+
for (const childId of node.children) {
|
|
3694
|
+
referencedNodes.add(childId);
|
|
3695
|
+
collectReferencedNodes(childId);
|
|
3696
|
+
}
|
|
3697
|
+
}
|
|
3698
|
+
}, "collectReferencedNodes");
|
|
3699
|
+
collectReferencedNodes(asset.rootNodeId);
|
|
3700
|
+
for (const node of asset.nodes) {
|
|
3701
|
+
if (!referencedNodes.has(node.id)) {
|
|
3702
|
+
warnings.push(`Orphaned node detected: ${node.id} (${node.name})`);
|
|
3703
|
+
}
|
|
3704
|
+
}
|
|
3705
|
+
}
|
|
3706
|
+
if (asset.blackboard && Array.isArray(asset.blackboard)) {
|
|
3707
|
+
const varNames = /* @__PURE__ */ new Set();
|
|
3708
|
+
for (const variable of asset.blackboard) {
|
|
3709
|
+
if (!variable.name) {
|
|
3710
|
+
errors.push("Blackboard variable missing name");
|
|
3711
|
+
continue;
|
|
3712
|
+
}
|
|
3713
|
+
if (varNames.has(variable.name)) {
|
|
3714
|
+
errors.push(`Duplicate blackboard variable: ${variable.name}`);
|
|
3715
|
+
}
|
|
3716
|
+
varNames.add(variable.name);
|
|
3717
|
+
if (!variable.type) {
|
|
3718
|
+
errors.push(`Blackboard variable ${variable.name} missing type`);
|
|
3719
|
+
}
|
|
3720
|
+
}
|
|
3721
|
+
}
|
|
3722
|
+
if (asset.propertyBindings && Array.isArray(asset.propertyBindings)) {
|
|
3723
|
+
const nodeIds = new Set(asset.nodes.map((n) => n.id));
|
|
3724
|
+
const varNames = new Set(asset.blackboard?.map((v) => v.name) || []);
|
|
3725
|
+
for (const binding of asset.propertyBindings) {
|
|
3726
|
+
if (!nodeIds.has(binding.nodeId)) {
|
|
3727
|
+
errors.push(`Property binding references non-existent node: ${binding.nodeId}`);
|
|
3728
|
+
}
|
|
3729
|
+
if (!varNames.has(binding.variableName)) {
|
|
3730
|
+
errors.push(`Property binding references non-existent variable: ${binding.variableName}`);
|
|
3731
|
+
}
|
|
3732
|
+
if (!binding.propertyName) {
|
|
3733
|
+
errors.push("Property binding missing propertyName");
|
|
3734
|
+
}
|
|
3735
|
+
}
|
|
3736
|
+
}
|
|
3737
|
+
const result = {
|
|
3738
|
+
valid: errors.length === 0
|
|
3739
|
+
};
|
|
3740
|
+
if (errors.length > 0) {
|
|
3741
|
+
result.errors = errors;
|
|
3742
|
+
}
|
|
3743
|
+
if (warnings.length > 0) {
|
|
3744
|
+
result.warnings = warnings;
|
|
3745
|
+
}
|
|
3746
|
+
return result;
|
|
3747
|
+
}
|
|
3748
|
+
/**
|
|
3749
|
+
* 获取资产统计信息
|
|
3750
|
+
*/
|
|
3751
|
+
static getStats(asset) {
|
|
3752
|
+
let actionCount = 0;
|
|
3753
|
+
let conditionCount = 0;
|
|
3754
|
+
let compositeCount = 0;
|
|
3755
|
+
let decoratorCount = 0;
|
|
3756
|
+
for (const node of asset.nodes) {
|
|
3757
|
+
switch (node.nodeType) {
|
|
3758
|
+
case NodeType.Action:
|
|
3759
|
+
actionCount++;
|
|
3760
|
+
break;
|
|
3761
|
+
case NodeType.Condition:
|
|
3762
|
+
conditionCount++;
|
|
3763
|
+
break;
|
|
3764
|
+
case NodeType.Composite:
|
|
3765
|
+
compositeCount++;
|
|
3766
|
+
break;
|
|
3767
|
+
case NodeType.Decorator:
|
|
3768
|
+
decoratorCount++;
|
|
3769
|
+
break;
|
|
3770
|
+
}
|
|
3771
|
+
}
|
|
3772
|
+
const getDepth = /* @__PURE__ */ __name((nodeId, currentDepth = 0) => {
|
|
3773
|
+
const node = asset.nodes.find((n) => n.id === nodeId);
|
|
3774
|
+
if (!node || !node.children || node.children.length === 0) {
|
|
3775
|
+
return currentDepth;
|
|
3776
|
+
}
|
|
3777
|
+
let maxChildDepth = currentDepth;
|
|
3778
|
+
for (const childId of node.children) {
|
|
3779
|
+
const childDepth = getDepth(childId, currentDepth + 1);
|
|
3780
|
+
maxChildDepth = Math.max(maxChildDepth, childDepth);
|
|
3781
|
+
}
|
|
3782
|
+
return maxChildDepth;
|
|
3783
|
+
}, "getDepth");
|
|
3784
|
+
return {
|
|
3785
|
+
nodeCount: asset.nodes.length,
|
|
3786
|
+
actionCount,
|
|
3787
|
+
conditionCount,
|
|
3788
|
+
compositeCount,
|
|
3789
|
+
decoratorCount,
|
|
3790
|
+
blackboardVariableCount: asset.blackboard?.length || 0,
|
|
3791
|
+
propertyBindingCount: asset.propertyBindings?.length || 0,
|
|
3792
|
+
maxDepth: getDepth(asset.rootNodeId)
|
|
3793
|
+
};
|
|
3794
|
+
}
|
|
3795
|
+
};
|
|
3796
|
+
__name(_BehaviorTreeAssetValidator, "BehaviorTreeAssetValidator");
|
|
3797
|
+
var BehaviorTreeAssetValidator = _BehaviorTreeAssetValidator;
|
|
3798
|
+
|
|
3799
|
+
// src/Serialization/EditorFormatConverter.ts
|
|
3800
|
+
import { createLogger as createLogger2 } from "@esengine/ecs-framework";
|
|
3801
|
+
var logger2 = createLogger2("EditorFormatConverter");
|
|
3802
|
+
var _EditorFormatConverter = class _EditorFormatConverter {
|
|
3803
|
+
/**
|
|
3804
|
+
* 转换编辑器格式为资产格式
|
|
3805
|
+
*
|
|
3806
|
+
* @param editorData 编辑器数据
|
|
3807
|
+
* @param metadata 可选的元数据覆盖
|
|
3808
|
+
* @returns 行为树资产
|
|
3809
|
+
*/
|
|
3810
|
+
static toAsset(editorData, metadata) {
|
|
3811
|
+
logger2.info("\u5F00\u59CB\u8F6C\u6362\u7F16\u8F91\u5668\u683C\u5F0F\u5230\u8D44\u4EA7\u683C\u5F0F");
|
|
3812
|
+
const rootNode = this.findRootNode(editorData.nodes);
|
|
3813
|
+
if (!rootNode) {
|
|
3814
|
+
throw new Error("\u672A\u627E\u5230\u6839\u8282\u70B9");
|
|
3815
|
+
}
|
|
3816
|
+
const assetMetadata = {
|
|
3817
|
+
name: metadata?.name || editorData.metadata?.name || "Untitled Behavior Tree",
|
|
3818
|
+
version: metadata?.version || editorData.version || "1.0.0"
|
|
3819
|
+
};
|
|
3820
|
+
const description = metadata?.description || editorData.metadata?.description;
|
|
3821
|
+
if (description) {
|
|
3822
|
+
assetMetadata.description = description;
|
|
3823
|
+
}
|
|
3824
|
+
const createdAt = metadata?.createdAt || editorData.metadata?.createdAt;
|
|
3825
|
+
if (createdAt) {
|
|
3826
|
+
assetMetadata.createdAt = createdAt;
|
|
3827
|
+
}
|
|
3828
|
+
const modifiedAt = metadata?.modifiedAt || (/* @__PURE__ */ new Date()).toISOString();
|
|
3829
|
+
if (modifiedAt) {
|
|
3830
|
+
assetMetadata.modifiedAt = modifiedAt;
|
|
3831
|
+
}
|
|
3832
|
+
const nodes = this.convertNodes(editorData.nodes);
|
|
3833
|
+
const blackboard = this.convertBlackboard(editorData.blackboard);
|
|
3834
|
+
const propertyBindings = this.convertPropertyBindings(editorData.connections, editorData.nodes, blackboard);
|
|
3835
|
+
const asset = {
|
|
3836
|
+
version: "1.0.0",
|
|
3837
|
+
metadata: assetMetadata,
|
|
3838
|
+
rootNodeId: rootNode.id,
|
|
3839
|
+
nodes,
|
|
3840
|
+
blackboard
|
|
3841
|
+
};
|
|
3842
|
+
if (propertyBindings.length > 0) {
|
|
3843
|
+
asset.propertyBindings = propertyBindings;
|
|
3844
|
+
}
|
|
3845
|
+
logger2.info(`\u8F6C\u6362\u5B8C\u6210: ${nodes.length}\u4E2A\u8282\u70B9, ${blackboard.length}\u4E2A\u9ED1\u677F\u53D8\u91CF, ${propertyBindings.length}\u4E2A\u5C5E\u6027\u7ED1\u5B9A`);
|
|
3846
|
+
return asset;
|
|
3847
|
+
}
|
|
3848
|
+
/**
|
|
3849
|
+
* 查找根节点
|
|
3850
|
+
*/
|
|
3851
|
+
static findRootNode(nodes) {
|
|
3852
|
+
return nodes.find((node) => node.template.category === "\u6839\u8282\u70B9" || node.data.nodeType === "root") || null;
|
|
3853
|
+
}
|
|
3854
|
+
/**
|
|
3855
|
+
* 转换节点列表
|
|
3856
|
+
*/
|
|
3857
|
+
static convertNodes(editorNodes) {
|
|
3858
|
+
return editorNodes.map((node) => this.convertNode(node));
|
|
3859
|
+
}
|
|
3860
|
+
/**
|
|
3861
|
+
* 转换单个节点
|
|
3862
|
+
*/
|
|
3863
|
+
static convertNode(editorNode) {
|
|
3864
|
+
const data = {
|
|
3865
|
+
...editorNode.data
|
|
3866
|
+
};
|
|
3867
|
+
delete data.nodeType;
|
|
3868
|
+
if (editorNode.template.className) {
|
|
3869
|
+
data.className = editorNode.template.className;
|
|
3870
|
+
}
|
|
3871
|
+
return {
|
|
3872
|
+
id: editorNode.id,
|
|
3873
|
+
name: editorNode.template.displayName || editorNode.data.name || "Node",
|
|
3874
|
+
nodeType: editorNode.template.type,
|
|
3875
|
+
data,
|
|
3876
|
+
children: editorNode.children || []
|
|
3877
|
+
};
|
|
3878
|
+
}
|
|
3879
|
+
/**
|
|
3880
|
+
* 转换黑板变量
|
|
3881
|
+
*/
|
|
3882
|
+
static convertBlackboard(blackboard) {
|
|
3883
|
+
const variables = [];
|
|
3884
|
+
for (const [name, value] of Object.entries(blackboard)) {
|
|
3885
|
+
const type = this.inferBlackboardType(value);
|
|
3886
|
+
variables.push({
|
|
3887
|
+
name,
|
|
3888
|
+
type,
|
|
3889
|
+
defaultValue: value
|
|
3890
|
+
});
|
|
3891
|
+
}
|
|
3892
|
+
return variables;
|
|
3893
|
+
}
|
|
3894
|
+
/**
|
|
3895
|
+
* 推断黑板变量类型
|
|
3896
|
+
*/
|
|
3897
|
+
static inferBlackboardType(value) {
|
|
3898
|
+
if (typeof value === "number") {
|
|
3899
|
+
return BlackboardValueType.Number;
|
|
3900
|
+
} else if (typeof value === "string") {
|
|
3901
|
+
return BlackboardValueType.String;
|
|
3902
|
+
} else if (typeof value === "boolean") {
|
|
3903
|
+
return BlackboardValueType.Boolean;
|
|
3904
|
+
} else {
|
|
3905
|
+
return BlackboardValueType.Object;
|
|
3906
|
+
}
|
|
3907
|
+
}
|
|
3908
|
+
/**
|
|
3909
|
+
* 转换属性绑定
|
|
3910
|
+
*/
|
|
3911
|
+
static convertPropertyBindings(connections, nodes, blackboard) {
|
|
3912
|
+
const bindings = [];
|
|
3913
|
+
const blackboardVarNames = new Set(blackboard.map((v) => v.name));
|
|
3914
|
+
const propertyConnections = connections.filter((conn) => conn.connectionType === "property");
|
|
3915
|
+
for (const conn of propertyConnections) {
|
|
3916
|
+
const fromNode = nodes.find((n) => n.id === conn.from);
|
|
3917
|
+
const toNode = nodes.find((n) => n.id === conn.to);
|
|
3918
|
+
if (!fromNode || !toNode || !conn.toProperty) {
|
|
3919
|
+
logger2.warn(`\u8DF3\u8FC7\u65E0\u6548\u7684\u5C5E\u6027\u8FDE\u63A5: from=${conn.from}, to=${conn.to}`);
|
|
3920
|
+
continue;
|
|
3921
|
+
}
|
|
3922
|
+
let variableName;
|
|
3923
|
+
if (fromNode.data.nodeType === "blackboard-variable") {
|
|
3924
|
+
variableName = fromNode.data.variableName;
|
|
3925
|
+
} else if (conn.fromProperty) {
|
|
3926
|
+
variableName = conn.fromProperty;
|
|
3927
|
+
}
|
|
3928
|
+
if (!variableName) {
|
|
3929
|
+
logger2.warn(`\u65E0\u6CD5\u786E\u5B9A\u53D8\u91CF\u540D: from\u8282\u70B9=${fromNode.template.displayName}`);
|
|
3930
|
+
continue;
|
|
3931
|
+
}
|
|
3932
|
+
if (!blackboardVarNames.has(variableName)) {
|
|
3933
|
+
logger2.warn(`\u5C5E\u6027\u7ED1\u5B9A\u5F15\u7528\u4E86\u4E0D\u5B58\u5728\u7684\u9ED1\u677F\u53D8\u91CF: ${variableName}`);
|
|
3934
|
+
continue;
|
|
3935
|
+
}
|
|
3936
|
+
bindings.push({
|
|
3937
|
+
nodeId: toNode.id,
|
|
3938
|
+
propertyName: conn.toProperty,
|
|
3939
|
+
variableName
|
|
3940
|
+
});
|
|
3941
|
+
}
|
|
3942
|
+
return bindings;
|
|
3943
|
+
}
|
|
3944
|
+
/**
|
|
3945
|
+
* 从资产格式转换回编辑器格式(用于加载)
|
|
3946
|
+
*
|
|
3947
|
+
* @param asset 行为树资产
|
|
3948
|
+
* @returns 编辑器格式数据
|
|
3949
|
+
*/
|
|
3950
|
+
static fromAsset(asset) {
|
|
3951
|
+
logger2.info("\u5F00\u59CB\u8F6C\u6362\u8D44\u4EA7\u683C\u5F0F\u5230\u7F16\u8F91\u5668\u683C\u5F0F");
|
|
3952
|
+
const nodes = this.convertNodesFromAsset(asset.nodes);
|
|
3953
|
+
const blackboard = {};
|
|
3954
|
+
for (const variable of asset.blackboard) {
|
|
3955
|
+
blackboard[variable.name] = variable.defaultValue;
|
|
3956
|
+
}
|
|
3957
|
+
const connections = this.convertPropertyBindingsToConnections(asset.propertyBindings || []);
|
|
3958
|
+
const nodeConnections = this.buildNodeConnections(asset.nodes);
|
|
3959
|
+
connections.push(...nodeConnections);
|
|
3960
|
+
const metadata = {
|
|
3961
|
+
name: asset.metadata.name
|
|
3962
|
+
};
|
|
3963
|
+
if (asset.metadata.description) {
|
|
3964
|
+
metadata.description = asset.metadata.description;
|
|
3965
|
+
}
|
|
3966
|
+
if (asset.metadata.createdAt) {
|
|
3967
|
+
metadata.createdAt = asset.metadata.createdAt;
|
|
3968
|
+
}
|
|
3969
|
+
if (asset.metadata.modifiedAt) {
|
|
3970
|
+
metadata.modifiedAt = asset.metadata.modifiedAt;
|
|
3971
|
+
}
|
|
3972
|
+
const editorData = {
|
|
3973
|
+
version: asset.metadata.version,
|
|
3974
|
+
metadata,
|
|
3975
|
+
nodes,
|
|
3976
|
+
connections,
|
|
3977
|
+
blackboard,
|
|
3978
|
+
canvasState: {
|
|
3979
|
+
offset: {
|
|
3980
|
+
x: 0,
|
|
3981
|
+
y: 0
|
|
3982
|
+
},
|
|
3983
|
+
scale: 1
|
|
3984
|
+
}
|
|
3985
|
+
};
|
|
3986
|
+
logger2.info(`\u8F6C\u6362\u5B8C\u6210: ${nodes.length}\u4E2A\u8282\u70B9, ${connections.length}\u4E2A\u8FDE\u63A5`);
|
|
3987
|
+
return editorData;
|
|
3988
|
+
}
|
|
3989
|
+
/**
|
|
3990
|
+
* 从资产格式转换节点
|
|
3991
|
+
*/
|
|
3992
|
+
static convertNodesFromAsset(assetNodes) {
|
|
3993
|
+
return assetNodes.map((node, index) => {
|
|
3994
|
+
const position = {
|
|
3995
|
+
x: 100 + index % 5 * 250,
|
|
3996
|
+
y: 100 + Math.floor(index / 5) * 150
|
|
3997
|
+
};
|
|
3998
|
+
const template = {
|
|
3999
|
+
displayName: node.name,
|
|
4000
|
+
category: this.inferCategory(node.nodeType),
|
|
4001
|
+
type: node.nodeType
|
|
4002
|
+
};
|
|
4003
|
+
if (node.data.className) {
|
|
4004
|
+
template.className = node.data.className;
|
|
4005
|
+
}
|
|
4006
|
+
return {
|
|
4007
|
+
id: node.id,
|
|
4008
|
+
template,
|
|
4009
|
+
data: {
|
|
4010
|
+
...node.data
|
|
4011
|
+
},
|
|
4012
|
+
position,
|
|
4013
|
+
children: node.children
|
|
4014
|
+
};
|
|
4015
|
+
});
|
|
4016
|
+
}
|
|
4017
|
+
/**
|
|
4018
|
+
* 推断节点分类
|
|
4019
|
+
*/
|
|
4020
|
+
static inferCategory(nodeType) {
|
|
4021
|
+
switch (nodeType) {
|
|
4022
|
+
case NodeType.Action:
|
|
4023
|
+
return "\u52A8\u4F5C";
|
|
4024
|
+
case NodeType.Condition:
|
|
4025
|
+
return "\u6761\u4EF6";
|
|
4026
|
+
case NodeType.Composite:
|
|
4027
|
+
return "\u7EC4\u5408";
|
|
4028
|
+
case NodeType.Decorator:
|
|
4029
|
+
return "\u88C5\u9970\u5668";
|
|
4030
|
+
default:
|
|
4031
|
+
return "\u5176\u4ED6";
|
|
4032
|
+
}
|
|
4033
|
+
}
|
|
4034
|
+
/**
|
|
4035
|
+
* 将属性绑定转换为连接
|
|
4036
|
+
*/
|
|
4037
|
+
static convertPropertyBindingsToConnections(bindings) {
|
|
4038
|
+
const connections = [];
|
|
4039
|
+
for (const binding of bindings) {
|
|
4040
|
+
connections.push({
|
|
4041
|
+
from: "blackboard",
|
|
4042
|
+
to: binding.nodeId,
|
|
4043
|
+
toProperty: binding.propertyName,
|
|
4044
|
+
connectionType: "property"
|
|
4045
|
+
});
|
|
4046
|
+
}
|
|
4047
|
+
return connections;
|
|
4048
|
+
}
|
|
4049
|
+
/**
|
|
4050
|
+
* 根据children关系构建节点连接
|
|
4051
|
+
*/
|
|
4052
|
+
static buildNodeConnections(nodes) {
|
|
4053
|
+
const connections = [];
|
|
4054
|
+
for (const node of nodes) {
|
|
4055
|
+
for (const childId of node.children) {
|
|
4056
|
+
connections.push({
|
|
4057
|
+
from: node.id,
|
|
4058
|
+
to: childId,
|
|
4059
|
+
connectionType: "node"
|
|
4060
|
+
});
|
|
4061
|
+
}
|
|
4062
|
+
}
|
|
4063
|
+
return connections;
|
|
4064
|
+
}
|
|
4065
|
+
};
|
|
4066
|
+
__name(_EditorFormatConverter, "EditorFormatConverter");
|
|
4067
|
+
var EditorFormatConverter = _EditorFormatConverter;
|
|
4068
|
+
|
|
4069
|
+
// src/Serialization/BehaviorTreeAssetSerializer.ts
|
|
4070
|
+
import { createLogger as createLogger3, BinarySerializer } from "@esengine/ecs-framework";
|
|
4071
|
+
var logger3 = createLogger3("BehaviorTreeAssetSerializer");
|
|
4072
|
+
var _BehaviorTreeAssetSerializer = class _BehaviorTreeAssetSerializer {
|
|
4073
|
+
/**
|
|
4074
|
+
* 序列化资产
|
|
4075
|
+
*
|
|
4076
|
+
* @param asset 行为树资产
|
|
4077
|
+
* @param options 序列化选项
|
|
4078
|
+
* @returns 序列化后的数据(字符串或Uint8Array)
|
|
4079
|
+
*
|
|
4080
|
+
* @example
|
|
4081
|
+
* ```typescript
|
|
4082
|
+
* // JSON格式
|
|
4083
|
+
* const jsonData = BehaviorTreeAssetSerializer.serialize(asset, { format: 'json', pretty: true });
|
|
4084
|
+
*
|
|
4085
|
+
* // 二进制格式
|
|
4086
|
+
* const binaryData = BehaviorTreeAssetSerializer.serialize(asset, { format: 'binary' });
|
|
4087
|
+
* ```
|
|
4088
|
+
*/
|
|
4089
|
+
static serialize(asset, options = {
|
|
4090
|
+
format: "json",
|
|
4091
|
+
pretty: true
|
|
4092
|
+
}) {
|
|
4093
|
+
if (options.validate !== false) {
|
|
4094
|
+
const validation = BehaviorTreeAssetValidator.validate(asset);
|
|
4095
|
+
if (!validation.valid) {
|
|
4096
|
+
const errors = validation.errors?.join(", ") || "Unknown error";
|
|
4097
|
+
throw new Error(`\u8D44\u4EA7\u9A8C\u8BC1\u5931\u8D25: ${errors}`);
|
|
4098
|
+
}
|
|
4099
|
+
if (validation.warnings && validation.warnings.length > 0) {
|
|
4100
|
+
logger3.warn(`\u8D44\u4EA7\u9A8C\u8BC1\u8B66\u544A: ${validation.warnings.join(", ")}`);
|
|
4101
|
+
}
|
|
4102
|
+
}
|
|
4103
|
+
if (options.format === "json") {
|
|
4104
|
+
return this.serializeToJSON(asset, options.pretty);
|
|
4105
|
+
} else {
|
|
4106
|
+
return this.serializeToBinary(asset);
|
|
4107
|
+
}
|
|
4108
|
+
}
|
|
4109
|
+
/**
|
|
4110
|
+
* 序列化为JSON格式
|
|
4111
|
+
*/
|
|
4112
|
+
static serializeToJSON(asset, pretty = true) {
|
|
4113
|
+
try {
|
|
4114
|
+
const json = pretty ? JSON.stringify(asset, null, 2) : JSON.stringify(asset);
|
|
4115
|
+
logger3.info(`\u5DF2\u5E8F\u5217\u5316\u4E3AJSON: ${json.length} \u5B57\u7B26`);
|
|
4116
|
+
return json;
|
|
4117
|
+
} catch (error) {
|
|
4118
|
+
throw new Error(`JSON\u5E8F\u5217\u5316\u5931\u8D25: ${error}`);
|
|
4119
|
+
}
|
|
4120
|
+
}
|
|
4121
|
+
/**
|
|
4122
|
+
* 序列化为二进制格式
|
|
4123
|
+
*/
|
|
4124
|
+
static serializeToBinary(asset) {
|
|
4125
|
+
try {
|
|
4126
|
+
const binary = BinarySerializer.encode(asset);
|
|
4127
|
+
logger3.info(`\u5DF2\u5E8F\u5217\u5316\u4E3A\u4E8C\u8FDB\u5236: ${binary.length} \u5B57\u8282`);
|
|
4128
|
+
return binary;
|
|
4129
|
+
} catch (error) {
|
|
4130
|
+
throw new Error(`\u4E8C\u8FDB\u5236\u5E8F\u5217\u5316\u5931\u8D25: ${error}`);
|
|
4131
|
+
}
|
|
4132
|
+
}
|
|
4133
|
+
/**
|
|
4134
|
+
* 反序列化资产
|
|
4135
|
+
*
|
|
4136
|
+
* @param data 序列化的数据(字符串或Uint8Array)
|
|
4137
|
+
* @param options 反序列化选项
|
|
4138
|
+
* @returns 行为树资产
|
|
4139
|
+
*
|
|
4140
|
+
* @example
|
|
4141
|
+
* ```typescript
|
|
4142
|
+
* // 从JSON加载
|
|
4143
|
+
* const asset = BehaviorTreeAssetSerializer.deserialize(jsonString);
|
|
4144
|
+
*
|
|
4145
|
+
* // 从二进制加载
|
|
4146
|
+
* const asset = BehaviorTreeAssetSerializer.deserialize(binaryData);
|
|
4147
|
+
* ```
|
|
4148
|
+
*/
|
|
4149
|
+
static deserialize(data, options = {
|
|
4150
|
+
validate: true,
|
|
4151
|
+
strict: true
|
|
4152
|
+
}) {
|
|
4153
|
+
let asset;
|
|
4154
|
+
try {
|
|
4155
|
+
if (typeof data === "string") {
|
|
4156
|
+
asset = this.deserializeFromJSON(data);
|
|
4157
|
+
} else {
|
|
4158
|
+
asset = this.deserializeFromBinary(data);
|
|
4159
|
+
}
|
|
4160
|
+
} catch (error) {
|
|
4161
|
+
throw new Error(`\u53CD\u5E8F\u5217\u5316\u5931\u8D25: ${error}`);
|
|
4162
|
+
}
|
|
4163
|
+
if (options.validate !== false) {
|
|
4164
|
+
const validation = BehaviorTreeAssetValidator.validate(asset);
|
|
4165
|
+
if (!validation.valid) {
|
|
4166
|
+
const errors = validation.errors?.join(", ") || "Unknown error";
|
|
4167
|
+
if (options.strict) {
|
|
4168
|
+
throw new Error(`\u8D44\u4EA7\u9A8C\u8BC1\u5931\u8D25: ${errors}`);
|
|
4169
|
+
} else {
|
|
4170
|
+
logger3.error(`\u8D44\u4EA7\u9A8C\u8BC1\u5931\u8D25: ${errors}`);
|
|
4171
|
+
}
|
|
4172
|
+
}
|
|
4173
|
+
if (validation.warnings && validation.warnings.length > 0) {
|
|
4174
|
+
logger3.warn(`\u8D44\u4EA7\u9A8C\u8BC1\u8B66\u544A: ${validation.warnings.join(", ")}`);
|
|
4175
|
+
}
|
|
4176
|
+
}
|
|
4177
|
+
return asset;
|
|
4178
|
+
}
|
|
4179
|
+
/**
|
|
4180
|
+
* 从JSON反序列化
|
|
4181
|
+
*/
|
|
4182
|
+
static deserializeFromJSON(json) {
|
|
4183
|
+
try {
|
|
4184
|
+
const data = JSON.parse(json);
|
|
4185
|
+
const isEditorFormat = !data.rootNodeId && data.nodes && data.connections;
|
|
4186
|
+
if (isEditorFormat) {
|
|
4187
|
+
logger3.info("\u68C0\u6D4B\u5230\u7F16\u8F91\u5668\u683C\u5F0F\uFF0C\u6B63\u5728\u8F6C\u6362\u4E3A\u8FD0\u884C\u65F6\u8D44\u4EA7\u683C\u5F0F...");
|
|
4188
|
+
const editorData = data;
|
|
4189
|
+
const asset = EditorFormatConverter.toAsset(editorData);
|
|
4190
|
+
logger3.info(`\u5DF2\u4ECE\u7F16\u8F91\u5668\u683C\u5F0F\u8F6C\u6362: ${asset.nodes.length} \u4E2A\u8282\u70B9`);
|
|
4191
|
+
return asset;
|
|
4192
|
+
} else {
|
|
4193
|
+
const asset = data;
|
|
4194
|
+
logger3.info(`\u5DF2\u4ECE\u8FD0\u884C\u65F6\u8D44\u4EA7\u683C\u5F0F\u53CD\u5E8F\u5217\u5316: ${asset.nodes.length} \u4E2A\u8282\u70B9`);
|
|
4195
|
+
return asset;
|
|
4196
|
+
}
|
|
4197
|
+
} catch (error) {
|
|
4198
|
+
throw new Error(`JSON\u89E3\u6790\u5931\u8D25: ${error}`);
|
|
4199
|
+
}
|
|
4200
|
+
}
|
|
4201
|
+
/**
|
|
4202
|
+
* 从二进制反序列化
|
|
4203
|
+
*/
|
|
4204
|
+
static deserializeFromBinary(binary) {
|
|
4205
|
+
try {
|
|
4206
|
+
const asset = BinarySerializer.decode(binary);
|
|
4207
|
+
logger3.info(`\u5DF2\u4ECE\u4E8C\u8FDB\u5236\u53CD\u5E8F\u5217\u5316: ${asset.nodes.length} \u4E2A\u8282\u70B9`);
|
|
4208
|
+
return asset;
|
|
4209
|
+
} catch (error) {
|
|
4210
|
+
throw new Error(`\u4E8C\u8FDB\u5236\u89E3\u7801\u5931\u8D25: ${error}`);
|
|
4211
|
+
}
|
|
4212
|
+
}
|
|
4213
|
+
/**
|
|
4214
|
+
* 检测数据格式
|
|
4215
|
+
*
|
|
4216
|
+
* @param data 序列化的数据
|
|
4217
|
+
* @returns 格式类型
|
|
4218
|
+
*/
|
|
4219
|
+
static detectFormat(data) {
|
|
4220
|
+
if (typeof data === "string") {
|
|
4221
|
+
return "json";
|
|
4222
|
+
} else {
|
|
4223
|
+
return "binary";
|
|
4224
|
+
}
|
|
4225
|
+
}
|
|
4226
|
+
/**
|
|
4227
|
+
* 获取序列化数据的信息(不完全反序列化)
|
|
4228
|
+
*
|
|
4229
|
+
* @param data 序列化的数据
|
|
4230
|
+
* @returns 资产元信息
|
|
4231
|
+
*/
|
|
4232
|
+
static getInfo(data) {
|
|
4233
|
+
try {
|
|
4234
|
+
const format = this.detectFormat(data);
|
|
4235
|
+
let asset;
|
|
4236
|
+
if (format === "json") {
|
|
4237
|
+
asset = JSON.parse(data);
|
|
4238
|
+
} else {
|
|
4239
|
+
asset = BinarySerializer.decode(data);
|
|
4240
|
+
}
|
|
4241
|
+
const size = typeof data === "string" ? data.length : data.length;
|
|
4242
|
+
return {
|
|
4243
|
+
format,
|
|
4244
|
+
name: asset.metadata.name,
|
|
4245
|
+
version: asset.version,
|
|
4246
|
+
nodeCount: asset.nodes.length,
|
|
4247
|
+
blackboardVariableCount: asset.blackboard.length,
|
|
4248
|
+
size
|
|
4249
|
+
};
|
|
4250
|
+
} catch (error) {
|
|
4251
|
+
logger3.error(`\u83B7\u53D6\u8D44\u4EA7\u4FE1\u606F\u5931\u8D25: ${error}`);
|
|
4252
|
+
return null;
|
|
4253
|
+
}
|
|
4254
|
+
}
|
|
4255
|
+
/**
|
|
4256
|
+
* 转换格式
|
|
4257
|
+
*
|
|
4258
|
+
* @param data 源数据
|
|
4259
|
+
* @param targetFormat 目标格式
|
|
4260
|
+
* @param pretty 是否美化JSON(仅当目标格式为json时有效)
|
|
4261
|
+
* @returns 转换后的数据
|
|
4262
|
+
*
|
|
4263
|
+
* @example
|
|
4264
|
+
* ```typescript
|
|
4265
|
+
* // JSON转二进制
|
|
4266
|
+
* const binary = BehaviorTreeAssetSerializer.convert(jsonString, 'binary');
|
|
4267
|
+
*
|
|
4268
|
+
* // 二进制转JSON
|
|
4269
|
+
* const json = BehaviorTreeAssetSerializer.convert(binaryData, 'json', true);
|
|
4270
|
+
* ```
|
|
4271
|
+
*/
|
|
4272
|
+
static convert(data, targetFormat, pretty = true) {
|
|
4273
|
+
const asset = this.deserialize(data, {
|
|
4274
|
+
validate: false
|
|
4275
|
+
});
|
|
4276
|
+
return this.serialize(asset, {
|
|
4277
|
+
format: targetFormat,
|
|
4278
|
+
pretty,
|
|
4279
|
+
validate: false
|
|
4280
|
+
});
|
|
4281
|
+
}
|
|
4282
|
+
/**
|
|
4283
|
+
* 比较两个资产数据的大小
|
|
4284
|
+
*
|
|
4285
|
+
* @param jsonData JSON格式数据
|
|
4286
|
+
* @param binaryData 二进制格式数据
|
|
4287
|
+
* @returns 压缩率(百分比)
|
|
4288
|
+
*/
|
|
4289
|
+
static compareSize(jsonData, binaryData) {
|
|
4290
|
+
const jsonSize = jsonData.length;
|
|
4291
|
+
const binarySize = binaryData.length;
|
|
4292
|
+
const savedBytes = jsonSize - binarySize;
|
|
4293
|
+
const compressionRatio = savedBytes / jsonSize * 100;
|
|
4294
|
+
return {
|
|
4295
|
+
jsonSize,
|
|
4296
|
+
binarySize,
|
|
4297
|
+
compressionRatio,
|
|
4298
|
+
savedBytes
|
|
4299
|
+
};
|
|
4300
|
+
}
|
|
4301
|
+
};
|
|
4302
|
+
__name(_BehaviorTreeAssetSerializer, "BehaviorTreeAssetSerializer");
|
|
4303
|
+
var BehaviorTreeAssetSerializer = _BehaviorTreeAssetSerializer;
|
|
4304
|
+
|
|
4305
|
+
// src/Services/GlobalBlackboardService.ts
|
|
4306
|
+
var _GlobalBlackboardService = class _GlobalBlackboardService {
|
|
4307
|
+
constructor() {
|
|
4308
|
+
__publicField(this, "variables", /* @__PURE__ */ new Map());
|
|
4309
|
+
}
|
|
4310
|
+
dispose() {
|
|
4311
|
+
this.variables.clear();
|
|
4312
|
+
}
|
|
4313
|
+
/**
|
|
4314
|
+
* 定义全局变量
|
|
4315
|
+
*/
|
|
4316
|
+
defineVariable(name, type, initialValue, options) {
|
|
4317
|
+
const variable = {
|
|
4318
|
+
name,
|
|
4319
|
+
type,
|
|
4320
|
+
value: initialValue,
|
|
4321
|
+
readonly: options?.readonly ?? false
|
|
4322
|
+
};
|
|
4323
|
+
if (options?.description !== void 0) {
|
|
4324
|
+
variable.description = options.description;
|
|
4325
|
+
}
|
|
4326
|
+
this.variables.set(name, variable);
|
|
4327
|
+
}
|
|
4328
|
+
/**
|
|
4329
|
+
* 获取全局变量值
|
|
4330
|
+
*/
|
|
4331
|
+
getValue(name) {
|
|
4332
|
+
const variable = this.variables.get(name);
|
|
4333
|
+
return variable?.value;
|
|
4334
|
+
}
|
|
4335
|
+
/**
|
|
4336
|
+
* 设置全局变量值
|
|
4337
|
+
*/
|
|
4338
|
+
setValue(name, value, force = false) {
|
|
4339
|
+
const variable = this.variables.get(name);
|
|
4340
|
+
if (!variable) {
|
|
4341
|
+
return false;
|
|
4342
|
+
}
|
|
4343
|
+
if (variable.readonly && !force) {
|
|
4344
|
+
return false;
|
|
4345
|
+
}
|
|
4346
|
+
variable.value = value;
|
|
4347
|
+
return true;
|
|
4348
|
+
}
|
|
4349
|
+
/**
|
|
4350
|
+
* 检查全局变量是否存在
|
|
4351
|
+
*/
|
|
4352
|
+
hasVariable(name) {
|
|
4353
|
+
return this.variables.has(name);
|
|
4354
|
+
}
|
|
4355
|
+
/**
|
|
4356
|
+
* 删除全局变量
|
|
4357
|
+
*/
|
|
4358
|
+
removeVariable(name) {
|
|
4359
|
+
return this.variables.delete(name);
|
|
4360
|
+
}
|
|
4361
|
+
/**
|
|
4362
|
+
* 获取所有变量名
|
|
4363
|
+
*/
|
|
4364
|
+
getVariableNames() {
|
|
4365
|
+
return Array.from(this.variables.keys());
|
|
4366
|
+
}
|
|
4367
|
+
/**
|
|
4368
|
+
* 获取所有变量
|
|
4369
|
+
*/
|
|
4370
|
+
getAllVariables() {
|
|
4371
|
+
return Array.from(this.variables.values());
|
|
4372
|
+
}
|
|
4373
|
+
/**
|
|
4374
|
+
* 清空所有全局变量
|
|
4375
|
+
*/
|
|
4376
|
+
clear() {
|
|
4377
|
+
this.variables.clear();
|
|
4378
|
+
}
|
|
4379
|
+
/**
|
|
4380
|
+
* 批量设置变量
|
|
4381
|
+
*/
|
|
4382
|
+
setVariables(values) {
|
|
4383
|
+
for (const [name, value] of Object.entries(values)) {
|
|
4384
|
+
const variable = this.variables.get(name);
|
|
4385
|
+
if (variable && !variable.readonly) {
|
|
4386
|
+
variable.value = value;
|
|
4387
|
+
}
|
|
4388
|
+
}
|
|
4389
|
+
}
|
|
4390
|
+
/**
|
|
4391
|
+
* 批量获取变量
|
|
4392
|
+
*/
|
|
4393
|
+
getVariables(names) {
|
|
4394
|
+
const result = {};
|
|
4395
|
+
for (const name of names) {
|
|
4396
|
+
const value = this.getValue(name);
|
|
4397
|
+
if (value !== void 0) {
|
|
4398
|
+
result[name] = value;
|
|
4399
|
+
}
|
|
4400
|
+
}
|
|
4401
|
+
return result;
|
|
4402
|
+
}
|
|
4403
|
+
/**
|
|
4404
|
+
* 导出配置
|
|
4405
|
+
*/
|
|
4406
|
+
exportConfig() {
|
|
4407
|
+
return {
|
|
4408
|
+
version: "1.0",
|
|
4409
|
+
variables: Array.from(this.variables.values())
|
|
4410
|
+
};
|
|
4411
|
+
}
|
|
4412
|
+
/**
|
|
4413
|
+
* 导入配置
|
|
4414
|
+
*/
|
|
4415
|
+
importConfig(config) {
|
|
4416
|
+
this.variables.clear();
|
|
4417
|
+
for (const variable of config.variables) {
|
|
4418
|
+
this.variables.set(variable.name, variable);
|
|
4419
|
+
}
|
|
4420
|
+
}
|
|
4421
|
+
/**
|
|
4422
|
+
* 序列化为 JSON
|
|
4423
|
+
*/
|
|
4424
|
+
toJSON() {
|
|
4425
|
+
return JSON.stringify(this.exportConfig(), null, 2);
|
|
4426
|
+
}
|
|
4427
|
+
/**
|
|
4428
|
+
* 从 JSON 反序列化
|
|
4429
|
+
*/
|
|
4430
|
+
static fromJSON(json) {
|
|
4431
|
+
return JSON.parse(json);
|
|
4432
|
+
}
|
|
4433
|
+
};
|
|
4434
|
+
__name(_GlobalBlackboardService, "GlobalBlackboardService");
|
|
4435
|
+
var GlobalBlackboardService = _GlobalBlackboardService;
|
|
4436
|
+
|
|
4437
|
+
// src/Blackboard/BlackboardTypes.ts
|
|
4438
|
+
var BlackboardTypes = {
|
|
4439
|
+
["string"]: {
|
|
4440
|
+
type: "string",
|
|
4441
|
+
displayName: "\u5B57\u7B26\u4E32",
|
|
4442
|
+
category: "basic",
|
|
4443
|
+
defaultValue: "",
|
|
4444
|
+
validator: /* @__PURE__ */ __name((v) => typeof v === "string", "validator")
|
|
4445
|
+
},
|
|
4446
|
+
["number"]: {
|
|
4447
|
+
type: "number",
|
|
4448
|
+
displayName: "\u6570\u5B57",
|
|
4449
|
+
category: "basic",
|
|
4450
|
+
defaultValue: 0,
|
|
4451
|
+
validator: /* @__PURE__ */ __name((v) => typeof v === "number", "validator")
|
|
4452
|
+
},
|
|
4453
|
+
["boolean"]: {
|
|
4454
|
+
type: "boolean",
|
|
4455
|
+
displayName: "\u5E03\u5C14\u503C",
|
|
4456
|
+
category: "basic",
|
|
4457
|
+
defaultValue: false,
|
|
4458
|
+
validator: /* @__PURE__ */ __name((v) => typeof v === "boolean", "validator")
|
|
4459
|
+
},
|
|
4460
|
+
["vector2"]: {
|
|
4461
|
+
type: "vector2",
|
|
4462
|
+
displayName: "\u4E8C\u7EF4\u5411\u91CF",
|
|
4463
|
+
category: "math",
|
|
4464
|
+
defaultValue: {
|
|
4465
|
+
x: 0,
|
|
4466
|
+
y: 0
|
|
4467
|
+
},
|
|
4468
|
+
editorComponent: "Vector2Editor",
|
|
4469
|
+
validator: /* @__PURE__ */ __name((v) => v && typeof v.x === "number" && typeof v.y === "number", "validator")
|
|
4470
|
+
},
|
|
4471
|
+
["vector3"]: {
|
|
4472
|
+
type: "vector3",
|
|
4473
|
+
displayName: "\u4E09\u7EF4\u5411\u91CF",
|
|
4474
|
+
category: "math",
|
|
4475
|
+
defaultValue: {
|
|
4476
|
+
x: 0,
|
|
4477
|
+
y: 0,
|
|
4478
|
+
z: 0
|
|
4479
|
+
},
|
|
4480
|
+
editorComponent: "Vector3Editor",
|
|
4481
|
+
validator: /* @__PURE__ */ __name((v) => v && typeof v.x === "number" && typeof v.y === "number" && typeof v.z === "number", "validator")
|
|
4482
|
+
},
|
|
4483
|
+
["color"]: {
|
|
4484
|
+
type: "color",
|
|
4485
|
+
displayName: "\u989C\u8272",
|
|
4486
|
+
category: "math",
|
|
4487
|
+
defaultValue: {
|
|
4488
|
+
r: 1,
|
|
4489
|
+
g: 1,
|
|
4490
|
+
b: 1,
|
|
4491
|
+
a: 1
|
|
4492
|
+
},
|
|
4493
|
+
editorComponent: "ColorEditor",
|
|
4494
|
+
validator: /* @__PURE__ */ __name((v) => v && typeof v.r === "number" && typeof v.g === "number" && typeof v.b === "number" && typeof v.a === "number", "validator")
|
|
4495
|
+
},
|
|
4496
|
+
["gameObject"]: {
|
|
4497
|
+
type: "gameObject",
|
|
4498
|
+
displayName: "\u6E38\u620F\u5BF9\u8C61",
|
|
4499
|
+
category: "reference",
|
|
4500
|
+
defaultValue: null,
|
|
4501
|
+
editorComponent: "GameObjectPicker"
|
|
4502
|
+
},
|
|
4503
|
+
["transform"]: {
|
|
4504
|
+
type: "transform",
|
|
4505
|
+
displayName: "\u53D8\u6362\u7EC4\u4EF6",
|
|
4506
|
+
category: "reference",
|
|
4507
|
+
defaultValue: null,
|
|
4508
|
+
editorComponent: "ComponentPicker"
|
|
4509
|
+
},
|
|
4510
|
+
["assetReference"]: {
|
|
4511
|
+
type: "assetReference",
|
|
4512
|
+
displayName: "\u8D44\u6E90\u5F15\u7528",
|
|
4513
|
+
category: "reference",
|
|
4514
|
+
defaultValue: null,
|
|
4515
|
+
editorComponent: "AssetPicker"
|
|
4516
|
+
},
|
|
4517
|
+
["entityId"]: {
|
|
4518
|
+
type: "entityId",
|
|
4519
|
+
displayName: "\u5B9E\u4F53ID",
|
|
4520
|
+
category: "game",
|
|
4521
|
+
defaultValue: -1,
|
|
4522
|
+
validator: /* @__PURE__ */ __name((v) => typeof v === "number" && v >= -1, "validator")
|
|
4523
|
+
},
|
|
4524
|
+
["resourcePath"]: {
|
|
4525
|
+
type: "resourcePath",
|
|
4526
|
+
displayName: "\u8D44\u6E90\u8DEF\u5F84",
|
|
4527
|
+
category: "game",
|
|
4528
|
+
defaultValue: "",
|
|
4529
|
+
editorComponent: "AssetPathPicker"
|
|
4530
|
+
},
|
|
4531
|
+
["array"]: {
|
|
4532
|
+
type: "array",
|
|
4533
|
+
displayName: "\u6570\u7EC4",
|
|
4534
|
+
category: "collection",
|
|
4535
|
+
defaultValue: [],
|
|
4536
|
+
editorComponent: "ArrayEditor"
|
|
4537
|
+
},
|
|
4538
|
+
["map"]: {
|
|
4539
|
+
type: "map",
|
|
4540
|
+
displayName: "\u6620\u5C04\u8868",
|
|
4541
|
+
category: "collection",
|
|
4542
|
+
defaultValue: {},
|
|
4543
|
+
editorComponent: "MapEditor"
|
|
4544
|
+
},
|
|
4545
|
+
["enum"]: {
|
|
4546
|
+
type: "enum",
|
|
4547
|
+
displayName: "\u679A\u4E3E",
|
|
4548
|
+
category: "advanced",
|
|
4549
|
+
defaultValue: "",
|
|
4550
|
+
editorComponent: "EnumPicker"
|
|
4551
|
+
},
|
|
4552
|
+
["animationState"]: {
|
|
4553
|
+
type: "animationState",
|
|
4554
|
+
displayName: "\u52A8\u753B\u72B6\u6001",
|
|
4555
|
+
category: "game",
|
|
4556
|
+
defaultValue: "",
|
|
4557
|
+
editorComponent: "AnimationStatePicker"
|
|
4558
|
+
},
|
|
4559
|
+
["audioClip"]: {
|
|
4560
|
+
type: "audioClip",
|
|
4561
|
+
displayName: "\u97F3\u9891\u7247\u6BB5",
|
|
4562
|
+
category: "game",
|
|
4563
|
+
defaultValue: null,
|
|
4564
|
+
editorComponent: "AudioClipPicker"
|
|
4565
|
+
},
|
|
4566
|
+
["material"]: {
|
|
4567
|
+
type: "material",
|
|
4568
|
+
displayName: "\u6750\u8D28",
|
|
4569
|
+
category: "game",
|
|
4570
|
+
defaultValue: null,
|
|
4571
|
+
editorComponent: "MaterialPicker"
|
|
4572
|
+
},
|
|
4573
|
+
["texture"]: {
|
|
4574
|
+
type: "texture",
|
|
4575
|
+
displayName: "\u7EB9\u7406",
|
|
4576
|
+
category: "game",
|
|
4577
|
+
defaultValue: null,
|
|
4578
|
+
editorComponent: "TexturePicker"
|
|
4579
|
+
},
|
|
4580
|
+
["vector4"]: {
|
|
4581
|
+
type: "vector4",
|
|
4582
|
+
displayName: "\u56DB\u7EF4\u5411\u91CF",
|
|
4583
|
+
category: "math",
|
|
4584
|
+
defaultValue: {
|
|
4585
|
+
x: 0,
|
|
4586
|
+
y: 0,
|
|
4587
|
+
z: 0,
|
|
4588
|
+
w: 0
|
|
4589
|
+
},
|
|
4590
|
+
editorComponent: "Vector4Editor"
|
|
4591
|
+
},
|
|
4592
|
+
["quaternion"]: {
|
|
4593
|
+
type: "quaternion",
|
|
4594
|
+
displayName: "\u56DB\u5143\u6570",
|
|
4595
|
+
category: "math",
|
|
4596
|
+
defaultValue: {
|
|
4597
|
+
x: 0,
|
|
4598
|
+
y: 0,
|
|
4599
|
+
z: 0,
|
|
4600
|
+
w: 1
|
|
4601
|
+
},
|
|
4602
|
+
editorComponent: "QuaternionEditor"
|
|
4603
|
+
},
|
|
4604
|
+
["component"]: {
|
|
4605
|
+
type: "component",
|
|
4606
|
+
displayName: "\u7EC4\u4EF6",
|
|
4607
|
+
category: "reference",
|
|
4608
|
+
defaultValue: null,
|
|
4609
|
+
editorComponent: "ComponentPicker"
|
|
4610
|
+
},
|
|
4611
|
+
["struct"]: {
|
|
4612
|
+
type: "struct",
|
|
4613
|
+
displayName: "\u7ED3\u6784\u4F53",
|
|
4614
|
+
category: "advanced",
|
|
4615
|
+
defaultValue: {},
|
|
4616
|
+
editorComponent: "StructEditor"
|
|
4617
|
+
},
|
|
4618
|
+
["function"]: {
|
|
4619
|
+
type: "function",
|
|
4620
|
+
displayName: "\u51FD\u6570",
|
|
4621
|
+
category: "advanced",
|
|
4622
|
+
defaultValue: null,
|
|
4623
|
+
editorComponent: "FunctionPicker"
|
|
4624
|
+
},
|
|
4625
|
+
["nodePath"]: {
|
|
4626
|
+
type: "nodePath",
|
|
4627
|
+
displayName: "\u8282\u70B9\u8DEF\u5F84",
|
|
4628
|
+
category: "game",
|
|
4629
|
+
defaultValue: "",
|
|
4630
|
+
editorComponent: "NodePathPicker"
|
|
4631
|
+
}
|
|
4632
|
+
};
|
|
4633
|
+
|
|
4634
|
+
// src/tokens.ts
|
|
4635
|
+
import { createServiceToken } from "@esengine/ecs-framework";
|
|
4636
|
+
var BehaviorTreeSystemToken = createServiceToken("behaviorTreeSystem");
|
|
4637
|
+
export {
|
|
4638
|
+
AbortType,
|
|
4639
|
+
AlwaysFailExecutor,
|
|
4640
|
+
AlwaysSucceedExecutor,
|
|
4641
|
+
BehaviorTreeAssetManager,
|
|
4642
|
+
BehaviorTreeAssetSerializer,
|
|
4643
|
+
BehaviorTreeAssetType,
|
|
4644
|
+
BehaviorTreeAssetValidator,
|
|
4645
|
+
BehaviorTreeBuilder,
|
|
4646
|
+
BehaviorTreeExecutionSystem,
|
|
4647
|
+
BehaviorTreeRuntimeComponent,
|
|
4648
|
+
BehaviorTreeStarter,
|
|
4649
|
+
BehaviorTreeSystemToken,
|
|
4650
|
+
BindingHelper,
|
|
4651
|
+
BlackboardCompare,
|
|
4652
|
+
BlackboardExists,
|
|
4653
|
+
BlackboardTypes,
|
|
4654
|
+
BlackboardValueType,
|
|
4655
|
+
CompositeType,
|
|
4656
|
+
ConditionalExecutor,
|
|
4657
|
+
CooldownExecutor,
|
|
4658
|
+
DecoratorType,
|
|
4659
|
+
EditorFormatConverter,
|
|
4660
|
+
EditorToBehaviorTreeDataConverter,
|
|
4661
|
+
ExecuteAction,
|
|
4662
|
+
ExecuteCondition,
|
|
4663
|
+
GlobalBlackboardService,
|
|
4664
|
+
InverterExecutor,
|
|
4665
|
+
LogAction,
|
|
4666
|
+
ModifyBlackboardValue,
|
|
4667
|
+
NodeExecutorRegistry,
|
|
4668
|
+
NodeMetadataRegistry,
|
|
4669
|
+
NodePropertyType,
|
|
4670
|
+
NodeTemplates,
|
|
4671
|
+
NodeType,
|
|
4672
|
+
ParallelExecutor,
|
|
4673
|
+
ParallelSelectorExecutor,
|
|
4674
|
+
RandomProbability,
|
|
4675
|
+
RandomSelectorExecutor,
|
|
4676
|
+
RandomSequenceExecutor,
|
|
4677
|
+
RepeaterExecutor,
|
|
4678
|
+
RootExecutor,
|
|
4679
|
+
SelectorExecutor,
|
|
4680
|
+
SequenceExecutor,
|
|
4681
|
+
ServiceDecorator,
|
|
4682
|
+
ServiceRegistry,
|
|
4683
|
+
SetBlackboardValue,
|
|
4684
|
+
SubTreeExecutor,
|
|
4685
|
+
TaskStatus,
|
|
4686
|
+
TimeoutExecutor,
|
|
4687
|
+
UntilFailExecutor,
|
|
4688
|
+
UntilSuccessExecutor,
|
|
4689
|
+
WaitAction,
|
|
4690
|
+
createDefaultRuntimeState
|
|
4691
|
+
};
|
|
4692
|
+
//# sourceMappingURL=index.js.map
|