add batch script
This commit is contained in:
1 parent
0f050a068b
commit
7994e9c515
6 files changed
+106
-9
No files matched your search
@@ -10,9 +10,10 @@
|
|||||||
+ 行为树->新建
|
+ 行为树->新建
|
||||||
|
|
||||||
## 示例项目
|
## 示例项目
|
||||||
+ 工作区: sample/sample-workspace.json
|
+ 工作区: sample/workspace.json
|
||||||
+ 节点定义: sample/sample-node-config.json
|
+ 节点定义: sample/node-config.json
|
||||||
+ 行为树目录: sample/sample-workdir
|
+ 行为树目录: sample/workdir
|
||||||
|
+ 批处理脚本: sample/scripts
|
||||||
|
|
||||||
Tips: workspace.json也可以手动编辑,加上isRelative可以让配置中的路径变成相对路径,这样就不需要团队中每个人在使用前都必须先创建工作区
|
Tips: workspace.json也可以手动编辑,加上isRelative可以让配置中的路径变成相对路径,这样就不需要团队中每个人在使用前都必须先创建工作区
|
||||||
|
|
||||||
@@ -44,9 +45,9 @@ npm run dist # 编译exe可执行文件
|
|||||||
|
|
||||||
## 技术栈
|
## 技术栈
|
||||||
+ react + ts
|
+ react + ts
|
||||||
+ g6
|
|
||||||
+ antd
|
|
||||||
+ electron
|
+ electron
|
||||||
|
+ antd
|
||||||
|
+ g6
|
||||||
|
|
||||||
## 示例行为树框架
|
## 示例行为树框架
|
||||||
+ lua版本 [behavior3lua](https://github.com/zhandouxiaojiji/behavior3lua)
|
+ lua版本 [behavior3lua](https://github.com/zhandouxiaojiji/behavior3lua)
|
||||||
@@ -54,6 +55,9 @@ npm run dist # 编译exe可执行文件
|
|||||||
|
|
||||||
## TODO
|
## TODO
|
||||||
+ 右键菜单
|
+ 右键菜单
|
||||||
|
+ 面板拖拽新建节点
|
||||||
|
+ 未保存的行为树标星号
|
||||||
|
+ 异步加载界面
|
||||||
|
|
||||||
## About
|
## About
|
||||||
目前编辑器还处于非常简陋的阶段,有问题可以联系作者(QQ1013299930),本项目将长期维护,望前端大佬们多提点~
|
目前编辑器还处于非常简陋的阶段,有问题可以联系作者(QQ1013299930),本项目将长期维护,望前端大佬们多提点~
|
||||||
@@ -0,0 +1,57 @@
|
|||||||
|
import * as fs from 'fs';
|
||||||
|
import * as path from 'path';
|
||||||
|
import { BehaviorNodeModel, BehaviorTreeModel } from './BehaviorTreeModel';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
export default (scriptPath: string, dirPath: string) => {
|
||||||
|
console.log("script", scriptPath);
|
||||||
|
const str = fs.readFileSync(scriptPath, "utf8");
|
||||||
|
const script = eval(str);
|
||||||
|
const batchExec = (filePath: string) => {
|
||||||
|
fs.readdir(filePath, (err, files) => {
|
||||||
|
if (err) {
|
||||||
|
console.warn(err)
|
||||||
|
} else {
|
||||||
|
files.forEach((filename) => {
|
||||||
|
var filedir = path.join(filePath, filename);
|
||||||
|
fs.stat(filedir, (err, stats) => {
|
||||||
|
if (err) {
|
||||||
|
console.warn('获取文件stats失败', err);
|
||||||
|
} else {
|
||||||
|
if (stats.isFile() && filename.match(/.\.json$/)) {
|
||||||
|
const str = fs.readFileSync(filedir, "utf8");
|
||||||
|
let tree: BehaviorTreeModel = JSON.parse(str);
|
||||||
|
if(script.processTree) {
|
||||||
|
tree = script.processTree(tree);
|
||||||
|
}
|
||||||
|
if(tree && script.processNode) {
|
||||||
|
const processNode = (node: BehaviorNodeModel) => {
|
||||||
|
script.processNode(node);
|
||||||
|
if(node.children) {
|
||||||
|
for(let child of node.children) {
|
||||||
|
processNode(child);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
processNode(tree.root);
|
||||||
|
}
|
||||||
|
if (tree) {
|
||||||
|
fs.writeFileSync(
|
||||||
|
filedir,
|
||||||
|
JSON.stringify(tree)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
if (stats.isDirectory()) {
|
||||||
|
batchExec(filedir);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
batchExec(dirPath);
|
||||||
|
}
|
||||||
@@ -12,4 +12,5 @@ export default {
|
|||||||
RELOAD_SERVER: "RELOAD_SERVER",
|
RELOAD_SERVER: "RELOAD_SERVER",
|
||||||
UNDO: "UNDO",
|
UNDO: "UNDO",
|
||||||
REDO: "REDO",
|
REDO: "REDO",
|
||||||
|
BATCH_EXEC: "BATCH_EXEC",
|
||||||
};
|
};
|
||||||
+18
-4
@@ -344,10 +344,6 @@ export default class AppMenu {
|
|||||||
return new MenuItem({
|
return new MenuItem({
|
||||||
label: "开发工具",
|
label: "开发工具",
|
||||||
submenu: [
|
submenu: [
|
||||||
{
|
|
||||||
label: "联调服务器",
|
|
||||||
submenu: serverItems,
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
label: "热更",
|
label: "热更",
|
||||||
accelerator: "Ctrl+R",
|
accelerator: "Ctrl+R",
|
||||||
@@ -355,6 +351,24 @@ export default class AppMenu {
|
|||||||
this.webContents.send(MainEventType.RELOAD_SERVER);
|
this.webContents.send(MainEventType.RELOAD_SERVER);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
label: "联调服务器",
|
||||||
|
submenu: serverItems,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: "处理脚本",
|
||||||
|
click: () => {
|
||||||
|
(async () => {
|
||||||
|
const res = await dialog.showOpenDialog({
|
||||||
|
properties: ["openFile"],
|
||||||
|
filters: [{ name: "Javascript", extensions: ["js"] }],
|
||||||
|
});
|
||||||
|
if (res.filePaths.length > 0) {
|
||||||
|
this.webContents.send(MainEventType.BATCH_EXEC, res.filePaths[0]);
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
type: 'separator',
|
type: 'separator',
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import "./index.css";
|
|||||||
import RegisterNode from "./RegisterNode";
|
import RegisterNode from "./RegisterNode";
|
||||||
import TreeTabs from "./TreeTabs";
|
import TreeTabs from "./TreeTabs";
|
||||||
import Explorer from "./Explorer";
|
import Explorer from "./Explorer";
|
||||||
|
import BatchExec from "../common/BatchExec";
|
||||||
|
|
||||||
const { Sider, Content } = Layout;
|
const { Sider, Content } = Layout;
|
||||||
|
|
||||||
@@ -63,6 +64,10 @@ export default class Main extends Component {
|
|||||||
message.success("服务器已更新");
|
message.success("服务器已更新");
|
||||||
})
|
})
|
||||||
|
|
||||||
|
ipcRenderer.on(MainEventType.BATCH_EXEC, (event: any, path: string)=>{
|
||||||
|
BatchExec(path, this.state.workdir);
|
||||||
|
})
|
||||||
|
|
||||||
console.log("workdir", this.settings.curWorkspace.getWorkdir());
|
console.log("workdir", this.settings.curWorkspace.getWorkdir());
|
||||||
this.setState({
|
this.setState({
|
||||||
workdir: this.settings.curWorkspace.getWorkdir(),
|
workdir: this.settings.curWorkspace.getWorkdir(),
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
/* 批处理脚本 */
|
||||||
|
/*
|
||||||
|
如果有processTree,则先运行prcessTree,如果有返回,则进行后面的针对每个节点运行processNode
|
||||||
|
如果没有定义processTree,则直接针对每个节点运行processNode
|
||||||
|
*/
|
||||||
|
({
|
||||||
|
processTree: (tree) => {
|
||||||
|
console.log("processTree", tree.name);
|
||||||
|
if (tree.name == "hero") {
|
||||||
|
return tree;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
processNode: (node) => {
|
||||||
|
console.log("processNode", node.id)
|
||||||
|
}
|
||||||
|
})
|
||||||
Reference in new issue
Block a user