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