fix BatchExec
This commit is contained in:
1 parent
1ae6c348a8
commit
74dc1c207d
3 files changed
+35
-44
No files matched your search
+31
-40
@@ -5,53 +5,44 @@ import { BehaviorNodeModel, BehaviorTreeModel } from './BehaviorTreeModel';
|
|||||||
|
|
||||||
|
|
||||||
export default (scriptPath: string, dirPath: string) => {
|
export default (scriptPath: string, dirPath: string) => {
|
||||||
console.log("script", scriptPath);
|
console.log("run script", scriptPath);
|
||||||
const str = fs.readFileSync(scriptPath, "utf8");
|
const str = fs.readFileSync(scriptPath, "utf8");
|
||||||
const script = eval(str);
|
const script = eval(str);
|
||||||
const batchExec = (filePath: string) => {
|
const batchExec = (filePath: string) => {
|
||||||
fs.readdir(filePath, (err, files) => {
|
const files = fs.readdirSync(filePath);
|
||||||
if (err) {
|
files.forEach((filename) => {
|
||||||
console.warn(err)
|
var filedir = path.join(filePath, filename);
|
||||||
} else {
|
const stats = fs.statSync(filedir);
|
||||||
files.forEach((filename) => {
|
if (stats.isFile() && filename.match(/.\.json$/)) {
|
||||||
var filedir = path.join(filePath, filename);
|
const str = fs.readFileSync(filedir, "utf8");
|
||||||
fs.stat(filedir, (err, stats) => {
|
let tree: BehaviorTreeModel = JSON.parse(str);
|
||||||
if (err) {
|
if (script.processTree) {
|
||||||
console.warn('获取文件stats失败', err);
|
tree = script.processTree(tree);
|
||||||
} else {
|
}
|
||||||
if (stats.isFile() && filename.match(/.\.json$/)) {
|
if (tree && script.processNode) {
|
||||||
const str = fs.readFileSync(filedir, "utf8");
|
const processNode = (node: BehaviorNodeModel) => {
|
||||||
let tree: BehaviorTreeModel = JSON.parse(str);
|
script.processNode(node, tree);
|
||||||
if(script.processTree) {
|
if (node.children) {
|
||||||
tree = script.processTree(tree);
|
for (let child of node.children) {
|
||||||
}
|
processNode(child);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
});
|
processNode(tree.root);
|
||||||
|
}
|
||||||
|
if (tree) {
|
||||||
|
fs.writeFileSync(
|
||||||
|
filedir,
|
||||||
|
JSON.stringify(tree)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
if (stats.isDirectory()) {
|
||||||
|
batchExec(filedir);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
batchExec(dirPath);
|
batchExec(dirPath);
|
||||||
|
console.log("run script", scriptPath, "done!");
|
||||||
}
|
}
|
||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "behavior3editor",
|
"name": "behavior3editor",
|
||||||
"version": "0.1.4",
|
"version": "0.1.5",
|
||||||
"description": "行为树编辑器",
|
"description": "行为树编辑器",
|
||||||
"main": "./dist/main.js",
|
"main": "./dist/main.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
@@ -5,12 +5,12 @@
|
|||||||
*/
|
*/
|
||||||
({
|
({
|
||||||
processTree: (tree) => {
|
processTree: (tree) => {
|
||||||
console.log("processTree", tree.name);
|
console.log(`processTree ${tree.name}`);
|
||||||
if (tree.name == "hero") {
|
if (tree.name == "hero") {
|
||||||
return tree;
|
return tree;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
processNode: (node) => {
|
processNode: (node, tree) => {
|
||||||
console.log("processNode", node.id)
|
console.log(`processNode ${tree.name}.${node.id}`);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
Reference in new issue
Block a user