mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-24 08:23:12 +09:00
Changed hotpatch scenario dir for visibility, made scenario loading recursive
This commit is contained in:
1 parent
58b609cbd0
commit
1e868b4ff4
2 files changed
+39
-6
No files matched your search
@@ -12,6 +12,8 @@ module.exports = class remoteCommands {
|
|||||||
this.socket.on("gameChat", async data => {
|
this.socket.on("gameChat", async data => {
|
||||||
if(data.instanceID && data.instanceID != this.config.unique.toString()){
|
if(data.instanceID && data.instanceID != this.config.unique.toString()){
|
||||||
if(data.data.includes("[CHAT]")
|
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
|
// check if we are allowed to cross chat at all, default to true
|
||||||
&& (mergedConfig.enableCrossServerShout == undefined || mergedConfig.enableCrossServerShout)
|
&& (mergedConfig.enableCrossServerShout == undefined || mergedConfig.enableCrossServerShout)
|
||||||
// check if we are supposed to relay this message
|
// check if we are supposed to relay this message
|
||||||
|
|||||||
@@ -11,29 +11,38 @@ module.exports = class remoteCommands {
|
|||||||
let hotpatchInstallStatus = await this.checkHotpatchInstallation();
|
let hotpatchInstallStatus = await this.checkHotpatchInstallation();
|
||||||
messageInterface("Hotpach installation status: "+hotpatchInstallStatus);
|
messageInterface("Hotpach installation status: "+hotpatchInstallStatus);
|
||||||
if(hotpatchInstallStatus){
|
if(hotpatchInstallStatus){
|
||||||
let scenarioDir = path.join(__dirname, "scenarios");
|
let scenarioDir = "scenarios";
|
||||||
await fs.ensureDir(scenarioDir)
|
await fs.ensureDir(scenarioDir)
|
||||||
let scenarios = await fs.readdir(scenarioDir);
|
let scenarios = await fs.readdir(scenarioDir);
|
||||||
for(let i = 0; i < scenarios.length; i++){
|
for(let i = 0; i < scenarios.length; i++){
|
||||||
let scenPath = path.join(scenarioDir, scenarios[i]);
|
let scenPath = path.join(scenarioDir, scenarios[i]);
|
||||||
let stat = await fs.stat(scenPath);
|
let stat = await fs.stat(scenPath);
|
||||||
if(stat.isDirectory){
|
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 = {};
|
let files = {};
|
||||||
for(let o = 0; o < scenario.length; o++){
|
for(let o = 0; o < scenario.length; o++){
|
||||||
let fileName = scenario[o];
|
let fileName = scenario[o];
|
||||||
if(fileName.split(".")[1] && fileName.split(".")[1].toLowerCase() == "lua"){
|
if(fileName.split(".")[1] && fileName.split(".")[1].toLowerCase() == "lua"){
|
||||||
messageInterface(`Loading ${scenarios[i]}/${fileName}`);
|
messageInterface(`Loading `/*${scenarios[i]}*/+`${fileName}`);
|
||||||
let code = await clusterTools.getLua(path.join(scenPath, fileName), false);
|
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;
|
files[fileName.split(".")[0]] = code;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let fileImportString = `\{`;
|
let fileImportString = `\{`;
|
||||||
for(let k in files){
|
for(let k in files){
|
||||||
fileImportString += `${k} = '${files[k]}, '`;
|
let name = k.replace(/\\/g, '/');
|
||||||
|
name = name.replace(/ /g, '');
|
||||||
|
fileImportString += `["${name}"] = '${files[k]}', `;
|
||||||
}
|
}
|
||||||
fileImportString += `\}`;
|
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(files.control) var returnValue = await messageInterface(`/silent-command remote.call('hotpatch', 'update', '${scenarios[i]}', '1.0.0', '${files.control}', ${fileImportString})`);
|
||||||
if(returnValue) messageInterface(returnValue);
|
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);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
Reference in new issue
Block a user