use 'readTree' to parse data file
This commit is contained in:
1 parent
7478e1fa0f
commit
4d1d09fe80
12 files changed
+60
-30
No files matched your search
@@ -103,6 +103,7 @@
|
|||||||
"node.editSubtreeDenied": "Unable to edit the subtree node",
|
"node.editSubtreeDenied": "Unable to edit the subtree node",
|
||||||
"node.id": "Node id",
|
"node.id": "Node id",
|
||||||
"node.inputVariable": "Input variables",
|
"node.inputVariable": "Input variables",
|
||||||
|
"node.invalidChildren": "Invalid number of children",
|
||||||
"node.invalidGroup": "Node group '{{group}}' is not enabled",
|
"node.invalidGroup": "Node group '{{group}}' is not enabled",
|
||||||
"node.invalidValue": "Invalid value",
|
"node.invalidValue": "Invalid value",
|
||||||
"node.invalidVariableName": "Invalid variable name, should start with a letter or underscore",
|
"node.invalidVariableName": "Invalid variable name, should start with a letter or underscore",
|
||||||
|
|||||||
@@ -102,6 +102,7 @@
|
|||||||
"node.disabled": "禁用",
|
"node.disabled": "禁用",
|
||||||
"node.editSubtreeDenied": "不能编辑子树节点",
|
"node.editSubtreeDenied": "不能编辑子树节点",
|
||||||
"node.id": "节点标识",
|
"node.id": "节点标识",
|
||||||
|
"node.invalidChildren": "子节点数量不合法",
|
||||||
"node.inputVariable": "输入变量",
|
"node.inputVariable": "输入变量",
|
||||||
"node.invalidGroup": "节点分组 “{{group}}” 未启用",
|
"node.invalidGroup": "节点分组 “{{group}}” 未启用",
|
||||||
"node.invalidValue": "无效的值",
|
"node.invalidValue": "无效的值",
|
||||||
|
|||||||
@@ -28,6 +28,7 @@
|
|||||||
"name": "Clear",
|
"name": "Clear",
|
||||||
"type": "Action",
|
"type": "Action",
|
||||||
"desc": "清除变量",
|
"desc": "清除变量",
|
||||||
|
"children": 0,
|
||||||
"output": [
|
"output": [
|
||||||
"清除的变量名"
|
"清除的变量名"
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -61,6 +61,19 @@
|
|||||||
"input": [
|
"input": [
|
||||||
"target"
|
"target"
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 8,
|
||||||
|
"name": "Clear",
|
||||||
|
"output": [
|
||||||
|
"test"
|
||||||
|
],
|
||||||
|
"children": [
|
||||||
|
{
|
||||||
|
"id": 9,
|
||||||
|
"name": "Idle"
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,18 +4,15 @@
|
|||||||
"id": 1,
|
"id": 1,
|
||||||
"name": "Sequence",
|
"name": "Sequence",
|
||||||
"desc": "怪物测试AI",
|
"desc": "怪物测试AI",
|
||||||
"args": {},
|
|
||||||
"children": [
|
"children": [
|
||||||
{
|
{
|
||||||
"id": 2,
|
"id": 2,
|
||||||
"name": "Sequence",
|
"name": "Sequence",
|
||||||
"desc": "攻击",
|
"desc": "攻击",
|
||||||
"args": {},
|
|
||||||
"children": [
|
"children": [
|
||||||
{
|
{
|
||||||
"id": 3,
|
"id": 3,
|
||||||
"name": "GetHp",
|
"name": "GetHp",
|
||||||
"args": {},
|
|
||||||
"output": [
|
"output": [
|
||||||
"hp"
|
"hp"
|
||||||
],
|
],
|
||||||
@@ -60,10 +57,14 @@
|
|||||||
"name": "Log",
|
"name": "Log",
|
||||||
"desc": "逃跑",
|
"desc": "逃跑",
|
||||||
"args": {
|
"args": {
|
||||||
"str": "Run!"
|
"message": "Run!"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"desc": "怪物测试AI"
|
"desc": "怪物测试AI",
|
||||||
|
"firstid": 1,
|
||||||
|
"group": [],
|
||||||
|
"import": [],
|
||||||
|
"declvar": []
|
||||||
}
|
}
|
||||||
@@ -9,7 +9,7 @@
|
|||||||
"id": 2,
|
"id": 2,
|
||||||
"name": "Log",
|
"name": "Log",
|
||||||
"args": {
|
"args": {
|
||||||
"str": "hello"
|
"message": "hello"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -21,5 +21,9 @@
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"desc": "子树1"
|
"desc": "子树1",
|
||||||
|
"firstid": 1,
|
||||||
|
"group": [],
|
||||||
|
"import": [],
|
||||||
|
"declvar": []
|
||||||
}
|
}
|
||||||
@@ -568,7 +568,7 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
|
|||||||
workspace.onEditingNode({
|
workspace.onEditingNode({
|
||||||
data: b3util.createNode(data, false),
|
data: b3util.createNode(data, false),
|
||||||
editable: !isSubtreeNode(data),
|
editable: !isSubtreeNode(data),
|
||||||
limit_error: !b3util.checkChildrenLimit(data),
|
limitError: !b3util.checkChildrenLimit(data),
|
||||||
});
|
});
|
||||||
setItemState(editor.selectedId, "selected", true);
|
setItemState(editor.selectedId, "selected", true);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -775,11 +775,21 @@ const NodeInspector: FC = () => {
|
|||||||
>
|
>
|
||||||
<Input disabled={true} />
|
<Input disabled={true} />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
<Form.Item name="children" label={t("node.children")}>
|
<Form.Item
|
||||||
<Input
|
name="children"
|
||||||
style={{ borderColor: editingNode.limit_error ? "red" : undefined }}
|
label={t("node.children")}
|
||||||
disabled={true}
|
rules={[
|
||||||
/>
|
{
|
||||||
|
validator() {
|
||||||
|
if (editingNode.limitError) {
|
||||||
|
return Promise.reject(new Error(t("node.invalidChildren")));
|
||||||
|
}
|
||||||
|
return Promise.resolve();
|
||||||
|
},
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
>
|
||||||
|
<Input disabled={true} />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
<Form.Item label={t("node.name")} name="name">
|
<Form.Item label={t("node.name")} name="name">
|
||||||
<AutoComplete
|
<AutoComplete
|
||||||
|
|||||||
@@ -151,14 +151,14 @@ G6.registerNode(
|
|||||||
(data.path && !data.children?.length) ||
|
(data.path && !data.children?.length) ||
|
||||||
!checkTreeData(data) ||
|
!checkTreeData(data) ||
|
||||||
(nodeDef.group && !usingGroups[nodeDef.group]) ||
|
(nodeDef.group && !usingGroups[nodeDef.group]) ||
|
||||||
(usingVars && data.input?.some((v) => !usingVars![v])) ||
|
|
||||||
(usingVars && data.output?.some((v) => !usingVars![v])) ||
|
|
||||||
(usingVars &&
|
(usingVars &&
|
||||||
nodeDef.args?.some(
|
(data.input?.some((v) => usingVars?.[v] === undefined) ||
|
||||||
(v) =>
|
data.output?.some((v) => usingVars?.[v] === undefined) ||
|
||||||
isExprType(v.type) &&
|
nodeDef.args?.some(
|
||||||
parseExpr(data.args?.[v.name] ?? "").some((vv) => !usingVars![vv])
|
(v) =>
|
||||||
))
|
isExprType(v.type) &&
|
||||||
|
parseExpr(data.args?.[v.name] ?? "").some((vv) => usingVars?.[vv] === undefined)
|
||||||
|
)))
|
||||||
) {
|
) {
|
||||||
classify = "Error";
|
classify = "Error";
|
||||||
color = NODE_COLORS[classify];
|
color = NODE_COLORS[classify];
|
||||||
|
|||||||
@@ -74,10 +74,6 @@ export class EditorStore {
|
|||||||
this.path = path;
|
this.path = path;
|
||||||
this.data = readTree(path);
|
this.data = readTree(path);
|
||||||
this.data.name = Path.basenameWithoutExt(path);
|
this.data.name = Path.basenameWithoutExt(path);
|
||||||
this.data.firstid = this.data.firstid ?? 1;
|
|
||||||
this.data.group = this.data.group ?? [];
|
|
||||||
this.data.import = this.data.import ?? [];
|
|
||||||
this.data.declvar = this.data.declvar ?? [];
|
|
||||||
this.root = b3util.createTreeData(this.data.root);
|
this.root = b3util.createTreeData(this.data.root);
|
||||||
this.modifiedTime = fs.statSync(path).mtimeMs;
|
this.modifiedTime = fs.statSync(path).mtimeMs;
|
||||||
this.import = this.data.import.map((v) => ({ path: v, vars: [] }));
|
this.import = this.data.import.map((v) => ({ path: v, vars: [] }));
|
||||||
@@ -102,7 +98,7 @@ export type FileTreeType = {
|
|||||||
export type EditNode = {
|
export type EditNode = {
|
||||||
data: NodeModel;
|
data: NodeModel;
|
||||||
editable: boolean;
|
editable: boolean;
|
||||||
limit_error?: boolean;
|
limitError?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type EditNodeDef = {
|
export type EditNodeDef = {
|
||||||
@@ -380,8 +376,7 @@ export const useWorkspace = create<WorkspaceStore>((set, get) => ({
|
|||||||
const str = fs.readFileSync(scriptPath, "utf8");
|
const str = fs.readFileSync(scriptPath, "utf8");
|
||||||
const batch = eval(str) as BatchScript;
|
const batch = eval(str) as BatchScript;
|
||||||
workspace.allFiles.forEach((file) => {
|
workspace.allFiles.forEach((file) => {
|
||||||
const treeStr = fs.readFileSync(file.path, "utf8");
|
let tree: TreeModel | undefined = readTree(file.path);
|
||||||
let tree: TreeModel | undefined = JSON.parse(treeStr);
|
|
||||||
if (batch.processTree && tree) {
|
if (batch.processTree && tree) {
|
||||||
tree = batch.processTree(tree, file.path);
|
tree = batch.processTree(tree, file.path);
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-2
@@ -652,8 +652,7 @@ export const createTreeData = (
|
|||||||
|
|
||||||
export const createBuildData = (path: string) => {
|
export const createBuildData = (path: string) => {
|
||||||
try {
|
try {
|
||||||
const str = fs.readFileSync(path, "utf8");
|
const treeModel: TreeModel = readTree(path);
|
||||||
const treeModel: TreeModel = JSON.parse(str);
|
|
||||||
const data = createTreeData(treeModel.root);
|
const data = createTreeData(treeModel.root);
|
||||||
refreshTreeDataId(data, treeModel.firstid ?? 1);
|
refreshTreeDataId(data, treeModel.firstid ?? 1);
|
||||||
treeModel.name = Path.basenameWithoutExt(path);
|
treeModel.name = Path.basenameWithoutExt(path);
|
||||||
|
|||||||
+6
-1
@@ -8,7 +8,12 @@ export const readJson = (path: string) => {
|
|||||||
|
|
||||||
export const readTree = (path: string) => {
|
export const readTree = (path: string) => {
|
||||||
const str = fs.readFileSync(path, "utf-8");
|
const str = fs.readFileSync(path, "utf-8");
|
||||||
return JSON.parse(str) as TreeModel;
|
const data = JSON.parse(str) as TreeModel;
|
||||||
|
data.firstid = data.firstid ?? 1;
|
||||||
|
data.group = data.group || [];
|
||||||
|
data.import = data.import || [];
|
||||||
|
data.declvar = data.declvar || [];
|
||||||
|
return data;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const writeJson = (path: string, data: any) => {
|
export const writeJson = (path: string, data: any) => {
|
||||||
|
|||||||
Reference in new issue
Block a user