mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-22 16:13:12 +09:00
inventoryImport now reads inventory successfully
This commit is contained in:
1 parent
a09cdfb1de
commit
53cd6c846a
2 files changed
+21
-3
No files matched your search
@@ -13,10 +13,10 @@ let historicalTicks = [];
|
|||||||
process.stdin.on('readable', () => {
|
process.stdin.on('readable', () => {
|
||||||
var chunk = process.stdin.read();
|
var chunk = process.stdin.read();
|
||||||
if (chunk !== null && isNaN(chunk)){
|
if (chunk !== null && isNaN(chunk)){
|
||||||
let inventory = "";
|
|
||||||
// eval because my lua is writing a JS object instead of traditional JSON
|
// eval because my lua is writing a JS object instead of traditional JSON
|
||||||
// this was done because I hate escaping strings and there are more quotes
|
// this was done because I hate escaping strings and there are more quotes
|
||||||
// in JSON than JS objects.
|
// in JSON than JS objects.
|
||||||
|
let inventory = "";
|
||||||
eval("inventory = " + chunk);
|
eval("inventory = " + chunk);
|
||||||
console.log(inventory);
|
console.log(inventory);
|
||||||
} else if(isJson(chunk) && JSON.parse(chunk).factorioPort){
|
} else if(isJson(chunk) && JSON.parse(chunk).factorioPort){
|
||||||
@@ -30,7 +30,9 @@ process.stdin.on('end', () => {
|
|||||||
// poll inventories
|
// poll inventories
|
||||||
setInterval(function(){
|
setInterval(function(){
|
||||||
// TODO: Make it work for players other than myself, don't error when inventory does not exist, check logistic request slots
|
// TODO: Make it work for players other than myself, don't error when inventory does not exist, check logistic request slots
|
||||||
console.log("/silent-command "+'local a=game.players["Danielv123"].get_inventory(defines.inventory.player_main).get_contents()local b=game.players["Danielv123"].get_quickbar().get_contents()local c={}local d="{inventory:{"for e,f in pairs(a)do d=d.."['+"'"+'"..e.."'+"'"+']:"..f..","end;for e,f in pairs(b)do d=d.."['+"'"+'"..e.."'+"'"+']:"..f..","end;d=d.."},requestSlots:{"for e,f in pairs(c)do d=d.."['+"'"+'"..e.."'+"'"+']:"..f..","end;d=d.."}}"game.write_file("'+pluginConfig.scriptOutputFileSubscription+'",d)');
|
// console.log("/silent-command "+'local a=game.players["Danielv123"].get_inventory(defines.inventory.player_main).get_contents()local b=game.players["Danielv123"].get_quickbar().get_contents()local c={}local d="{inventory:{"for e,f in pairs(a)do d=d.."['+"'"+'"..e.."'+"'"+']:"..f..","end;for e,f in pairs(b)do d=d.."['+"'"+'"..e.."'+"'"+']:"..f..","end;d=d.."},requestSlots:{"for e,f in pairs(c)do d=d.."['+"'"+'"..e.."'+"'"+']:"..f..","end;d=d.."}}"game.write_file("'+pluginConfig.scriptOutputFileSubscription+'",d)');
|
||||||
|
// console.log("Running inventory LUA")
|
||||||
|
console.log("/silent-command "+'local a=game.players["Danielv123"].get_inventory(defines.inventory.player_main).get_contents()local b=game.players["Danielv123"].get_quickbar().get_contents()local c={}for d=1,game.players["Danielv123"].force.character_logistic_slot_count do c[d]=game.players["Danielv123"].character.get_request_slot(d)end;local e="{inventory:{"for f,g in pairs(a)do e=e.."['+"'"+'"..f.."'+"'"+']:"..g..","end;for f,g in pairs(b)do e=e.."['+"'"+'"..f.."'+"'"+']:"..g..","end;e=e.."},requestSlots:{"for f,g in pairs(c)do e=e.."['+"'"+'"..g["name"].."'+"'"+']:"..g["count"]..", "end;e=e.."}}"game.write_file("'+pluginConfig.scriptOutputFileSubscription+'",e)')
|
||||||
/*
|
/*
|
||||||
needle.post(config.masterIP+':'+config.masterPort+'/api/editSlaveMeta', {slaveID: config.unique, password: config.clientPassword, meta: {UPS:UPS}}, function(err, resp) {
|
needle.post(config.masterIP+':'+config.masterPort+'/api/editSlaveMeta', {slaveID: config.unique, password: config.clientPassword, meta: {UPS:UPS}}, function(err, resp) {
|
||||||
// success?
|
// success?
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ local inventory = game.players["Danielv123"].get_inventory(defines.inventory.pla
|
|||||||
local quickbar = game.players["Danielv123"].get_quickbar().get_contents()
|
local quickbar = game.players["Danielv123"].get_quickbar().get_contents()
|
||||||
--[[ Get contents of requester slots into a table ]]
|
--[[ Get contents of requester slots into a table ]]
|
||||||
local requests = {}
|
local requests = {}
|
||||||
for i = 1, game.player.force.character_logistic_slot_count do
|
for i = 1, game.players["Danielv123"].force.character_logistic_slot_count do
|
||||||
requests[i] = game.players["Danielv123"].character.get_request_slot(i)
|
requests[i] = game.players["Danielv123"].character.get_request_slot(i)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -48,3 +48,19 @@ o = o.."}}"
|
|||||||
game.print(o)
|
game.print(o)
|
||||||
game.write_file("test.txt", o)
|
game.write_file("test.txt", o)
|
||||||
|
|
||||||
|
|
||||||
|
--[[
|
||||||
|
|
||||||
|
Minification procedure:
|
||||||
|
|
||||||
|
Run through https://mothereff.in/lua-minifier
|
||||||
|
Replace ' with '+"'"+'
|
||||||
|
Prepend /silent-command
|
||||||
|
enclose in ''
|
||||||
|
|
||||||
|
]]
|
||||||
|
|
||||||
|
-- minified strings
|
||||||
|
|
||||||
|
local a=game.players["Danielv123"].get_inventory(defines.inventory.player_main).get_contents()local b=game.players["Danielv123"].get_quickbar().get_contents()local c={}for d=1,game.players["Danielv123"].force.character_logistic_slot_count do c[d]=game.players["Danielv123"].character.get_request_slot(d)end;local e="{inventory:{"for f,g in pairs(a)do e=e.."['+"'"+'"..f.."'+"'"+']:"..g..","end;for f,g in pairs(b)do e=e.."['+"'"+'"..f.."'+"'"+']:"..g..","end;e=e.."},requestSlots:{"for f,g in pairs(c)do e=e.."['+"'"+'"..g["name"].."'+"'"+']:"..g["count"]..", "end;e=e.."}}"game.print(e)
|
||||||
|
local inventory = game.players["Danielv123"].get_inventory(defines.inventory.player_main).get_contents()local quickbar = game.players["Danielv123"].get_quickbar().get_contents()local requests = {}for i = 1, game.player.force.character_logistic_slot_count do requests[i] = game.players["Danielv123"].character.get_request_slot(i) end local o = "{inventory:{" for k,v in pairs(inventory) do o = o.."['+"'"+'"..k.."'+"'"+']:"..v.."," end for k,v in pairs(quickbar) do o = o.."['+"'"+'"..k.."'+"'"+']:"..v.."," end o = o.."},requestSlots:{" for k,v in pairs(requests) do o = o.."['+"'"+'"..v["name"].."'+"'"+']:"..v["count"]..", " end o = o.."}}" game.write_file("test.txt", o)
|
||||||
Reference in new issue
Block a user