specify output directory when build

This commit is contained in:
codetypes committed 2024-03-12 09:46:56 +08:00
1 parent 8e43285089
commit 95689ec712
4 files changed
+39 -24

No files matched your search

+12 -2
View File
@@ -20,6 +20,7 @@ export default class AppMenu {
private mainWindow: BrowserWindow; private mainWindow: BrowserWindow;
private webContents: WebContents; private webContents: WebContents;
private settings: Settings; private settings: Settings;
private buildDir?: string;
constructor(mainProcess: MainProcess) { constructor(mainProcess: MainProcess) {
this.mainProcess = mainProcess; this.mainProcess = mainProcess;
@@ -139,8 +140,17 @@ export default class AppMenu {
{ {
label: "构建", label: "构建",
accelerator: "CommandOrControl+b", accelerator: "CommandOrControl+b",
click: () => { click: async () => {
this.webContents.send(MainEventType.BUILD); if (!this.buildDir) {
const res = await dialog.showOpenDialog({
properties: ["openDirectory"],
});
if (res.canceled) {
return;
}
this.buildDir = res.filePaths[0];
}
this.webContents.send(MainEventType.BUILD, this.buildDir);
}, },
}, },
], ],
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "behavior3editor", "name": "behavior3editor",
"version": "0.2.0", "version": "0.2.1",
"description": "行为树编辑器", "description": "行为树编辑器",
"main": "./dist/main.js", "main": "./dist/main.js",
"scripts": { "scripts": {
+4 -9
View File
@@ -2,8 +2,8 @@ import { Tabs, message } from "antd";
import { ipcRenderer } from "electron"; import { ipcRenderer } from "electron";
import * as fs from "fs"; import * as fs from "fs";
import * as path from "path"; import * as path from "path";
import * as Utils from "../common/Utils";
import React, { Component } from "react"; import React, { Component } from "react";
import * as Utils from "../common/Utils";
import Editor from "./Editor"; import Editor from "./Editor";
import "antd/dist/antd.dark.css"; import "antd/dist/antd.dark.css";
@@ -72,7 +72,7 @@ export default class TreeTabs extends Component<TreeTabsProps, TreeTabsState> {
message.success("已保存所有行为树"); message.success("已保存所有行为树");
}); });
ipcRenderer.on(MainEventType.BUILD, () => { ipcRenderer.on(MainEventType.BUILD, async (event, buildDir) => {
for (let k in this.editors) { for (let k in this.editors) {
let editor = this.editors[k]; let editor = this.editors[k];
editor.save(); editor.save();
@@ -80,21 +80,16 @@ export default class TreeTabs extends Component<TreeTabsProps, TreeTabsState> {
const settings = Utils.getRemoteSettings(); const settings = Utils.getRemoteSettings();
const workdir = settings.workdir; const workdir = settings.workdir;
if (!fs.existsSync(workdir)) {
console.log("workdir not found:", workdir);
return;
}
const files = fs.readdirSync(workdir).filter((f) => { const files = fs.readdirSync(workdir).filter((f) => {
return f.endsWith(".json"); return f.endsWith(".json");
}); });
for (const path of files) { for (const path of files) {
const builddir = fs.realpathSync(workdir + "/../build", "utf-8"); const buildpath = buildDir + "/" + path;
fs.mkdirSync(builddir, { recursive: true });
const buildpath = builddir + "/" + path;
console.log("build:", buildpath); console.log("build:", buildpath);
const treeModel = Utils.createBuildData(path, settings); const treeModel = Utils.createBuildData(path, settings);
fs.writeFileSync(buildpath, JSON.stringify(treeModel, null, 2)); fs.writeFileSync(buildpath, JSON.stringify(treeModel, null, 2));
} }
message.success("已构建所有行为树");
}); });
ipcRenderer.on(MainEventType.UNDO, () => { ipcRenderer.on(MainEventType.UNDO, () => {
+22 -12
View File
@@ -55,18 +55,18 @@ export default class Main extends Component {
body: JSON.stringify({ body: JSON.stringify({
cmd: "btree.reload", cmd: "btree.reload",
data: { data: {
trees: this.tabs.getOpenTreesModel() trees: this.tabs.getOpenTreesModel(),
}, },
session: this.session++, session: this.session++,
timestamp: Date.now(), timestamp: Date.now(),
}) }),
}); });
message.success("服务器已更新"); message.success("服务器已更新");
}) });
ipcRenderer.on(MainEventType.BATCH_EXEC, (event: any, path: string) => { ipcRenderer.on(MainEventType.BATCH_EXEC, (event: any, path: string) => {
BatchExec(path, this.state.workdir); BatchExec(path, this.state.workdir);
}) });
console.log("workdir", this.settings.curWorkspace.getWorkdir()); console.log("workdir", this.settings.curWorkspace.getWorkdir());
setTimeout(() => { setTimeout(() => {
@@ -113,7 +113,7 @@ export default class Main extends Component {
sider.style.maxWidth = width + "px"; sider.style.maxWidth = width + "px";
sider.style.minWidth = "0px"; sider.style.minWidth = "0px";
sider.style.flex = ""; sider.style.flex = "";
reSizer.style.left = (width - 5) + "px"; reSizer.style.left = width - 5 + "px";
content.style.width = window.innerWidth - width + "px"; content.style.width = window.innerWidth - width + "px";
} }
@@ -122,16 +122,27 @@ export default class Main extends Component {
document.documentElement.removeEventListener("mouseup", stopDrag, false); document.documentElement.removeEventListener("mouseup", stopDrag, false);
} }
reSizer.addEventListener("mouseover", function() { reSizer.addEventListener(
"mouseover",
function () {
reSizer.style.opacity = "1"; reSizer.style.opacity = "1";
reSizer.addEventListener("mousedown", initDrag, false); reSizer.addEventListener("mousedown", initDrag, false);
reSizer.addEventListener("mouseout", function init() { reSizer.addEventListener(
"mouseout",
function init() {
reSizer.style.opacity = "0"; reSizer.style.opacity = "0";
}, false); },
}, false); false
);
},
false
);
window.addEventListener("resize", function () { window.addEventListener("resize", function () {
const currentWidth = parseInt(document.defaultView.getComputedStyle(reSizerParent).width, 10); const currentWidth = parseInt(
document.defaultView.getComputedStyle(reSizerParent).width,
10
);
setWidth(currentWidth); setWidth(currentWidth);
}); });
@@ -174,8 +185,7 @@ export default class Main extends Component {
}} }}
onTabSelected={(path) => { onTabSelected={(path) => {
this.explorer.selectNode(path); this.explorer.selectNode(path);
} }}
}
/> />
</Content> </Content>
</Layout> </Layout>