milo logging

This commit is contained in:
kepler155c
2018-11-12 02:03:37 -05:00
parent 9ee8ce9f33
commit 3f095ff522
6 changed files with 41 additions and 15 deletions

View File

@@ -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)

View File

@@ -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)

View File

@@ -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

View File

@@ -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)

View File

@@ -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,

View File

@@ -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 {