fix copy & paste node
This commit is contained in:
1 parent
7321592a12
commit
8564fc1ebe
3 files changed
+36
-10
No files matched your search
+27
-3
@@ -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
@@ -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": {
|
||||||
|
|||||||
@@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -407,8 +409,8 @@ export default class Editor extends React.Component<EditorProps, EditorState> {
|
|||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
<TreePanel model={treeModel} />
|
<TreePanel model={treeModel} />
|
||||||
)}
|
)}
|
||||||
</Col>
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in new issue
Block a user