diff --git a/client.js b/client.js index ae637ede..ef59cc74 100644 --- a/client.js +++ b/client.js @@ -107,6 +107,22 @@ setInterval(function() { } }, 3000) // COMBINATOR SIGNALS --------------------------------------------------------- +// get inventory from Master and RCON it to our slave +setInterval(function() { + needle.get(config.masterIP + ":" + config.masterPort + '/inventory', function(err, response, body){ + if(response && response.body) { + // Take the inventory we (hopefully) got and turn it into the format LUA accepts + // console.log(response.body) + var inventory = response.body; + var inventoryFrame = {}; + for(i = 0;i 0 then + if global.worldID then + table.insert(frame,1,{count=global.worldID,name="signal-srcid",type="virtual"}) + end table.insert(frame,{count=game.tick,name="signal-srctick",type="virtual"}) - game.write_file(TX_BUFFER_FILE, json:encode(frame).."\n", true) + game.write_file(TX_BUFFER_FILE, json:encode(frame).."\n", true, global.write_file_player or 0) -- Loopback for testing --AddFrameToRXBuffer(frame) @@ -409,8 +418,6 @@ function SetRXCombinators() if rxControl.valid then rxControl.parameters={parameters=frame} rxControl.enabled=true - else - table.remove(global.rxControls,i) end end end @@ -423,12 +430,36 @@ function ClearRXCombinators() for i,rxControl in pairs(global.rxControls) do if rxControl.valid then rxControl.enabled=false - else - table.remove(global.rxControls,i) end end end +function UpdateInvCombinators() + -- Update all inventory Combinators + -- Prepare a frame from the last inventory report, plus any virtuals + local invframe = {} + if global.worldID then + table.insert(invframe,{count=global.worldID,index=#invframe+1,signal={name="signal-localid",type="virtual"}}) + end + + local items = game.item_prototypes + if global.invdata then + for name,count in pairs(global.invdata) do + if items[name] then + invframe[#invframe+1] = {count=count,index=#invframe+1,signal={name=name,type="item"}} + end + end + end + + for i,invControl in pairs(global.invControls) do + if invControl.valid then + invControl.parameters={parameters=invframe} + invControl.enabled=true + end + end + +end + --[[ Remote Thing ]]-- remote.add_interface("clusterio", { @@ -465,4 +496,17 @@ remote.add_interface("clusterio", end return buffer end, + setFilePlayer = function(i) + global.write_file_player = i + end, + receiveInventory = function(jsoninvdata) + local invdata = json:decode(jsoninvdata) + -- invdata = {["iron-plates"]=1234,["copper-plates"]=5678,...} + global.invdata = invdata + UpdateInvCombinators() + end, + setWorldID = function(newid) + global.worldID = newid + UpdateInvCombinators() + end }) diff --git a/clusterio_0.0.2/data.lua b/clusterio_0.0.3/data.lua similarity index 88% rename from clusterio_0.0.2/data.lua rename to clusterio_0.0.3/data.lua index 6a3fb83a..6d09fc41 100644 --- a/clusterio_0.0.2/data.lua +++ b/clusterio_0.0.3/data.lua @@ -161,20 +161,20 @@ data:extend{ subgroup = "virtual-signal-clusterio", order = "e[clusterio]-[1srctick]" }, - --[[{ + { type = "virtual-signal", name = "signal-srcid", icon = "__base__/graphics/icons/signal/signal_grey.png", subgroup = "virtual-signal-clusterio", order = "e[clusterio]-[2srcid]" - },]] - --[[{ + }, + { type = "virtual-signal", name = "signal-localid", icon = "__base__/graphics/icons/signal/signal_grey.png", subgroup = "virtual-signal-clusterio", order = "e[clusterio]-[3localid]" - },]] + }, } -- TX Combinator @@ -239,3 +239,34 @@ data:extend{ requester_paste_multiplier = 1 }, } +-- Inventory Combinator +local inv = table.deepcopy(data.raw["constant-combinator"]["constant-combinator"]) +inv.name = INV_COMBINATOR_NAME +inv.minable.result = INV_COMBINATOR_NAME +inv.item_slot_count = 100 +data:extend{ + inv, + { + type = "item", + name = INV_COMBINATOR_NAME, + icon = inv.icon, + flags = {"goes-to-quickbar"}, + subgroup = "storage", + place_result=INV_COMBINATOR_NAME, + order = "a[items]-b["..INV_COMBINATOR_NAME.."]", + stack_size = 50, + }, + { + type = "recipe", + name = INV_COMBINATOR_NAME, + enabled = true, -- TODO do this on a tech somewhere + ingredients = + { + {"constant-combinator", 1}, + {"electronic-circuit", 3}, + {"advanced-circuit", 1} + }, + result = INV_COMBINATOR_NAME, + requester_paste_multiplier = 1 + }, +} diff --git a/clusterio_0.0.2/graphics/icons/none.png b/clusterio_0.0.3/graphics/icons/none.png similarity index 100% rename from clusterio_0.0.2/graphics/icons/none.png rename to clusterio_0.0.3/graphics/icons/none.png diff --git a/clusterio_0.0.2/info.json b/clusterio_0.0.3/info.json similarity index 93% rename from clusterio_0.0.2/info.json rename to clusterio_0.0.3/info.json index e9a8572e..08fd900d 100644 --- a/clusterio_0.0.2/info.json +++ b/clusterio_0.0.3/info.json @@ -2,7 +2,7 @@ { "name": "clusterio", "title": "Clusterio", -"version": "0.0.2", +"version": "0.0.3", "date": "19-08-2016", "author": "Danielv123 & Keyboardhack & justarandomgeek", "dependencies": ["base >= 0.13"], diff --git a/clusterio_0.0.2/json.lua b/clusterio_0.0.3/json.lua similarity index 100% rename from clusterio_0.0.2/json.lua rename to clusterio_0.0.3/json.lua diff --git a/clusterio_0.0.2/locale/en/item-names.cfg b/clusterio_0.0.3/locale/en/item-names.cfg similarity index 61% rename from clusterio_0.0.2/locale/en/item-names.cfg rename to clusterio_0.0.3/locale/en/item-names.cfg index 08399bce..d7561293 100644 --- a/clusterio_0.0.2/locale/en/item-names.cfg +++ b/clusterio_0.0.3/locale/en/item-names.cfg @@ -5,6 +5,7 @@ put-tank=Put tank get-tank=Get tank put-combinator=Transmit combinator get-combinator=Receive combinator +inventory-combinator=Inventory combinator [item-name] put-chest=Put chest @@ -13,3 +14,9 @@ put-tank=Put tank get-tank=Get tank put-combinator=Transmit combinator get-combinator=Receive combinator +inventory-combinator=Inventory combinator + +[virtual-signal-name] +signal-srctick=Source World Tick +signal-srcid=Source World ID +signal-localid=Local World ID