diff --git a/common/Utils.ts b/common/Utils.ts index 633261d..b27268f 100644 --- a/common/Utils.ts +++ b/common/Utils.ts @@ -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; }; diff --git a/package.json b/package.json index 9309714..c616514 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "behavior3editor", - "version": "0.1.1", + "version": "0.1.2", "description": "行为树编辑器", "main": "./dist/main.js", "scripts": { diff --git a/render-process/Editor/index.tsx b/render-process/Editor/index.tsx index fd32f86..e98e945 100644 --- a/render-process/Editor/index.tsx +++ b/render-process/Editor/index.tsx @@ -350,8 +350,8 @@ export default class Editor extends React.Component { 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 { 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 { }} /> ) : ( - - )} + + )}