Big changes to plugin system, fixed inventoryImports

This commit is contained in:
Danielv123 committed 2017-12-10 11:27:02 +01:00
1 parent 36ccf22e02
commit 44b68c92d5
3 files changed
+114 -87

No files matched your search

+1 -1
View File
@@ -12,7 +12,7 @@ module.exports = {
version: "1.0.0",
// Binary entrypoint for plugin. Don't let it crash. Stdout is sent to game as server chat (run /c commands from here for interface)
// Make sure its cross platform somehow.
binary: "node",
binary: "nodePackage",
arguments: ["index.js"],
description: "Clusterio plugin to fill character logistic slots with master imports",
// We'll send everything in this file to your stdin. Beware.
+20 -23
View File
@@ -4,27 +4,24 @@ const pluginConfig = require("./config.js");
const functions = require("./interfacingFunctions");
console.log("/silent-command game.print('InventoryImports enabled')");
var config = {};
process.stdin.setEncoding('utf8');
process.stdin.on('readable', () => {
var chunk = process.stdin.read();
// console.log(chunk)
if (chunk !== null && isNaN(chunk) && config && isJson(chunk) && !JSON.parse(chunk).factorioPort){
let inventory = JSON.parse(chunk)
// process inventory of players and ask master for more stuff
functions.handleInventory(inventory, config, console.log);
} else if(isJson(chunk) && JSON.parse(chunk).factorioPort){
config = JSON.parse(chunk);
}
});
process.stdin.on('end', () => {
process.stdout.write('end');
});
// poll inventories
setInterval(function(){
// console.log("Polling inventories\n")
console.log(functions.pollInventories(pluginConfig.scriptOutputFileSubscription));
}, 10000);
class inventoryImports {
constructor(slaveConfig, messageInterface){
this.config = slaveConfig;
this.messageInterface = messageInterface;
messageInterface("/silent-command game.print('InventoryImports enabled')");
setInterval(function(){
messageInterface("Polling inventories\n")
messageInterface(functions.pollInventories(pluginConfig.scriptOutputFileSubscription));
}, 10000);
}
scriptOutput(data){
if(data !== null && isJson(data)){
let inventory = JSON.parse(data);
// process inventory of players and ask master for more stuff
functions.handleInventory(inventory, this.config, this.messageInterface);
}
}
}
module.exports = inventoryImports;