From 2af29c5d934ddc7122a487f31e425cdc149d6745 Mon Sep 17 00:00:00 2001 From: kepler155c Date: Tue, 13 Nov 2018 14:32:37 -0500 Subject: [PATCH] milo: refresh interval --- milo/apis/storage.lua | 1 + milo/plugins/brewingStandView.lua | 2 +- milo/plugins/refreshTask.lua | 17 +++++++++++++++-- milo/plugins/storageView.lua | 18 +++++++++++++++--- 4 files changed, 32 insertions(+), 6 deletions(-) diff --git a/milo/apis/storage.lua b/milo/apis/storage.lua index 20524e8..a18297f 100644 --- a/milo/apis/storage.lua +++ b/milo/apis/storage.lua @@ -177,6 +177,7 @@ function Storage:listItems(throttle) local timer = Timer() for _, adapter in self:onlineAdapters() do if adapter.dirty then + _G._debug('STORAGE: refreshing ' .. adapter.name) adapter:listItems(throttle) adapter.dirty = false end diff --git a/milo/plugins/brewingStandView.lua b/milo/plugins/brewingStandView.lua index b3036a4..d67a74e 100644 --- a/milo/plugins/brewingStandView.lua +++ b/milo/plugins/brewingStandView.lua @@ -13,7 +13,7 @@ Simply craft potions in the brewing stand as normal except for these conditions. When finished brewing, the recipe will be available upon refreshing. -Note that you do not need to import items from the brewing stand, this will be done automatically.]] +Note that you do not need to import items from the brewing stand or export blaze powder, this will be done automatically.]] local brewingStandView = UI.Window { title = 'Brewing Stand', diff --git a/milo/plugins/refreshTask.lua b/milo/plugins/refreshTask.lua index d3dcb05..9b89f81 100644 --- a/milo/plugins/refreshTask.lua +++ b/milo/plugins/refreshTask.lua @@ -8,9 +8,22 @@ local RefreshTask = { } function RefreshTask:cycle(context) - if os.clock() - context.storage.lastRefresh > 60 then - context.storage:refresh() + local now = os.clock() + + for node, adapter in context.storage:onlineAdapters() do + if node.refreshInterval then + if not adapter.lastRefresh or adapter.lastRefresh + node.refreshInterval < now then + _G._debug('REFRESHER: ' .. adapter.name) + context.storage.dirty = true + adapter.dirty = true + adapter.lastRefresh = now + end + end end + +-- if os.clock() - context.storage.lastRefresh > 60 then +-- context.storage:refresh() +-- end end Milo:registerTask(RefreshTask) diff --git a/milo/plugins/storageView.lua b/milo/plugins/storageView.lua index 1ba333d..b850510 100644 --- a/milo/plugins/storageView.lua +++ b/milo/plugins/storageView.lua @@ -9,23 +9,35 @@ local storageView = UI.Window { index = 2, backgroundColor = colors.cyan, form = UI.Form { - x = 1, y = 2, ex = -1, ey = -2, + x = 1, y = 1, ex = -1, ey = -2, manualControls = true, [1] = UI.TextEntry { formLabel = 'Priority', formKey = 'priority', help = 'Larger values get precedence', limit = 4, - validate = 'numeric', pruneEmpty = true, + validate = 'numeric', + shadowText = 'Numeric priority', }, [2] = UI.Checkbox { formLabel = 'Locked', formKey = 'lockWith', help = 'Locks chest to a single item type', - pruneEmpty = true, }, [3] = UI.Text { x = 16, ex = -2, y = 3, value = '', }, + [4] = UI.TextEntry { + formLabel = 'Refresh', formKey = 'refreshInterval', + help = 'Refresh periodically', + limit = 4, + validate = 'numeric', + shadowText = 'seconds between refresh', + }, + [5] = UI.TextArea { + x = 12, ex = -2, y = 5, + textColor = colors.yellow, + value = 'Only specify if you are manually taking items out of this inventory. Value should be > 10', + }, --[[ [4] = UI.Checkbox { formLabel = 'Void', formKey = 'voidExcess',