From 3f095ff5224816a691f0a68feb8384091089e9e7 Mon Sep 17 00:00:00 2001 From: kepler155c Date: Mon, 12 Nov 2018 02:03:37 -0500 Subject: [PATCH] milo logging --- farms/farmer.lua | 6 ++++-- milo/apis/milo.lua | 5 ++++- milo/apis/storage.lua | 34 +++++++++++++++++++++++++--------- milo/core/machines.lua | 1 + milo/plugins/activityView.lua | 4 ++++ milo/plugins/jobMonitor.lua | 6 +++--- 6 files changed, 41 insertions(+), 15 deletions(-) diff --git a/farms/farmer.lua b/farms/farmer.lua index 2a5a65d..877d1a0 100644 --- a/farms/farmer.lua +++ b/farms/farmer.lua @@ -144,11 +144,13 @@ local function harvest(blocks) local sensed = peripheral.call('right', 'sense') turtle.equip('right', 'minecraft:diamond_pickaxe') Util.filterInplace(sensed, function(s) - if s.displayName == 'item.tile.cactus' and Point.distance(b, s) < 6 then + if s.displayName == 'item.tile.cactus' then s.x = Util.round(s.x) + turtle.point.x s.z = Util.round(s.z) + turtle.point.z s.y = -1 - return true + if Point.distance(b, s) < 6 then + return true + end end end) Point.eachClosest(turtle.point, sensed, function(s) diff --git a/milo/apis/milo.lua b/milo/apis/milo.lua index b00749e..aadd885 100644 --- a/milo/apis/milo.lua +++ b/milo/apis/milo.lua @@ -85,7 +85,10 @@ function Milo:registerTask(task) end function Milo:showError(msg) - self.context.jobMonitor:showError(msg) + -- TODO: break dependency + if self.context.jobMonitor then + self.context.jobMonitor:showError(msg) + end end function Milo:getItem(items, inItem, ignoreDamage, ignoreNbtHash) diff --git a/milo/apis/storage.lua b/milo/apis/storage.lua index 070e538..da7cfac 100644 --- a/milo/apis/storage.lua +++ b/milo/apis/storage.lua @@ -216,11 +216,19 @@ function Storage:updateCache(adapter, key, count) adapter.dirty = true self.dirty = true else + -- TODO: all items imported should be updated in itemdb + -- error here if not local item = itemDB:get(key) or itemDB:splitKey(key) - entry = Util.shallowCopy(item) - entry.count = count - entry.key = key - adapter.cache[key] = entry + if item.displayName then + entry = Util.shallowCopy(item) + entry.count = count + entry.key = key + adapter.cache[key] = entry + else + -- TODO: somehow update itemdb with this maybe new item + adapter.dirty = true + self.dirty = true + end end else entry.count = entry.count + count @@ -230,6 +238,14 @@ function Storage:updateCache(adapter, key, count) end end +local function sn(name) + local t = { name:match(':(.+)_(%d+)$') } + if #t ~= 2 then + return name + end + return table.concat(table.unpack(t), '_') +end + function Storage:export(target, slot, count, item) local total = 0 local key = item.key or table.concat({ item.name, item.damage, item.nbtHash }, ':') @@ -237,9 +253,9 @@ function Storage:export(target, slot, count, item) local function provide(adapter) local amount = adapter:provide(item, count, slot, target or self.localName) if amount > 0 then --- _debug('EXT: %s(%d): %s -> %s%s', --- item.name, amount, adapter.name, direction or self.localName, --- slot and string.format('[%d]', slot) or '') + _G._debug('EXT: %s(%d): %s -> %s%s', + item.name, amount, sn(adapter.name), sn(target or self.localName), + slot and string.format('[%d]', slot) or '') self:updateCache(adapter, key, -amount) self:updateCache(self, key, -amount) end @@ -287,7 +303,7 @@ function Storage:import(source, slot, count, item) _G._debug('INS: %s(%d): %s[%d] -> %s', item.name, amount, - source or self.localName, slot, adapter.name) + sn(source or self.localName), slot, sn(adapter.name)) self:updateCache(adapter, key, amount) self:updateCache(self, key, amount) @@ -340,7 +356,7 @@ function Storage:trash(source, slot, count) local trashcan = Util.find(self.nodes, 'mtype', 'trashcan') if trashcan and trashcan.adapter and trashcan.adapter.online then -_G._debug('TRA: %s[%d] (%d)', source or self.localName, slot, count or 64) +_G._debug('TRA: %s[%d] (%d)', sn(source or self.localName), slot, count or 64) return trashcan.adapter.pullItems(source or self.localName, slot, count) end diff --git a/milo/core/machines.lua b/milo/core/machines.lua index f8cb0cc..388a651 100644 --- a/milo/core/machines.lua +++ b/milo/core/machines.lua @@ -435,6 +435,7 @@ _G._p2 = self.node } for _, page in pairs(self.wizard.pages) do if page.isValidType then + -- TODO: dedupe list local choice = page:isValidType(self.node) if choice then table.insert(choices, choice) diff --git a/milo/plugins/activityView.lua b/milo/plugins/activityView.lua index 7b48148..d313aa1 100644 --- a/milo/plugins/activityView.lua +++ b/milo/plugins/activityView.lua @@ -39,6 +39,10 @@ end UI:getPage('nodeWizard').wizard:add({ activity = activityWizardPage }) +if not monitor then + return +end + local page = UI.Window { parent = UI.Device { device = monitor.adapter, diff --git a/milo/plugins/jobMonitor.lua b/milo/plugins/jobMonitor.lua index bbd86ce..30ee1f7 100644 --- a/milo/plugins/jobMonitor.lua +++ b/milo/plugins/jobMonitor.lua @@ -8,7 +8,7 @@ local Util = require('util') local colors = _G.colors local context = Milo:getContext() local device = _G.device -local monNode = context.storage:getSingleNode('jobs') +local monitor = context.storage:getSingleNode('jobs') --[[ Configuration Screen ]] local template = @@ -39,7 +39,7 @@ end UI:getPage('nodeWizard').wizard:add({ jobs = jobsWizardPage }) --[[ Display ]] -if not monNode then +if not monitor then return end @@ -47,7 +47,7 @@ end local jobMonitor = UI.Page { parent = UI.Device { - device = monNode.adapter, + device = monitor.adapter, textScale = .5, }, grid = UI.Grid {