From 3ff89550953477d16f9dcf80f62ab0690848e8f7 Mon Sep 17 00:00:00 2001 From: sli97 <775303361@qq.com> Date: Sun, 8 Oct 2023 01:23:11 +0800 Subject: [PATCH] save --- dist/panels/default/index.js | 3 + dist/runtime/node/composite/RandomSelector.js | 47 ++++++++++++++ .../node/composite/RandomSequence copy.js | 64 +++++++++++++++++++ dist/runtime/node/composite/RandomSequence.js | 21 +----- dist/runtime/node/composite/Sequence.js | 21 +----- dist/runtime/node/composite/index.js | 1 + src/panels/default/index.ts | 3 + src/panels/static/style/default/index.css | 15 +++-- src/panels/static/template/vue/app.html | 7 +- src/runtime/node/composite/RandomSelector.ts | 40 ++++++++++++ .../node/composite/RandomSelector.ts.meta | 9 +++ src/runtime/node/composite/RandomSequence.ts | 20 +----- src/runtime/node/composite/Sequence.ts | 20 +----- src/runtime/node/composite/index.ts | 1 + 14 files changed, 191 insertions(+), 81 deletions(-) create mode 100644 dist/runtime/node/composite/RandomSelector.js create mode 100644 dist/runtime/node/composite/RandomSequence copy.js create mode 100644 src/runtime/node/composite/RandomSelector.ts create mode 100644 src/runtime/node/composite/RandomSelector.ts.meta 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 @@
-
+
{{log.content}}
-
+
-
+
Root
+
Version 1.0.2
diff --git a/src/runtime/node/composite/RandomSelector.ts b/src/runtime/node/composite/RandomSelector.ts new file mode 100644 index 0000000..7890b11 --- /dev/null +++ b/src/runtime/node/composite/RandomSelector.ts @@ -0,0 +1,40 @@ +import { Composite, NodeStatus } from "../index"; +import { btclass } from "../../core/decorator"; + +@btclass("RandomSelector") +export default class RandomSelector extends Composite { + executionOrder: Array = []; + + get index() { + return this.executionOrder[this.executionOrder.length - 1]; + } + + onStart(): void { + super.onStart(); + this.shuffle(); + } + + canExecute(): boolean { + return Boolean(this.executionOrder.length) && this.status !== NodeStatus.Success; + } + + onChildExecuted(status: NodeStatus, _: number): void { + this.executionOrder.pop(); + this.status = status; + } + + onConditionalAbort() { + this.executionOrder = []; + this.status = 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]); + } + } +} diff --git a/src/runtime/node/composite/RandomSelector.ts.meta b/src/runtime/node/composite/RandomSelector.ts.meta new file mode 100644 index 0000000..c162d84 --- /dev/null +++ b/src/runtime/node/composite/RandomSelector.ts.meta @@ -0,0 +1,9 @@ +{ + "ver": "4.0.23", + "importer": "typescript", + "imported": true, + "uuid": "ff11c9ef-38fb-430b-96c6-398bea66af98", + "files": [], + "subMetas": {}, + "userData": {} +} diff --git a/src/runtime/node/composite/RandomSequence.ts b/src/runtime/node/composite/RandomSequence.ts index efcbaec..1fc63f2 100644 --- a/src/runtime/node/composite/RandomSequence.ts +++ b/src/runtime/node/composite/RandomSequence.ts @@ -19,24 +19,8 @@ export default class RandomSequence extends Composite { } onChildExecuted(status: NodeStatus, _: number): void { - switch (status) { - case NodeStatus.Success: - this.executionOrder.pop(); - if (this.executionOrder.length <= 0) { - this.status = NodeStatus.Success; - } else { - this.status = NodeStatus.Running; - } - break; - case NodeStatus.Failure: - this.status = NodeStatus.Failure; - break; - case NodeStatus.Running: - this.status = NodeStatus.Running; - break; - default: - break; - } + this.executionOrder.pop(); + this.status = status; } onConditionalAbort() { diff --git a/src/runtime/node/composite/Sequence.ts b/src/runtime/node/composite/Sequence.ts index 4eee7a3..d6ffa53 100644 --- a/src/runtime/node/composite/Sequence.ts +++ b/src/runtime/node/composite/Sequence.ts @@ -13,24 +13,8 @@ export default class Sequence extends Composite { } onChildExecuted(status: NodeStatus, _: number): void { - switch (status) { - case NodeStatus.Success: - this.index++; - if (this.index >= this.children.length) { - this.status = NodeStatus.Success; - } else { - this.status = NodeStatus.Running; - } - break; - case NodeStatus.Failure: - this.status = NodeStatus.Failure; - break; - case NodeStatus.Running: - this.status = NodeStatus.Running; - break; - default: - break; - } + this.index++; + this.status = status; } onConditionalAbort(index: number) { diff --git a/src/runtime/node/composite/index.ts b/src/runtime/node/composite/index.ts index 6530602..726e0a9 100644 --- a/src/runtime/node/composite/index.ts +++ b/src/runtime/node/composite/index.ts @@ -2,3 +2,4 @@ export * from "./Sequence"; export * from "./Selector"; export * from "./Parallel"; export * from "./RandomSequence"; +export * from "./RandomSelector";