fix copy & paste node

This commit is contained in:
zhandouxiaojiji committed 2020-11-27 17:17:11 +08:00
1 parent 7321592a12
commit 8564fc1ebe
3 files changed
+36 -10

No files matched your search

+27 -3
View File
@@ -5,11 +5,35 @@ import { remote } from "electron";
import * as path from "path";
export const cloneNodeData = (nodeData: GraphNodeModel) => {
const newData: GraphNodeModel = {
id: nodeData.id + "new",
const newData: BehaviorNodeModel = {
id: Number(nodeData.id),
name: nodeData.name,
conf: nodeData.conf,
};
if(nodeData.input) {
newData.input = [];
for(let v of nodeData.input){
newData.input.push(v || "");
}
}
if(nodeData.output) {
newData.output = [];
for(let v of nodeData.output){
newData.output.push(v || "");
}
}
if(nodeData.args) {
newData.args = {};
for(let k in nodeData.args) {
let v = nodeData.args[k];
newData.args[k] = v;
}
}
if(nodeData.children) {
newData.children = []
for(let child of nodeData.children) {
newData.children.push(cloneNodeData(child));
}
}
return newData;
};
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "behavior3editor",
"version": "0.1.1",
"version": "0.1.2",
"description": "行为树编辑器",
"main": "./dist/main.js",
"scripts": {
+8 -6
View File
@@ -350,8 +350,8 @@ export default class Editor extends React.Component<EditorProps, EditorState> {
if (!curNodeId) {
return;
}
const data = this.graph.findDataById(curNodeId);
clipboard.writeText(JSON.stringify(data, null, 2));
const data = this.graph.findDataById(curNodeId) as GraphNodeModel;
clipboard.writeText(JSON.stringify(Utils.cloneNodeData(data), null, 2));
}
pasteNode() {
@@ -367,15 +367,17 @@ export default class Editor extends React.Component<EditorProps, EditorState> {
return;
}
this.onSelectNode(null);
const data = JSON.parse(str);
const data = Utils.createTreeData(JSON.parse(str), this.state.settings);
this.autoId = Utils.refreshNodeId(data, this.autoId);
if (!curNodeData.children) {
curNodeData.children = [];
}
curNodeData.children.push(data);
this.autoId = Utils.refreshNodeId(this.graph.findDataById("1") as GraphNodeModel);
// this.autoId = Utils.refreshNodeId(this.graph.findDataById("1") as GraphNodeModel);
this.changeWithoutAnim();
} catch (error) {
message.error("粘贴数据有误");
console.error("paste error", error);
}
}
@@ -407,8 +409,8 @@ export default class Editor extends React.Component<EditorProps, EditorState> {
}}
/>
) : (
<TreePanel model={treeModel} />
)}
<TreePanel model={treeModel} />
)}
</Col>
</Row>
</div>