diff --git a/README.md b/README.md index ab66f23..86f8005 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,8 @@ + 节点定义: sample/sample-node-config.json + 行为树目录: sample/sample-workdir +Tips: workspace.json也可以手动编辑,加上isRelative可以让配置中的路径变成相对路径,这样就不需要团队中每个人在使用前都必须先创建工作区 + ## 节点定义 ```typescript interface ArgsDefType { @@ -46,7 +48,7 @@ npm run build # 编译exe可执行文件 + antd + electron -## 示例项目 +## 示例行为树框架 + lua版本 [behavior3lua](https://github.com/zhandouxiaojiji/behavior3lua) + js/ts版本 计划中。 diff --git a/main-process/Workspace.ts b/main-process/Workspace.ts index 618a74d..1404dad 100644 --- a/main-process/Workspace.ts +++ b/main-process/Workspace.ts @@ -1,6 +1,13 @@ import * as fs from 'fs'; +import * as path from 'path'; import { BehaviorNodeTypeModel } from '../common/BehaviorTreeModel'; +export interface WorkspaceModel { + isRelative?: boolean; + nodeConfPath: string; + workdir: string; +} + const unknowNodeType: BehaviorNodeTypeModel = { name: 'unknow', desc: '新建节点', @@ -25,9 +32,16 @@ export default class Workspace { } try { const str = fs.readFileSync(this.filepath, 'utf8'); - const data = JSON.parse(str); - this.nodeConfPath = data.nodeConfPath; - this.workdir = data.workdir; + const model = JSON.parse(str) as WorkspaceModel; + if (model.isRelative) { + const root = path.dirname(this.filepath); + this.nodeConfPath = root + '/' + model.nodeConfPath; + this.workdir = root + '/' + model.workdir; + } else { + this.nodeConfPath = model.nodeConfPath; + this.workdir = model.workdir; + } + this.initNodeConf(); } catch (error) { console.log(error); diff --git a/sample/workspace.json b/sample/workspace.json index 0c685fe..9a58516 100644 --- a/sample/workspace.json +++ b/sample/workspace.json @@ -1,4 +1,5 @@ { - "nodeConfPath": "sample\\node-config.json", - "workdir": "E:\\code\\behavior3editor\\sample\\workdir" + "isRelative": true, + "nodeConfPath": "node-config.json", + "workdir": "workdir" } \ No newline at end of file