support multi group for node
This commit is contained in:
1 parent
9cdc4cee68
commit
7395935e6f
7 files changed
+58
-19
No files matched your search
@@ -357,7 +357,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "TestB3",
|
"name": "TestB3",
|
||||||
"type": "Action",
|
"type": "Action (Client|Server|Test)",
|
||||||
"args": [
|
"args": [
|
||||||
{
|
{
|
||||||
"name": "time",
|
"name": "time",
|
||||||
|
|||||||
@@ -3,8 +3,13 @@
|
|||||||
"desc": "",
|
"desc": "",
|
||||||
"firstid": 1,
|
"firstid": 1,
|
||||||
"export": true,
|
"export": true,
|
||||||
"group": ["Client"],
|
"group": [
|
||||||
"import": ["vars/declare-core.json", "vars/declare-vars.json"],
|
"Client"
|
||||||
|
],
|
||||||
|
"import": [
|
||||||
|
"vars/declare-core.json",
|
||||||
|
"vars/declare-vars.json"
|
||||||
|
],
|
||||||
"declvar": [
|
"declvar": [
|
||||||
{
|
{
|
||||||
"name": "target",
|
"name": "target",
|
||||||
@@ -28,12 +33,16 @@
|
|||||||
"id": 4,
|
"id": 4,
|
||||||
"name": "FindEnemy",
|
"name": "FindEnemy",
|
||||||
"args": {},
|
"args": {},
|
||||||
"output": ["target1"]
|
"output": [
|
||||||
|
"target1"
|
||||||
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": 5,
|
"id": 5,
|
||||||
"name": "Attack",
|
"name": "Attack",
|
||||||
"input": ["target1"]
|
"input": [
|
||||||
|
"target1"
|
||||||
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": 6,
|
"id": 6,
|
||||||
@@ -45,19 +54,46 @@
|
|||||||
{
|
{
|
||||||
"id": 7,
|
"id": 7,
|
||||||
"name": "MoveToTarget",
|
"name": "MoveToTarget",
|
||||||
"input": ["target"]
|
"input": [
|
||||||
|
"target"
|
||||||
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": 8,
|
"id": 8,
|
||||||
"name": "Clear",
|
"name": "Clear",
|
||||||
"output": ["test"],
|
"output": [
|
||||||
|
"test"
|
||||||
|
],
|
||||||
"children": [
|
"children": [
|
||||||
{
|
{
|
||||||
"id": 9,
|
"id": 9,
|
||||||
"name": "Idle"
|
"name": "Idle"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 10,
|
||||||
|
"name": "TestB3",
|
||||||
|
"args": {
|
||||||
|
"time": 1,
|
||||||
|
"open": true,
|
||||||
|
"check": "1",
|
||||||
|
"name": "1",
|
||||||
|
"status": "FAILURE"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 11,
|
||||||
|
"name": "TestB3",
|
||||||
|
"args": {
|
||||||
|
"time": 1,
|
||||||
|
"open": true,
|
||||||
|
"check": "1",
|
||||||
|
"name": "1",
|
||||||
|
"status": "RUNNING"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
},
|
||||||
|
"version": "1.8.0"
|
||||||
}
|
}
|
||||||
@@ -324,12 +324,14 @@ export const Explorer: FC = () => {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
workspace.nodeDefs.forEach((nodeDef) => {
|
workspace.nodeDefs.forEach((nodeDef) => {
|
||||||
let catalog = data.children?.find((nt) => nt.title === nodeDef.type);
|
(nodeDef.group || []).forEach((g, idx) => {
|
||||||
|
const typeGroup = !g ? nodeDef.type : nodeDef.type.replace(/\(([\w|]+)\)/, `(${g})`);
|
||||||
|
let catalog = data.children?.find((nt) => nt.title === typeGroup);
|
||||||
if (!catalog) {
|
if (!catalog) {
|
||||||
const type = getNodeType(nodeDef);
|
const type = getNodeType(nodeDef);
|
||||||
catalog = {
|
catalog = {
|
||||||
title: nodeDef.type,
|
title: typeGroup,
|
||||||
path: `nodeTree.catalog.${nodeDef.type}`,
|
path: `nodeTree.catalog.${typeGroup}`,
|
||||||
children: [],
|
children: [],
|
||||||
icon: (
|
icon: (
|
||||||
<Flex justify="center" align="center" style={{ height: "100%" }}>
|
<Flex justify="center" align="center" style={{ height: "100%" }}>
|
||||||
@@ -347,7 +349,7 @@ export const Explorer: FC = () => {
|
|||||||
title: `${nodeDef.name}(${nodeDef.desc})`,
|
title: `${nodeDef.name}(${nodeDef.desc})`,
|
||||||
isLeaf: true,
|
isLeaf: true,
|
||||||
def: nodeDef,
|
def: nodeDef,
|
||||||
path: `${nodeDef.name}`,
|
path: `${nodeDef.name} ${idx}`,
|
||||||
icon: nodeDef.icon ? (
|
icon: nodeDef.icon ? (
|
||||||
<Flex justify="center" align="center" style={{ height: "100%" }}>
|
<Flex justify="center" align="center" style={{ height: "100%" }}>
|
||||||
<img
|
<img
|
||||||
@@ -364,6 +366,7 @@ export const Explorer: FC = () => {
|
|||||||
),
|
),
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
});
|
||||||
data.children?.sort((a, b) => a.title.localeCompare(b.title));
|
data.children?.sort((a, b) => a.title.localeCompare(b.title));
|
||||||
data.children?.forEach((child) =>
|
data.children?.forEach((child) =>
|
||||||
child.children?.sort((a, b) => a.title.localeCompare(b.title))
|
child.children?.sort((a, b) => a.title.localeCompare(b.title))
|
||||||
|
|||||||
@@ -765,7 +765,7 @@ const NodeInspector: FC = () => {
|
|||||||
rules={[
|
rules={[
|
||||||
{
|
{
|
||||||
validator() {
|
validator() {
|
||||||
if (def.group && !usingGroups[def.group]) {
|
if (def.group && !def.group.some((g) => usingGroups[g])) {
|
||||||
return Promise.reject(new Error(t("node.invalidGroup", { group: def.group })));
|
return Promise.reject(new Error(t("node.invalidGroup", { group: def.group })));
|
||||||
}
|
}
|
||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
|
|||||||
@@ -150,7 +150,7 @@ G6.registerNode(
|
|||||||
!nodeDefs.has(data.name) ||
|
!nodeDefs.has(data.name) ||
|
||||||
(data.path && !data.children?.length) ||
|
(data.path && !data.children?.length) ||
|
||||||
!checkTreeData(data) ||
|
!checkTreeData(data) ||
|
||||||
(nodeDef.group && !usingGroups[nodeDef.group]) ||
|
(nodeDef.group && !nodeDef.group.some((g) => usingGroups[g])) ||
|
||||||
(usingVars &&
|
(usingVars &&
|
||||||
(data.input?.some((v) => v && usingVars?.[v] === undefined) ||
|
(data.input?.some((v) => v && usingVars?.[v] === undefined) ||
|
||||||
data.output?.some((v) => v && usingVars?.[v] === undefined) ||
|
data.output?.some((v) => v && usingVars?.[v] === undefined) ||
|
||||||
|
|||||||
+1
-1
@@ -3,7 +3,7 @@ import { NodeDef } from "../behavior3/src/behavior3";
|
|||||||
|
|
||||||
declare module "../behavior3/src/behavior3" {
|
declare module "../behavior3/src/behavior3" {
|
||||||
interface NodeDef {
|
interface NodeDef {
|
||||||
group?: string;
|
group?: string[];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+4
-4
@@ -52,10 +52,10 @@ export const initWorkdir = (path: string, handler: typeof alertError) => {
|
|||||||
for (const v of nodeDefData) {
|
for (const v of nodeDefData) {
|
||||||
nodeDefs.set(v.name, v);
|
nodeDefs.set(v.name, v);
|
||||||
|
|
||||||
const group = v.type.match(/\((\w+)\)/)?.[1];
|
const group = v.type.match(/\(([\w|]+)\)/)?.[1];
|
||||||
if (group) {
|
if (group) {
|
||||||
v.group = group;
|
v.group = group.split("|");
|
||||||
groups.add(group);
|
v.group.forEach((g) => groups.add(g));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
groupDefs = Array.from(groups).sort();
|
groupDefs = Array.from(groups).sort();
|
||||||
@@ -299,7 +299,7 @@ export const checkNodeData = (data: NodeModel | null | undefined) => {
|
|||||||
let hasError = false;
|
let hasError = false;
|
||||||
|
|
||||||
if (conf.group) {
|
if (conf.group) {
|
||||||
if (!usingGroups[conf.group]) {
|
if (!conf.group.some((g) => usingGroups[g])) {
|
||||||
error(data, `node group '${conf.group}' is not enabled`);
|
error(data, `node group '${conf.group}' is not enabled`);
|
||||||
hasError = true;
|
hasError = true;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user