diff --git a/README.md b/README.md index 565eff2..191bdaa 100644 --- a/README.md +++ b/README.md @@ -45,14 +45,10 @@ export interface NodeDef { | "json?" | "json[]" | "json[]?" - | "enum" - | "enum?" - | "enum[]" - | "enum[]?" - | "code" - | "code?" - | "code[]" - | "code[]?"; + | "expr" + | "expr?" + | "expr[]" + | "expr[]?"; desc: string; default?: unknown; /** Input `value`, only one is allowed between `value` and this arg.*/ diff --git a/package-lock.json b/package-lock.json index 7ea4244..7dd52f7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "behavior3editor", - "version": "1.8.0", + "version": "1.8.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "behavior3editor", - "version": "1.8.0", + "version": "1.8.1", "hasInstallScript": true, "license": "MIT", "dependencies": { diff --git a/package.json b/package.json index 84a669f..e55d631 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "behavior3editor", - "version": "1.8.0", + "version": "1.8.1", "main": "dist-electron/main/index.js", "description": "行为树编辑器", "author": "zhandouxiaojiji & codetypes", diff --git a/public/locales/en.json b/public/locales/en.json index 04717c9..32c934f 100644 --- a/public/locales/en.json +++ b/public/locales/en.json @@ -86,6 +86,7 @@ "tree.export": "Export", "tree.firstid": "First id", "tree.group": "Enable Node Grouping", + "tree.group.placeholder": "Select node groups", "tree.vars": "Define Variables", "tree.vars.name": "name", "tree.vars.invalidName": "Invalid variable name", diff --git a/public/locales/zh.json b/public/locales/zh.json index 0346d9f..fbbe256 100644 --- a/public/locales/zh.json +++ b/public/locales/zh.json @@ -86,6 +86,7 @@ "tree.export": "导出", "tree.firstid": "起始标识", "tree.group": "启用节点分组", + "tree.group.placeholder": "选择节点分组", "tree.vars": "定义变量", "tree.vars.name": "变量名", "tree.vars.invalidName": "变量名不合法", diff --git a/sample/node-config.b3-setting b/sample/node-config.b3-setting index 1fa1356..b6d24c2 100644 --- a/sample/node-config.b3-setting +++ b/sample/node-config.b3-setting @@ -66,7 +66,7 @@ "args": [ { "name": "builtin", - "type": "enum", + "type": "string", "desc": "事件", "options": [ { @@ -332,7 +332,10 @@ }, { "name": "MoveToPos", - "type": "Action (Client)", + "type": "Action", + "group": [ + "Client" + ], "args": [ { "name": "x", @@ -349,7 +352,10 @@ }, { "name": "MoveToTarget", - "type": "Action (Server)", + "type": "Action", + "group": [ + "Server" + ], "input": [ "{目标}" ], @@ -357,7 +363,12 @@ }, { "name": "TestB3", - "type": "Action (Client|Server|Test)", + "type": "Action", + "group": [ + "Client", + "Server", + "Test" + ], "args": [ { "name": "time", @@ -387,7 +398,7 @@ { "name": "status", "desc": "状态", - "type": "enum", + "type": "string", "options": [ { "name": "成功", diff --git a/sample/vars/test-vars.json b/sample/vars/test-vars.json index a2351c6..420a8a4 100644 --- a/sample/vars/test-vars.json +++ b/sample/vars/test-vars.json @@ -50,7 +50,7 @@ "id": 6, "name": "Check", "args": { - "value": "target[0].x > 0 |" + "value": "target[0].x > 0 " } }, { @@ -95,6 +95,13 @@ "output": [ "context" ] + }, + { + "id": 12, + "name": "Listen", + "args": { + "builtin": "afterRunFailure" + } } ] } diff --git a/sample/workdir/hero.json b/sample/workdir/hero.json index 8e6d037..0c59e66 100644 --- a/sample/workdir/hero.json +++ b/sample/workdir/hero.json @@ -1,16 +1,24 @@ { + "version": "1.8.0", "name": "hero", + "desc": "英雄测试AI", + "firstid": 1, + "export": true, + "group": [ + "Client", + "Server" + ], + "import": [], + "declvar": [], "root": { "id": 1, "name": "Selector", "desc": "英雄测试AI", - "args": {}, "children": [ { "id": 2, "name": "Sequence", "desc": "攻击", - "args": {}, "children": [ { "id": 3, @@ -28,7 +36,6 @@ { "id": 4, "name": "Attack", - "args": {}, "input": [ "enemy" ] @@ -46,7 +53,6 @@ "id": 6, "name": "Sequence", "desc": "移动", - "args": {}, "children": [ { "id": 7, @@ -64,7 +70,6 @@ { "id": 8, "name": "MoveToTarget", - "args": {}, "input": [ "enemy" ] @@ -75,12 +80,10 @@ "id": 9, "name": "Sequence", "desc": "逃跑", - "args": {}, "children": [ { "id": 10, "name": "GetHp", - "args": {}, "output": [ "hp" ] @@ -110,11 +113,5 @@ "name": "Idle" } ] - }, - "desc": "英雄测试AI", - "version": "1.8.0", - "firstid": 1, - "group": [], - "import": [], - "declvar": [] + } } \ No newline at end of file diff --git a/sample/workdir/monster.json b/sample/workdir/monster.json index 3225067..ed1fbe6 100644 --- a/sample/workdir/monster.json +++ b/sample/workdir/monster.json @@ -1,5 +1,14 @@ { + "version": "1.8.0", "name": "monster", + "desc": "怪物测试AI", + "firstid": 1, + "export": true, + "group": [ + "Test" + ], + "import": [], + "declvar": [], "root": { "id": 1, "name": "Sequence", @@ -26,26 +35,30 @@ ] }, { - "id": 7, + "id": 6, "name": "Cmp", "args": { - "gt": 50, - "value": "hp" + "value": "hp", + "gt": 50 }, "input": [ - "" + "hp" ] }, { - "id": 8, + "id": 7, "name": "TestB3", "desc": "攻击", "args": { - "str": "Attack!" + "time": 1, + "open": true, + "check": "1", + "name": "1", + "status": "FAILURE" } }, { - "id": 9, + "id": 8, "name": "Sequence", "desc": "新建行为树", "path": "workdir/subtree1.json" @@ -53,7 +66,7 @@ ] }, { - "id": 12, + "id": 11, "name": "Log", "desc": "逃跑", "args": { @@ -61,10 +74,5 @@ } } ] - }, - "desc": "怪物测试AI", - "firstid": 1, - "group": [], - "import": [], - "declvar": [] + } } \ No newline at end of file diff --git a/src/behavior3 b/src/behavior3 index d6e3f08..b3e20e8 160000 --- a/src/behavior3 +++ b/src/behavior3 @@ -1 +1 @@ -Subproject commit d6e3f089504ae999030cb439fbb023d900705d53 +Subproject commit b3e20e85785aed1b1b5762e08c94056101e0cd35 diff --git a/src/components/inspector.tsx b/src/components/inspector.tsx index 57e5925..bef5bc1 100644 --- a/src/components/inspector.tsx +++ b/src/components/inspector.tsx @@ -8,7 +8,6 @@ import { import { AutoComplete, Button, - Checkbox, Divider, Flex, Form, @@ -29,9 +28,9 @@ import { useShallow } from "zustand/react/shallow"; import { ExpressionEvaluator } from "../behavior3/src/behavior3"; import { EditNode, EditTree, useWorkspace } from "../contexts/workspace-context"; import { + hasArgOptions, ImportDef, isBoolType, - isEnumType, isExprType, isFloatType, isIntType, @@ -141,49 +140,6 @@ const VarDefItem: FC = ({ name, onChange, onRemove, disabled, ...p ); }; -interface GroupDefItemProps { - disabled?: boolean; - value?: string[]; - onChange?: (value: string[]) => void; -} - -const GroupDefItem: FC = ({ disabled, onChange, ...props }) => { - const [value, setValue] = useState(props.value ?? []); - const form = useFormInstance(); - const workspace = useWorkspace( - useShallow((state) => ({ - groupDefs: state.groupDefs, - })) - ); - return ( - - {workspace.groupDefs.map((g) => ( - { - const arr = e.target.checked ? [...value, g] : value.filter((v) => v !== g); - setValue(arr); - onChange?.(arr); - form.submit(); - }} - > - {g} - - ))} - - ); -}; - const TreeInspector: FC = () => { const workspace = useWorkspace( useShallow((state) => ({ @@ -360,6 +316,7 @@ const TreeInspector: FC = () => { mode="multiple" suffixIcon={null} onChange={form.submit} + placeholder={t("tree.group.placeholder")} options={workspace.groupDefs.map((g) => ({ label: g, value: g }))} /> @@ -1160,29 +1117,29 @@ const NodeInspector: FC = () => { }), ]} > - {isStringType(type) && ( + {!hasArgOptions(arg) && isStringType(type) && (