workspace.json中允许配置相对路径
This commit is contained in:
1 parent
6f9ddce974
commit
16d783aebf
3 files changed
+23
-6
No files matched your search
@@ -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版本 计划中。
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
{
|
||||
"nodeConfPath": "sample\\node-config.json",
|
||||
"workdir": "E:\\code\\behavior3editor\\sample\\workdir"
|
||||
"isRelative": true,
|
||||
"nodeConfPath": "node-config.json",
|
||||
"workdir": "workdir"
|
||||
}
|
||||
Reference in new issue
Block a user