milo logging
This commit is contained in:
@@ -144,11 +144,13 @@ local function harvest(blocks)
|
|||||||
local sensed = peripheral.call('right', 'sense')
|
local sensed = peripheral.call('right', 'sense')
|
||||||
turtle.equip('right', 'minecraft:diamond_pickaxe')
|
turtle.equip('right', 'minecraft:diamond_pickaxe')
|
||||||
Util.filterInplace(sensed, function(s)
|
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.x = Util.round(s.x) + turtle.point.x
|
||||||
s.z = Util.round(s.z) + turtle.point.z
|
s.z = Util.round(s.z) + turtle.point.z
|
||||||
s.y = -1
|
s.y = -1
|
||||||
return true
|
if Point.distance(b, s) < 6 then
|
||||||
|
return true
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
Point.eachClosest(turtle.point, sensed, function(s)
|
Point.eachClosest(turtle.point, sensed, function(s)
|
||||||
|
|||||||
@@ -85,7 +85,10 @@ function Milo:registerTask(task)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function Milo:showError(msg)
|
function Milo:showError(msg)
|
||||||
self.context.jobMonitor:showError(msg)
|
-- TODO: break dependency
|
||||||
|
if self.context.jobMonitor then
|
||||||
|
self.context.jobMonitor:showError(msg)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function Milo:getItem(items, inItem, ignoreDamage, ignoreNbtHash)
|
function Milo:getItem(items, inItem, ignoreDamage, ignoreNbtHash)
|
||||||
|
|||||||
@@ -216,11 +216,19 @@ function Storage:updateCache(adapter, key, count)
|
|||||||
adapter.dirty = true
|
adapter.dirty = true
|
||||||
self.dirty = true
|
self.dirty = true
|
||||||
else
|
else
|
||||||
|
-- TODO: all items imported should be updated in itemdb
|
||||||
|
-- error here if not
|
||||||
local item = itemDB:get(key) or itemDB:splitKey(key)
|
local item = itemDB:get(key) or itemDB:splitKey(key)
|
||||||
entry = Util.shallowCopy(item)
|
if item.displayName then
|
||||||
entry.count = count
|
entry = Util.shallowCopy(item)
|
||||||
entry.key = key
|
entry.count = count
|
||||||
adapter.cache[key] = entry
|
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
|
end
|
||||||
else
|
else
|
||||||
entry.count = entry.count + count
|
entry.count = entry.count + count
|
||||||
@@ -230,6 +238,14 @@ function Storage:updateCache(adapter, key, count)
|
|||||||
end
|
end
|
||||||
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)
|
function Storage:export(target, slot, count, item)
|
||||||
local total = 0
|
local total = 0
|
||||||
local key = item.key or table.concat({ item.name, item.damage, item.nbtHash }, ':')
|
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 function provide(adapter)
|
||||||
local amount = adapter:provide(item, count, slot, target or self.localName)
|
local amount = adapter:provide(item, count, slot, target or self.localName)
|
||||||
if amount > 0 then
|
if amount > 0 then
|
||||||
-- _debug('EXT: %s(%d): %s -> %s%s',
|
_G._debug('EXT: %s(%d): %s -> %s%s',
|
||||||
-- item.name, amount, adapter.name, direction or self.localName,
|
item.name, amount, sn(adapter.name), sn(target or self.localName),
|
||||||
-- slot and string.format('[%d]', slot) or '')
|
slot and string.format('[%d]', slot) or '')
|
||||||
self:updateCache(adapter, key, -amount)
|
self:updateCache(adapter, key, -amount)
|
||||||
self:updateCache(self, key, -amount)
|
self:updateCache(self, key, -amount)
|
||||||
end
|
end
|
||||||
@@ -287,7 +303,7 @@ function Storage:import(source, slot, count, item)
|
|||||||
|
|
||||||
_G._debug('INS: %s(%d): %s[%d] -> %s',
|
_G._debug('INS: %s(%d): %s[%d] -> %s',
|
||||||
item.name, amount,
|
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(adapter, key, amount)
|
||||||
self:updateCache(self, 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')
|
local trashcan = Util.find(self.nodes, 'mtype', 'trashcan')
|
||||||
if trashcan and trashcan.adapter and trashcan.adapter.online then
|
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)
|
return trashcan.adapter.pullItems(source or self.localName, slot, count)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -435,6 +435,7 @@ _G._p2 = self.node
|
|||||||
}
|
}
|
||||||
for _, page in pairs(self.wizard.pages) do
|
for _, page in pairs(self.wizard.pages) do
|
||||||
if page.isValidType then
|
if page.isValidType then
|
||||||
|
-- TODO: dedupe list
|
||||||
local choice = page:isValidType(self.node)
|
local choice = page:isValidType(self.node)
|
||||||
if choice then
|
if choice then
|
||||||
table.insert(choices, choice)
|
table.insert(choices, choice)
|
||||||
|
|||||||
@@ -39,6 +39,10 @@ end
|
|||||||
|
|
||||||
UI:getPage('nodeWizard').wizard:add({ activity = activityWizardPage })
|
UI:getPage('nodeWizard').wizard:add({ activity = activityWizardPage })
|
||||||
|
|
||||||
|
if not monitor then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
local page = UI.Window {
|
local page = UI.Window {
|
||||||
parent = UI.Device {
|
parent = UI.Device {
|
||||||
device = monitor.adapter,
|
device = monitor.adapter,
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ local Util = require('util')
|
|||||||
local colors = _G.colors
|
local colors = _G.colors
|
||||||
local context = Milo:getContext()
|
local context = Milo:getContext()
|
||||||
local device = _G.device
|
local device = _G.device
|
||||||
local monNode = context.storage:getSingleNode('jobs')
|
local monitor = context.storage:getSingleNode('jobs')
|
||||||
|
|
||||||
--[[ Configuration Screen ]]
|
--[[ Configuration Screen ]]
|
||||||
local template =
|
local template =
|
||||||
@@ -39,7 +39,7 @@ end
|
|||||||
UI:getPage('nodeWizard').wizard:add({ jobs = jobsWizardPage })
|
UI:getPage('nodeWizard').wizard:add({ jobs = jobsWizardPage })
|
||||||
|
|
||||||
--[[ Display ]]
|
--[[ Display ]]
|
||||||
if not monNode then
|
if not monitor then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -47,7 +47,7 @@ end
|
|||||||
|
|
||||||
local jobMonitor = UI.Page {
|
local jobMonitor = UI.Page {
|
||||||
parent = UI.Device {
|
parent = UI.Device {
|
||||||
device = monNode.adapter,
|
device = monitor.adapter,
|
||||||
textScale = .5,
|
textScale = .5,
|
||||||
},
|
},
|
||||||
grid = UI.Grid {
|
grid = UI.Grid {
|
||||||
|
|||||||
Reference in New Issue
Block a user