Move collate_stacks
This commit is contained in:
parent
439c357742
commit
b588060d3b
@ -165,14 +165,9 @@ local function server(command)
|
|||||||
|
|
||||||
return { moved = moved }
|
return { moved = moved }
|
||||||
elseif command.type == "search" then
|
elseif command.type == "search" then
|
||||||
local matching_items = d.map(search(command.query, command.threshold), function(x) return x.item end)
|
return w.collate_stacks(d.map(search(command.query, command.threshold), function(x) return x.item end))
|
||||||
local out = {}
|
elseif command.type == "list" then
|
||||||
for _, stack in pairs(matching_items) do
|
return index
|
||||||
local i = w.get_internal_identifier(stack)
|
|
||||||
if out[i] then out[i].count = out[i].count + stack.count
|
|
||||||
else out[i] = stack end
|
|
||||||
end
|
|
||||||
return out
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
13
lib.lua
13
lib.lua
@ -182,6 +182,17 @@ local function collate(items)
|
|||||||
return ret
|
return ret
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Functions like "collate" but on itemstacks (adds their counts)
|
||||||
|
local function collate_stacks(s)
|
||||||
|
local out = {}
|
||||||
|
for _, stack in pairs(matching_items) do
|
||||||
|
local i = w.get_internal_identifier(stack)
|
||||||
|
if out[i] then out[i].count = out[i].count + stack.count
|
||||||
|
else out[i] = stack end
|
||||||
|
end
|
||||||
|
return out
|
||||||
|
end
|
||||||
|
|
||||||
-- Checks whether "needs"'s (a collate-formatted table) values are all greater than those of "has"
|
-- Checks whether "needs"'s (a collate-formatted table) values are all greater than those of "has"
|
||||||
local function satisfied(needs, has)
|
local function satisfied(needs, has)
|
||||||
local good = true
|
local good = true
|
||||||
@ -229,4 +240,4 @@ local function init()
|
|||||||
d.map(find_peripherals(function(type, name, wrapped) return type == "modem" end), function(p) rednet.open(p.name) end)
|
d.map(find_peripherals(function(type, name, wrapped) return type == "modem" end), function(p) rednet.open(p.name) end)
|
||||||
end
|
end
|
||||||
|
|
||||||
return { errors = errors, serve = serve, query_by_ID = query_by_ID, query_by_type = query_by_type, get_internal_identifier = get_internal_identifier, load_config = load_config, find_peripherals = find_peripherals, init = init, collate = collate, satisfied = satisfied }
|
return { errors = errors, serve = serve, query_by_ID = query_by_ID, query_by_type = query_by_type, get_internal_identifier = get_internal_identifier, load_config = load_config, find_peripherals = find_peripherals, init = init, collate = collate, satisfied = satisfied, collate_stacks = collate_stacks }
|
Loading…
Reference in New Issue
Block a user