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