Add a Defragment button to Milo #36

Merged
Luca0208 merged 10 commits from develop-1.8-milo-defrag into develop-1.8 2020-05-10 01:48:40 -04:00
2 changed files with 25 additions and 13 deletions
Showing only changes of commit cedb807e89 - Show all commits

View File

@@ -293,30 +293,33 @@ end
-- provide a raw list of all the items in all storage chests
-- it might be beneficial to move this to the adapter class at some point and cache the raw item list in this class at some point
function Storage:listItemsRaw()
function Storage:listItemsRaw(throttle)
local res = {}
for _, v in pairs(self.nodes) do
if v.category == "storage" then
local chest = device[v.name]
throttle = throttle or Util.throttle()
for _, v in pairs(self.nodes) do
if v.category == "storage" then
kepler155c commented 2020-05-01 00:37:32 -04:00 (Migrated from github.com)
Review

Need to check if a chest is locked to specific items. There's 2 different ways to go here:

  1. the easy way - ignore locked chests.
  2. process the locked chests first - only pulling items in that match the filter.

My vote is for #2 :)

Need to check if a chest is locked to specific items. There's 2 different ways to go here: 1. the easy way - ignore locked chests. 2. process the locked chests first - only pulling items in that match the filter. My vote is for #2 :)
Luca0208 commented 2020-05-04 16:29:23 -04:00 (Migrated from github.com)
Review

Just so I get this right, when a chest is locked it would be enough to prioritise that chest when trying to find a target for the item?

Just so I get this right, when a chest is locked it would be enough to prioritise that chest when trying to find a target for the item?
local chest = device[v.name]
local items = chest.list()
for slot, item in pairs(items) do
items[slot] = itemDB:get(item, function() return chest.getItemMeta(slot) end)
end
res[v.name] = items
end
end
res[v.name] = items
throttle()
end
end
return res
return res
end
-- provide a list of items and which chests provide them
function Storage:listProviders()
function Storage:listProviders(throttle)
local res = {}
local rawItems = self:listItemsRaw()
local rawItems = self:listItemsRaw(throttle)
for chest, items in pairs(rawItems) do
for slot, item in pairs(items) do
@@ -331,8 +334,8 @@ function Storage:listProviders()
end
-- defrags the storage system
function Storage:defrag()
local items = self:listProviders()
function Storage:defrag(throttle)
local items = self:listProviders(throttle)
for _, providers in pairs(items) do
table.sort(providers, function(a, b)

View File

@@ -256,7 +256,8 @@ function page:eventHandler(event)
self:setFocus(self.statusBar.filter)
elseif event.type == 'defrag' then
context.storage:defrag()
self:defrag()
self:refresh(true)
elseif event.type == 'toggle_display' then
displayMode = (displayMode + 1) % 2
@@ -365,6 +366,14 @@ function page:refresh(force)
self.throttle:disable()
end
function page:defrag()
local throttle = function() self.throttle:update() end
self.throttle:enable()
context.storage:defrag(throttle)
self.throttle:disable()
end
function page:applyFilter()
local function filterItems(t, filter)
self.grid.sortColumn = Milo:getState('sortColumn') or 'count'