Changed hotpatch scenario dir for visibility, made scenario loading recursive

This commit is contained in:
Daniel Vestøl committed 2018-11-13 21:24:42 +01:00
1 parent 58b609cbd0
commit 1e868b4ff4
2 files changed
+39 -6

No files matched your search

+2
View File
@@ -12,6 +12,8 @@ module.exports = class remoteCommands {
this.socket.on("gameChat", async data => {
if(data.instanceID && data.instanceID != this.config.unique.toString()){
if(data.data.includes("[CHAT]")
// if this isn't used as an info command or something (reduce spam)
&& !data.data.includes("!info")
// check if we are allowed to cross chat at all, default to true
&& (mergedConfig.enableCrossServerShout == undefined || mergedConfig.enableCrossServerShout)
// check if we are supposed to relay this message
+37 -6
View File
@@ -11,29 +11,38 @@ module.exports = class remoteCommands {
let hotpatchInstallStatus = await this.checkHotpatchInstallation();
messageInterface("Hotpach installation status: "+hotpatchInstallStatus);
if(hotpatchInstallStatus){
let scenarioDir = path.join(__dirname, "scenarios");
let scenarioDir = "scenarios";
await fs.ensureDir(scenarioDir)
let scenarios = await fs.readdir(scenarioDir);
for(let i = 0; i < scenarios.length; i++){
let scenPath = path.join(scenarioDir, scenarios[i]);
let stat = await fs.stat(scenPath);
if(stat.isDirectory){
let scenario = await fs.readdir(scenPath);
// let scenario = await fs.readdir(scenPath, {withFileTypes: true});
// this function is bad in terms of scope since it relies on a global for return values, should be refactored.
filesCollection = [];
readDirectorySynchronously(scenPath);
let scenario = filesCollection;
let files = {};
for(let o = 0; o < scenario.length; o++){
let fileName = scenario[o];
if(fileName.split(".")[1] && fileName.split(".")[1].toLowerCase() == "lua"){
messageInterface(`Loading ${scenarios[i]}/${fileName}`);
let code = await clusterTools.getLua(path.join(scenPath, fileName), false);
messageInterface(`Loading `/*${scenarios[i]}*/+`${fileName}`);
let code = await clusterTools.getLua(/*path.join(scenPath, */fileName/*)*/, false);
// trim away external path from filenames
fileName = fileName.replace("scenarios\\factoriommoscenarios\\", "");
files[fileName.split(".")[0]] = code;
}
}
let fileImportString = `\{`;
for(let k in files){
fileImportString += `${k} = '${files[k]}, '`;
let name = k.replace(/\\/g, '/');
name = name.replace(/ /g, '');
fileImportString += `["${name}"] = '${files[k]}', `;
}
fileImportString += `\}`;
console.log(fileImportString)
if(files.control) var returnValue = await messageInterface(`/silent-command remote.call('hotpatch', 'update', '${scenarios[i]}', '1.0.0', '${files.control}', ${fileImportString})`);
if(returnValue) messageInterface(returnValue);
}
@@ -51,3 +60,25 @@ module.exports = class remoteCommands {
}
}
}
// this function is bad in terms of scope since it relies on a global for return values, should be refactored.
var filesCollection = [];
const directoriesToSkip = ['bower_components', 'node_modules', 'www', 'platforms', '.git'];
function readDirectorySynchronously(directory) {
var currentDirectorypath = /*path.join(__dirname + */directory//);
var currentDirectory = fs.readdirSync(currentDirectorypath, 'utf8');
currentDirectory.forEach(file => {
var fileShouldBeSkipped = directoriesToSkip.indexOf(file) > -1;
var pathOfCurrentItem = path.join(/*__dirname + */directory + '/' + file);
if (!fileShouldBeSkipped && fs.statSync(pathOfCurrentItem).isFile()) {
filesCollection.push(pathOfCurrentItem);
}
else if (!fileShouldBeSkipped) {
var directorypath = path.join(directory, file);
readDirectorySynchronously(directorypath);
}
});
}