mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-11 23:04:52 +09:00
Add Inventory Combinator which reports the last inventory reported by the external code.
This commit is contained in:
1 parent
09feb085ef
commit
5e65fa5208
3 files changed
+69
-3
No files matched your search
@@ -21,7 +21,7 @@ OUTPUT_TANK_ICON_PATH = nil
|
||||
MAX_RX_BUFFER_SIZE = 40 -- slightly more than one second
|
||||
RX_COMBINATOR_NAME = "get-combinator"
|
||||
TX_COMBINATOR_NAME = "put-combinator"
|
||||
|
||||
INV_COMBINATOR_NAME = "inventory-combinator"
|
||||
|
||||
OUTPUT_FILE = "output.txt"
|
||||
ORDER_FILE = "orders.txt"
|
||||
|
||||
@@ -47,6 +47,9 @@ function AddEntity(entity)
|
||||
table.insert(global.txControls, entity.get_or_create_control_behavior())
|
||||
elseif entity.name == RX_COMBINATOR_NAME then
|
||||
table.insert(global.rxControls, entity.get_or_create_control_behavior())
|
||||
entity.operable=false
|
||||
elseif entity.name == INV_COMBINATOR_NAME then
|
||||
table.insert(global.invControls, entity.get_or_create_control_behavior())
|
||||
entity.operable=false
|
||||
end
|
||||
end
|
||||
@@ -90,7 +93,7 @@ end)
|
||||
|
||||
|
||||
script.on_event(defines.events.on_tick, function(event)
|
||||
|
||||
|
||||
global.inputChests = global.inputChests or {}
|
||||
global.outputChests = global.outputChests or {}
|
||||
global.inputTanks = global.inputTanks or {}
|
||||
@@ -99,7 +102,7 @@ script.on_event(defines.events.on_tick, function(event)
|
||||
global.inputList = global.inputList or {}
|
||||
global.rxControls = global.rxControls or {}
|
||||
global.txControls = global.txControls or {}
|
||||
|
||||
global.invControls = global.invControls or {}
|
||||
|
||||
-- TX Combinators must run every tick to catch single pulses
|
||||
HandleTXCombinators()
|
||||
@@ -429,6 +432,32 @@ function ClearRXCombinators()
|
||||
end
|
||||
end
|
||||
|
||||
function UpdateInvCombinators()
|
||||
-- Update all inventory Combinators
|
||||
-- Prepare a frame from the last inventory report, plus any virtuals
|
||||
local invframe = {
|
||||
--TODO: virtual signals here, localid, possibly others
|
||||
}
|
||||
local items = game.item_prototypes
|
||||
if global.invdata then
|
||||
for name,count in pairs(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
|
||||
else
|
||||
table.remove(global.invControls,i)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--[[ Remote Thing ]]--
|
||||
remote.add_interface("clusterio",
|
||||
{
|
||||
@@ -468,4 +497,10 @@ remote.add_interface("clusterio",
|
||||
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
|
||||
})
|
||||
@@ -238,4 +238,35 @@ data:extend{
|
||||
result = RX_COMBINATOR_NAME,
|
||||
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
|
||||
},
|
||||
}
|
||||
Reference in new issue
Block a user