diff --git a/lib/manager/instanceManager.js b/lib/manager/instanceManager.js new file mode 100644 index 00000000..1b0162a9 --- /dev/null +++ b/lib/manager/instanceManager.js @@ -0,0 +1,2 @@ +const fs = require("fs-extra"); +const needle = require("needle"); diff --git a/lib/scenarios/Hotpatch/hotpatch/mod-tools.lua b/lib/scenarios/Hotpatch/hotpatch/mod-tools.lua index 860e3b59..89371cd6 100644 --- a/lib/scenarios/Hotpatch/hotpatch/mod-tools.lua +++ b/lib/scenarios/Hotpatch/hotpatch/mod-tools.lua @@ -382,7 +382,6 @@ debug_log({'hotpatch-info.loading-libs'}) local libraries = { 'camera', 'flying_tags', - 'inspect', 'math3d', 'mod-gui', 'noise', diff --git a/sharedPlugins/scenario_loader/index.js b/sharedPlugins/scenario_loader/index.js index 2f4e8223..5889ee4b 100644 --- a/sharedPlugins/scenario_loader/index.js +++ b/sharedPlugins/scenario_loader/index.js @@ -11,35 +11,36 @@ module.exports = class remoteCommands { let hotpatchInstallStatus = await this.checkHotpatchInstallation(); messageInterface("Hotpach installation status: "+hotpatchInstallStatus); if(hotpatchInstallStatus){ - let scenarioDir = "scenarios"; - await fs.ensureDir(scenarioDir) - let scenarios = await fs.readdir(scenarioDir); - for(let i = 0; i < scenarios.length; i++){ - messageInterface(`Loading scenario ${scenarios[i]}`) - let startTime = Date.now(); - let scenPath = path.join(scenarioDir, scenarios[i]); - let stat = await fs.stat(scenPath); - if(stat.isDirectory){ - async function loadFiles(dir, rootdir){ - let returnFiles = []; - let entries = await fs.readdir(path.join(rootdir, dir)); - for(let o = 0; o < entries.length; o++){ - let stat = await fs.stat(path.join(rootdir, dir, entries[o])); - if(stat.isDirectory()){ - // recurse - let subFolder = await loadFiles(path.join(dir, entries[o]), rootdir); - returnFiles = returnFiles.concat(subFolder); - } else if(entries[o].split(".")[entries[o].split(".").length-1].toLowerCase() == "lua"){ - // if it is a Lua file, read its contents - // let data = await fs.readFile(path.join(rootdir, dir, entries[o])); - let data = await clusterTools.getLua(path.join(rootdir, dir, entries[o]), false); - returnFiles.push({ - name: path.join(dir, entries[o].split(".")[0]), - data, - }); - } - } - return returnFiles; + await this.loadScenariosFromFolder("scenarios") // located in project root folder (with sharedMods, sharedPlugins etc) + } + })(); + } + async loadScenariosFromFolder(scenarioDir){ + await fs.ensureDir(scenarioDir) + let scenarios = await fs.readdir(scenarioDir); + for(let i = 0; i < scenarios.length; i++){ + this.messageInterface(`Loading scenario ${scenarios[i]}`) + let startTime = Date.now(); + let scenPath = path.join(scenarioDir, scenarios[i]); + let stat = await fs.stat(scenPath); + if(stat.isDirectory){ + async function loadFiles(dir, rootdir){ + let returnFiles = []; + let entries = await fs.readdir(path.join(rootdir, dir)); + for(let o = 0; o < entries.length; o++){ + let stat = await fs.stat(path.join(rootdir, dir, entries[o])); + if(stat.isDirectory()){ + // recurse + let subFolder = await loadFiles(path.join(dir, entries[o]), rootdir); + returnFiles = returnFiles.concat(subFolder); + } else if(entries[o].split(".")[entries[o].split(".").length-1].toLowerCase() == "lua"){ + // if it is a Lua file, read its contents + // let data = await fs.readFile(path.join(rootdir, dir, entries[o])); + let data = await clusterTools.getLua(path.join(rootdir, dir, entries[o]), false); + returnFiles.push({ + name: path.join(dir, entries[o].split(".")[0]), + data, + }); } let fileMap = await loadFiles("", scenPath); let files = {}; @@ -61,6 +62,24 @@ module.exports = class remoteCommands { messageInterface(`Loaded scenario ${scenarios[i]} in ${Math.floor(Date.now()-startTime)}ms`); } } + let fileMap = await loadFiles("", scenPath); + let files = {}; + fileMap.forEach(map => { + files[map.name] = map.data; + console.log(map.name); + }); + + let fileImportString = `\{`; + for(let k in files){ + let name = k.replace(/\\/g, '/'); + name = name.replace(/ /g, ''); + // make sure *not* to include control.lua as it is provided as a seperate argument + if(name != "control") fileImportString += `["${name}"] = '${files[k]}', `; + } + fileImportString += `\}`; + if(files.control) var returnValue = await this.messageInterface(`/silent-command remote.call('hotpatch', 'update', '${scenarios[i]}', '1.0.0', '${files.control}', ${fileImportString})`); + if(returnValue) this.messageInterface(returnValue); + this.messageInterface(`Loaded scenario ${scenarios[i]} in ${Math.floor(Date.now()-startTime)}ms`); } })(); } @@ -96,3 +115,8 @@ function readDirectorySynchronously(directory) { } }); } +class AsyncArray extends Array { + constructor(arr) { + super(arr) + this.data = arr; // In place of Array subclassing + }