123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- var t = require;
- var e = module;
- var i = exports;
- Object.defineProperty(i, "__esModule", {value: !0});
- const s = t("B3Functions"),
- l = t("constants"),
- r = t("Tick");
- i.default = class {
- constructor() {
- (this.id = s.createUUID()),
- (this.title = "The behavior tree"),
- (this.description = "Default description"),
- (this.properties = {}),
- (this.root = null),
- (this.debug = !1);
- }
- load(t, e = {}) {
- (e = e || {}),
- (this.title = t.title || this.title),
- (this.description = t.description || this.description),
- (this.properties = t.properties || this.properties);
- var i,
- s,
- o,
- a = {};
- for (i in t.nodes) {
- if (!((s = t.nodes[i]).name in e))
- throw new EvalError('BehaviorTree.load: Invalid node name + "' + s.name + '".');
- ((o = new e[s.name](s.properties)).id = s.id || o.id),
- (o.name = s.name),
- (o.title = s.title || o.title),
- (o.description = s.description || o.description),
- (o.properties = s.properties || o.properties),
- (a[i] = o);
- }
- for (i in t.nodes)
- if (((s = t.nodes[i]), (o = a[i]).category === l.COMPOSITE && s.children))
- for (var n = 0; n < s.children.length; n++) {
- var r = s.children[n];
- o.children.push(a[r]);
- }
- else o.category === l.DECORATOR && s.child && (o.child = a[s.child]);
- this.root = a[t.root];
- }
- dump() {}
- tick(t, e) {
- if (!e) throw "The blackboard parameter is obligatory and must be an instance of b3.Blackboard";
- const i = new r.default();
- (i.debug = this.debug), (i.target = t), (i.blackboard = e);
- const s = (i.tree = this).root._execute(i),
- o = e.get("openNodes", this.id),
- a = i._openNodes.slice(0);
- let n = Math.min(o.length, a.length);
- for (let t = 0; t < n; t++)
- if (o[t] !== a[t]) {
- n = t;
- break;
- }
- for (let t = o.length - 1; t >= n; t--)
- e.get("isOpen", this.id, o[t].id) && (o[t]._close(i), o[t].interrupt(i));
- return e.set("openNodes", a, this.id), e.set("nodeCount", i._nodeCount, this.id), s;
- }
- };
|