diff --git a/dist/panels/default/index.js b/dist/panels/default/index.js index faac742..1df164a 100644 --- a/dist/panels/default/index.js +++ b/dist/panels/default/index.js @@ -345,6 +345,9 @@ const component = lib_1.Vue.extend({ this.assets = assets.map(({ name, source, file }) => ({ name, url: source, file: file, content: "" })); }, async initSelection() { + // 切换节点时清空全局数据 + selectedBoxes = []; + SAVE_DEBOUNCE_TIMER = null; // 找到当前选中的节点 const node = await Editor.Message.request("scene", "query-node", Editor.Selection.getSelected("node")); // 未选中节点或者选中的是场景节点(场景节点不能添加组件) diff --git a/dist/runtime/node/composite/RandomSelector.js b/dist/runtime/node/composite/RandomSelector.js new file mode 100644 index 0000000..8f839c4 --- /dev/null +++ b/dist/runtime/node/composite/RandomSelector.js @@ -0,0 +1,47 @@ +"use strict"; +var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { + var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); + 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; + return c > 3 && r && Object.defineProperty(target, key, r), r; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const index_1 = require("../index"); +const decorator_1 = require("../../core/decorator"); +let RandomSelector = class RandomSelector extends index_1.Composite { + constructor() { + super(...arguments); + this.executionOrder = []; + } + get index() { + return this.executionOrder[this.executionOrder.length - 1]; + } + onStart() { + super.onStart(); + this.shuffle(); + } + canExecute() { + return Boolean(this.executionOrder.length) && this.status !== index_1.NodeStatus.Success; + } + onChildExecuted(status, _) { + this.executionOrder.pop(); + this.status = status; + } + onConditionalAbort() { + this.executionOrder = []; + this.status = index_1.NodeStatus.Inactive; + this.shuffle(); + } + shuffle() { + this.executionOrder = []; + const indexList = Array.from({ length: this.children.length }, (e, i) => i); + for (let i = indexList.length - 1; i >= 0; i--) { + const num = Math.floor(Math.random() * indexList.length); + this.executionOrder.push(indexList.splice(num, 1)[0]); + } + } +}; +RandomSelector = __decorate([ + (0, decorator_1.btclass)("RandomSelector") +], RandomSelector); +exports.default = RandomSelector; diff --git a/dist/runtime/node/composite/RandomSequence copy.js b/dist/runtime/node/composite/RandomSequence copy.js new file mode 100644 index 0000000..d49caed --- /dev/null +++ b/dist/runtime/node/composite/RandomSequence copy.js @@ -0,0 +1,64 @@ +"use strict"; +var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { + var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); + 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; + return c > 3 && r && Object.defineProperty(target, key, r), r; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const index_1 = require("../index"); +const decorator_1 = require("../../core/decorator"); +let RandomSequence = class RandomSequence extends index_1.Composite { + constructor() { + super(...arguments); + this.executionOrder = []; + } + get index() { + return this.executionOrder[this.executionOrder.length - 1]; + } + onStart() { + super.onStart(); + this.shuffle(); + } + canExecute() { + return Boolean(this.executionOrder.length) && this.status !== index_1.NodeStatus.Failure; + } + onChildExecuted(status, _) { + switch (status) { + case index_1.NodeStatus.Success: + this.executionOrder.pop(); + if (this.executionOrder.length <= 0) { + this.status = index_1.NodeStatus.Success; + } + else { + this.status = index_1.NodeStatus.Running; + } + break; + case index_1.NodeStatus.Failure: + this.status = index_1.NodeStatus.Failure; + break; + case index_1.NodeStatus.Running: + this.status = index_1.NodeStatus.Running; + break; + default: + break; + } + } + onConditionalAbort() { + this.executionOrder = []; + this.status = index_1.NodeStatus.Inactive; + this.shuffle(); + } + shuffle() { + this.executionOrder = []; + const indexList = Array.from({ length: this.children.length }, (e, i) => i); + for (let i = indexList.length - 1; i >= 0; i--) { + const num = Math.floor(Math.random() * indexList.length); + this.executionOrder.push(indexList.splice(num, 1)[0]); + } + } +}; +RandomSequence = __decorate([ + (0, decorator_1.btclass)("RandomSequence") +], RandomSequence); +exports.default = RandomSequence; diff --git a/dist/runtime/node/composite/RandomSequence.js b/dist/runtime/node/composite/RandomSequence.js index d49caed..74b655d 100644 --- a/dist/runtime/node/composite/RandomSequence.js +++ b/dist/runtime/node/composite/RandomSequence.js @@ -24,25 +24,8 @@ let RandomSequence = class RandomSequence extends index_1.Composite { return Boolean(this.executionOrder.length) && this.status !== index_1.NodeStatus.Failure; } onChildExecuted(status, _) { - switch (status) { - case index_1.NodeStatus.Success: - this.executionOrder.pop(); - if (this.executionOrder.length <= 0) { - this.status = index_1.NodeStatus.Success; - } - else { - this.status = index_1.NodeStatus.Running; - } - break; - case index_1.NodeStatus.Failure: - this.status = index_1.NodeStatus.Failure; - break; - case index_1.NodeStatus.Running: - this.status = index_1.NodeStatus.Running; - break; - default: - break; - } + this.executionOrder.pop(); + this.status = status; } onConditionalAbort() { this.executionOrder = []; diff --git a/dist/runtime/node/composite/Sequence.js b/dist/runtime/node/composite/Sequence.js index c66c9f4..5b4d34b 100644 --- a/dist/runtime/node/composite/Sequence.js +++ b/dist/runtime/node/composite/Sequence.js @@ -17,25 +17,8 @@ let Sequence = class Sequence extends index_1.Composite { return this.index < this.children.length && this.status !== index_1.NodeStatus.Failure; } onChildExecuted(status, _) { - switch (status) { - case index_1.NodeStatus.Success: - this.index++; - if (this.index >= this.children.length) { - this.status = index_1.NodeStatus.Success; - } - else { - this.status = index_1.NodeStatus.Running; - } - break; - case index_1.NodeStatus.Failure: - this.status = index_1.NodeStatus.Failure; - break; - case index_1.NodeStatus.Running: - this.status = index_1.NodeStatus.Running; - break; - default: - break; - } + this.index++; + this.status = status; } onConditionalAbort(index) { this.index = index; diff --git a/dist/runtime/node/composite/index.js b/dist/runtime/node/composite/index.js index 72eace0..ce04851 100644 --- a/dist/runtime/node/composite/index.js +++ b/dist/runtime/node/composite/index.js @@ -18,3 +18,4 @@ __exportStar(require("./Sequence"), exports); __exportStar(require("./Selector"), exports); __exportStar(require("./Parallel"), exports); __exportStar(require("./RandomSequence"), exports); +__exportStar(require("./RandomSelector"), exports); diff --git a/src/panels/default/index.ts b/src/panels/default/index.ts index cebe2a9..a70f922 100644 --- a/src/panels/default/index.ts +++ b/src/panels/default/index.ts @@ -377,6 +377,9 @@ const component = Vue.extend({ this.assets = assets.map(({ name, source, file }) => ({ name, url: source, file: file, content: "" })); }, async initSelection() { + // 切换节点时清空全局数据 + selectedBoxes = []; + SAVE_DEBOUNCE_TIMER = null; // 找到当前选中的节点 const node = await Editor.Message.request("scene", "query-node", Editor.Selection.getSelected("node")); diff --git a/src/panels/static/style/default/index.css b/src/panels/static/style/default/index.css index aeddbaf..c30ec7a 100644 --- a/src/panels/static/style/default/index.css +++ b/src/panels/static/style/default/index.css @@ -50,7 +50,7 @@ ui-prop[no-label] { overflow: auto; } -.fix-left { +.fix-left-top { position: absolute; left: 14px; top: 14px; @@ -58,21 +58,28 @@ ui-prop[no-label] { display: flex; } -.fix-right { +.fix-right-top { position: absolute; - right: 14px; + right: 20px; top: 14px; z-index: 1; display: flex; } -.fix-bottom { +.fix-left-bottom { position: absolute; left: 14px; bottom: 24px; z-index: 1; } +.fix-right-bottom { + position: absolute; + right: 20px; + bottom: 24px; + z-index: 1; +} + .fix-bottom ui-button { padding: 0 12px; } diff --git a/src/panels/static/template/vue/app.html b/src/panels/static/template/vue/app.html index f4d2378..d0548f1 100644 --- a/src/panels/static/template/vue/app.html +++ b/src/panels/static/template/vue/app.html @@ -4,23 +4,24 @@