mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-16 23:30:41 +09:00
Replace Hotpatch with save patching
Remove Hotpatch and implement a save patcher in its place. The save patcher takes a normal Factorio save and adds modules to it that's loaded by a generated control.lua file. This greatly reduces the difficulty of adding an existing game to Clusterio and using scenario code in plugins. The mechanism for selecting what code to patch into the saves from plugins is temorary and expected to change with #220.
This commit is contained in:
1 parent
079e31cf05
commit
1a035e849e
61 files changed
+575
-2709
No files matched your search
@@ -3,11 +3,9 @@ const fs = require("fs-extra");
|
||||
|
||||
const objectOps = require("lib/objectOps.js");
|
||||
const fileOps = require("lib/fileOps");
|
||||
const checkHotpatchInstallation = require("lib/clusterTools/checkHotpatchInstallation");
|
||||
const getLua = require("lib/clusterTools/getLua");
|
||||
|
||||
const pluginConfig = require("./config");
|
||||
const COMPRESS_LUA = false;
|
||||
|
||||
|
||||
function ensureFileSync(path) {
|
||||
if (!fs.existsSync(path)) {
|
||||
@@ -39,16 +37,8 @@ module.exports = class remoteCommands {
|
||||
ensureFileSync(instancedirectory + "/script-output/output.txt");
|
||||
ensureFileSync(instancedirectory + "/script-output/orders.txt");
|
||||
ensureFileSync(instancedirectory + "/script-output/txbuffer.txt");
|
||||
|
||||
(async ()=>{
|
||||
let hotpatchInstallStatus = await checkHotpatchInstallation(this.messageInterface);
|
||||
this.messageInterface("Hotpach installation status: "+hotpatchInstallStatus);
|
||||
if(hotpatchInstallStatus){
|
||||
// let mainCode = await getLua("sharedPlugins/playerManager/lua/playerTracking.lua");
|
||||
// if(mainCode) var returnValue = await messageInterface("/silent-command remote.call('hotpatch', 'update', '"+pluginConfig.name+"', '"+pluginConfig.version+"', '"+mainCode+"')");
|
||||
}
|
||||
})().catch(e => console.log(e));
|
||||
|
||||
|
||||
|
||||
// flow/production statistics ------------------------------------------------------------
|
||||
var oldFlowStats = false;
|
||||
var oldTimestamp;
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
/*
|
||||
Clusterio plugin for loading softmod scenarios using Hotpatch
|
||||
To load a scenario, simply drop it inside sharedPlugins/scenario_loader/scenarios/
|
||||
*/
|
||||
module.exports = {
|
||||
name: "scenario_loader",
|
||||
version: "1.0.0",
|
||||
binary: "nodePackage",
|
||||
description: "Simple way to load scenarios using Hotpatch"
|
||||
}
|
||||
@@ -1,107 +0,0 @@
|
||||
const fs = require("fs-extra");
|
||||
const path = require("path");
|
||||
const clusterTools = require("lib/clusterTools")();
|
||||
|
||||
module.exports = class remoteCommands {
|
||||
constructor(mergedConfig, messageInterface, extras){
|
||||
this.messageInterface = messageInterface;
|
||||
this.config = mergedConfig;
|
||||
|
||||
(async () => {
|
||||
let hotpatchInstallStatus = await clusterTools.checkHotpatchInstallation(messageInterface);
|
||||
messageInterface("Hotpach installation status: "+hotpatchInstallStatus);
|
||||
if(hotpatchInstallStatus){
|
||||
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,
|
||||
});
|
||||
}
|
||||
}
|
||||
return returnFiles;
|
||||
}
|
||||
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`);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 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);
|
||||
}
|
||||
});
|
||||
}
|
||||
class AsyncArray extends Array {
|
||||
constructor(arr) {
|
||||
super(arr)
|
||||
this.data = arr; // In place of Array subclassing
|
||||
}
|
||||
async filterAsync(predicate) {
|
||||
// Take a copy of the array, it might mutate by the time we've finished
|
||||
const data = Array.from(this.data);
|
||||
// Transform all the elements into an array of promises using the predicate
|
||||
// as the promise
|
||||
const result = await Promise.all(data.map((element, index) => predicate(element, index, data)));
|
||||
return data.filter((element, index) => {
|
||||
return result[index];
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
// These are libraries that does not have any units test, they are
|
||||
// required here in order to track coverage for them.
|
||||
|
||||
require('../index');
|
||||
Reference in new issue
Block a user