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
+34 -8

No files matched your search

+27 -3
View File
@@ -5,11 +5,35 @@ import { remote } from "electron";
import * as path from "path"; import * as path from "path";
export const cloneNodeData = (nodeData: GraphNodeModel) => { export const cloneNodeData = (nodeData: GraphNodeModel) => {
const newData: GraphNodeModel = { const newData: BehaviorNodeModel = {
id: nodeData.id + "new", id: Number(nodeData.id),
name: nodeData.name, 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; return newData;
}; };
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "behavior3editor", "name": "behavior3editor",
"version": "0.1.1", "version": "0.1.2",
"description": "行为树编辑器", "description": "行为树编辑器",
"main": "./dist/main.js", "main": "./dist/main.js",
"scripts": { "scripts": {
+6 -4
View File
@@ -350,8 +350,8 @@ export default class Editor extends React.Component<EditorProps, EditorState> {
if (!curNodeId) { if (!curNodeId) {
return; return;
} }
const data = this.graph.findDataById(curNodeId); const data = this.graph.findDataById(curNodeId) as GraphNodeModel;
clipboard.writeText(JSON.stringify(data, null, 2)); clipboard.writeText(JSON.stringify(Utils.cloneNodeData(data), null, 2));
} }
pasteNode() { pasteNode() {
@@ -367,15 +367,17 @@ export default class Editor extends React.Component<EditorProps, EditorState> {
return; return;
} }
this.onSelectNode(null); 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) { if (!curNodeData.children) {
curNodeData.children = []; curNodeData.children = [];
} }
curNodeData.children.push(data); 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(); this.changeWithoutAnim();
} catch (error) { } catch (error) {
message.error("粘贴数据有误"); message.error("粘贴数据有误");
console.error("paste error", error);
} }
} }