mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-18 23:33:12 +09:00
Big changes to plugin system, fixed inventoryImports
This commit is contained in:
1 parent
36ccf22e02
commit
44b68c92d5
3 files changed
+114
-87
No files matched your search
@@ -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.
|
||||
|
||||
@@ -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;
|
||||
Reference in new issue
Block a user