save selected as subtree quickly
This commit is contained in:
1 parent
fed08a0f45
commit
91da6f0071
4 files changed
+53
-1
No files matched your search
@@ -11,6 +11,7 @@ export default {
|
||||
SAVE_ALL: "SAVE_ALL",
|
||||
BUILD: "BUILD",
|
||||
SAVE: "SAVE",
|
||||
SAVE_AS_SUBTREE: "SAVE_AS_SUBTREE",
|
||||
UNDO: "UNDO",
|
||||
REDO: "REDO",
|
||||
};
|
||||
@@ -115,6 +115,20 @@ export default class AppMenu {
|
||||
this.webContents.send(MainEventType.SAVE_ALL);
|
||||
},
|
||||
},
|
||||
{
|
||||
label: "保存为子树",
|
||||
click: async () => {
|
||||
const res = await dialog.showSaveDialog({
|
||||
defaultPath: this.settings.workdir,
|
||||
properties: ["showOverwriteConfirmation"],
|
||||
filters: [{ name: "Json", extensions: ["json"] }],
|
||||
});
|
||||
if (!res.canceled) {
|
||||
const path = res.filePath;
|
||||
this.webContents.send(MainEventType.SAVE_AS_SUBTREE, path);
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
label: "合并导出Json",
|
||||
click: () => {
|
||||
|
||||
@@ -463,6 +463,34 @@ export default class Editor extends React.Component<EditorProps, EditorState> {
|
||||
this.graph.set("animate", true);
|
||||
}
|
||||
|
||||
saveAsSubtree(subpath: string) {
|
||||
const { curNodeId } = this.state;
|
||||
if (!curNodeId) {
|
||||
message.warn("未选择一个节点");
|
||||
return;
|
||||
} else if (curNodeId == "1") {
|
||||
message.warn("根节点不能保存为子树");
|
||||
return;
|
||||
}
|
||||
const workdir = this.settings.workdir;
|
||||
if (subpath.indexOf(workdir) == -1) {
|
||||
message.warn("请保存在工作区中");
|
||||
return;
|
||||
}
|
||||
const data = this.graph.findDataById(curNodeId) as GraphNodeModel;
|
||||
const subroot = Utils.createFileData(data);
|
||||
const subtreeModel = {
|
||||
name: path.basename(subpath).slice(0, -5),
|
||||
root: subroot,
|
||||
desc: data.desc,
|
||||
} as BehaviorTreeModel;
|
||||
fs.writeFileSync(subpath, JSON.stringify(subtreeModel, null, 2));
|
||||
this.pushUndoStack();
|
||||
data.path = subpath.substring(workdir.length + 1);
|
||||
this.unsave = true;
|
||||
this.save();
|
||||
}
|
||||
|
||||
reload() {
|
||||
if (!this.unsave) {
|
||||
const data = this.graph.findDataById("1") as GraphNodeModel;
|
||||
|
||||
@@ -64,6 +64,15 @@ export default class TreeTabs extends Component<TreeTabsProps, TreeTabsState> {
|
||||
message.success("已保存");
|
||||
});
|
||||
|
||||
ipcRenderer.on(MainEventType.SAVE_AS_SUBTREE, (event: any, path: string) => {
|
||||
const { curTree: curPath } = this.state;
|
||||
if (!curPath) {
|
||||
return;
|
||||
}
|
||||
const editor = this.editors[curPath];
|
||||
editor.saveAsSubtree(path);
|
||||
});
|
||||
|
||||
ipcRenderer.on(MainEventType.SAVE_ALL, (event: any) => {
|
||||
for (let k in this.editors) {
|
||||
let editor = this.editors[k];
|
||||
@@ -72,7 +81,7 @@ export default class TreeTabs extends Component<TreeTabsProps, TreeTabsState> {
|
||||
message.success("已保存所有行为树");
|
||||
});
|
||||
|
||||
ipcRenderer.on(MainEventType.BUILD, async (event, buildDir) => {
|
||||
ipcRenderer.on(MainEventType.BUILD, async (event, buildDir: string) => {
|
||||
for (let k in this.editors) {
|
||||
let editor = this.editors[k];
|
||||
editor.save();
|
||||
|
||||
Reference in new issue
Block a user