rename debug function + milo wip
This commit is contained in:
@@ -110,7 +110,7 @@ function ChestAdapter:listItems(throttle)
|
|||||||
return items
|
return items
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
debug(m)
|
_debug(m)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -102,7 +102,7 @@ function MEAdapter:refresh()
|
|||||||
itemDB:flush()
|
itemDB:flush()
|
||||||
|
|
||||||
if not s and m then
|
if not s and m then
|
||||||
debug(m)
|
_debug(m)
|
||||||
end
|
end
|
||||||
|
|
||||||
if s and not failed and hasItems and self.items and not Util.empty(self.items) then
|
if s and not failed and hasItems and self.items and not Util.empty(self.items) then
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ function RefinedAdapter:listItems(throttle)
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
if not s and m then
|
if not s and m then
|
||||||
debug(m)
|
_debug(m)
|
||||||
end
|
end
|
||||||
|
|
||||||
itemDB:flush()
|
itemDB:flush()
|
||||||
|
|||||||
@@ -1210,8 +1210,8 @@ local function learnRecipe(page)
|
|||||||
end
|
end
|
||||||
|
|
||||||
if not recipe then
|
if not recipe then
|
||||||
debug(results)
|
_debug(results)
|
||||||
debug(newRecipe)
|
_debug(newRecipe)
|
||||||
error('Failed - view system log')
|
error('Failed - view system log')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -13,9 +13,9 @@ mon.clear()
|
|||||||
mon.setTextScale(.5)
|
mon.setTextScale(.5)
|
||||||
mon.setCursorPos(1, 1)
|
mon.setCursorPos(1, 1)
|
||||||
|
|
||||||
local oldDebug = _G.debug
|
local oldDebug = _G._debug
|
||||||
|
|
||||||
_G.debug = function(...)
|
_G._debug = function(...)
|
||||||
local oldTerm = term.redirect(mon)
|
local oldTerm = term.redirect(mon)
|
||||||
Util.print(...)
|
Util.print(...)
|
||||||
term.redirect(oldTerm)
|
term.redirect(oldTerm)
|
||||||
@@ -30,4 +30,4 @@ repeat
|
|||||||
end
|
end
|
||||||
until e == 'terminate'
|
until e == 'terminate'
|
||||||
|
|
||||||
_G.debug = oldDebug
|
_G._debug = oldDebug
|
||||||
|
|||||||
@@ -4,54 +4,17 @@
|
|||||||
Using a turtle allows for crafting of items eliminating the need for AE/RS
|
Using a turtle allows for crafting of items eliminating the need for AE/RS
|
||||||
molecular assemblers / crafters.
|
molecular assemblers / crafters.
|
||||||
|
|
||||||
Inventory setup:
|
|
||||||
Turtle/computer must be touching at least one type of inventory
|
|
||||||
|
|
||||||
Generic inventory block such as:
|
|
||||||
Vanilla chest
|
|
||||||
RFTools modular storage
|
|
||||||
Storage drawers controller
|
|
||||||
and many others...
|
|
||||||
|
|
||||||
Applied energistics
|
|
||||||
AE cable or interface (depending upon AE/MC version)
|
|
||||||
|
|
||||||
Refined storage
|
|
||||||
TODO: add required block
|
|
||||||
|
|
||||||
Turtle crafting:
|
Turtle crafting:
|
||||||
1. The turtle must have a crafting table equipped.
|
1. The turtle must have a crafting table equipped.
|
||||||
2. Equip the turtle with an introspection module.
|
2. Equip the turtle with an introspection module.
|
||||||
|
|
||||||
Controller (optional):
|
|
||||||
Provides the ability to request crafting from AE / RS
|
|
||||||
|
|
||||||
Applied Energistics
|
|
||||||
In versions 1.7x, AE can be used for both inventory access and crafting
|
|
||||||
requests.
|
|
||||||
|
|
||||||
In versions 1.8+, AE can only be used to request crafting.
|
|
||||||
|
|
||||||
Refined Storage
|
|
||||||
In versions 1.8x, inventory access works depending upon version.
|
|
||||||
|
|
||||||
Turtle/computer must be touching an interface for inventory access. If only
|
|
||||||
requesting crafting, the controller must be either be touching or connected
|
|
||||||
via CC cables.
|
|
||||||
|
|
||||||
Configuration:
|
Configuration:
|
||||||
Configuration file is usr/config/milo
|
Configuration file is usr/config/milo
|
||||||
|
|
||||||
monitor : valid options include:
|
monitor : valid options include:
|
||||||
type/monitor - will use the first monitor found
|
type/monitor - will use the first monitor found
|
||||||
side/north - specify a direction (top/bottom/east/etc)
|
side/north - specify a direction (top/bottom/east/etc)
|
||||||
name/monitor_1 - specify the exact name of the peripheral
|
name/monitor_1 - specify the exact name of the peripheral
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
-- Internal
|
|
||||||
Imports are at < 20
|
|
||||||
|
|
||||||
]]--
|
]]--
|
||||||
|
|
||||||
_G.requireInjector(_ENV)
|
_G.requireInjector(_ENV)
|
||||||
@@ -137,9 +100,9 @@ table.sort(context.tasks, function(a, b)
|
|||||||
return a.priority < b.priority
|
return a.priority < b.priority
|
||||||
end)
|
end)
|
||||||
|
|
||||||
debug('Tasks\n-----')
|
_debug('Tasks\n-----')
|
||||||
for _, task in ipairs(context.tasks) do
|
for _, task in ipairs(context.tasks) do
|
||||||
debug('%d: %s', task.priority, task.name)
|
_debug('%d: %s', task.priority, task.name)
|
||||||
end
|
end
|
||||||
|
|
||||||
Milo:clearGrid()
|
Milo:clearGrid()
|
||||||
@@ -155,7 +118,8 @@ Event.onInterval(5, function()
|
|||||||
for _, task in ipairs(context.tasks) do
|
for _, task in ipairs(context.tasks) do
|
||||||
local s, m = pcall(function() task:cycle(context) end)
|
local s, m = pcall(function() task:cycle(context) end)
|
||||||
if not s and m then
|
if not s and m then
|
||||||
Util.print(task.name)
|
_debug(task.name .. ' crashed')
|
||||||
|
Util.print(task.name .. ' crashed')
|
||||||
error(m)
|
error(m)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -301,48 +301,48 @@ end
|
|||||||
|
|
||||||
_G.p4 = Event
|
_G.p4 = Event
|
||||||
|
|
||||||
debug(options.slot)
|
_debug(options.slot)
|
||||||
if options.slot.value then
|
if options.slot.value then
|
||||||
debug('Transfer items initialized')
|
_debug('Transfer items initialized')
|
||||||
Event.addRoutine(function()
|
Event.addRoutine(function()
|
||||||
while true do
|
while true do
|
||||||
debug('sleeping')
|
_debug('sleeping')
|
||||||
os.sleep(1.5)
|
os.sleep(1.5)
|
||||||
local neural = device.neuralInterface
|
local neural = device.neuralInterface
|
||||||
debug(neural)
|
_debug(neural)
|
||||||
if neural and neural.getInventory then
|
if neural and neural.getInventory then
|
||||||
local item = neural.getInventory().getItem(options.slot.value)
|
local item = neural.getInventory().getItem(options.slot.value)
|
||||||
if item then
|
if item then
|
||||||
debug('depositing')
|
_debug('depositing')
|
||||||
page:sendRequest({ request = 'deposit', slot = options.slot.value })
|
page:sendRequest({ request = 'deposit', slot = options.slot.value })
|
||||||
-- local item =
|
-- local item =
|
||||||
-- TODO: update count for this one item
|
-- TODO: update count for this one item
|
||||||
-- page.grid:draw() page:sync()
|
-- page.grid:draw() page:sync()
|
||||||
else
|
else
|
||||||
debug('empty')
|
_debug('empty')
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
debug('missing Introspection module')
|
_debug('missing Introspection module')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
if options.shield.value then
|
if options.shield.value then
|
||||||
debug('Transfer items initialized')
|
_debug('Transfer items initialized')
|
||||||
Event.onInterval(2, function()
|
Event.onInterval(2, function()
|
||||||
local neural = device.neuralInterface
|
local neural = device.neuralInterface
|
||||||
if neural and neural.getEquipment then
|
if neural and neural.getEquipment then
|
||||||
local item = neural.getEquipment().getItem(SHIELD_SLOT)
|
local item = neural.getEquipment().getItem(SHIELD_SLOT)
|
||||||
if item then
|
if item then
|
||||||
debug('depositing')
|
_debug('depositing')
|
||||||
page:sendRequest({ request = 'deposit', slot = 'shield' })
|
page:sendRequest({ request = 'deposit', slot = 'shield' })
|
||||||
-- local item =
|
-- local item =
|
||||||
-- TODO: update count for this one item
|
-- TODO: update count for this one item
|
||||||
-- page.grid:draw() page:sync()
|
-- page.grid:draw() page:sync()
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
debug('missing Introspection module')
|
_debug('missing Introspection module')
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -113,24 +113,50 @@ function Milo:getItemWithQty(res, ignoreDamage, ignoreNbtHash)
|
|||||||
return item
|
return item
|
||||||
end
|
end
|
||||||
|
|
||||||
function Milo:clearGrid()
|
function Milo:getMatches(items, item, ignoreDamage, ignoreNbtHash)
|
||||||
local function clear()
|
local t = { }
|
||||||
turtle.eachFilledSlot(function(slot)
|
|
||||||
self.context.storage:import(self.context.localName, slot.index, slot.count, slot)
|
|
||||||
end)
|
|
||||||
|
|
||||||
for i = 1, 16 do
|
if not ignoreDamage and not ignoreNbtHash then
|
||||||
if turtle.getItemCount(i) ~= 0 then
|
local key = item.key or Milo:uniqueKey(item)
|
||||||
return false
|
local e = items[key]
|
||||||
|
if e then
|
||||||
|
t[key] = Util.shallowCopy(e)
|
||||||
|
end
|
||||||
|
|
||||||
|
else
|
||||||
|
for k,v in pairs(items) do
|
||||||
|
if item.name == v.name and
|
||||||
|
(ignoreDamage or item.damage == v.damage) and
|
||||||
|
(ignoreNbtHash or item.nbtHash == v.nbtHash) then
|
||||||
|
local e = t[k]
|
||||||
|
if not e then
|
||||||
|
t[k] = Util.shallowCopy(v)
|
||||||
|
else
|
||||||
|
e.count = e.count + item.count
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return true
|
|
||||||
end
|
end
|
||||||
return clear() or clear()
|
|
||||||
|
return t
|
||||||
|
end
|
||||||
|
|
||||||
|
function Milo:clearGrid()
|
||||||
|
turtle.eachFilledSlot(function(slot)
|
||||||
|
self.context.storage:import(self.context.localName, slot.index, slot.count, slot)
|
||||||
|
end)
|
||||||
|
|
||||||
|
for i = 1, 16 do
|
||||||
|
if turtle.getItemCount(i) ~= 0 then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
function Milo:getTurtleInventory()
|
function Milo:getTurtleInventory()
|
||||||
local list = { }
|
local list = { }
|
||||||
|
|
||||||
for i = 1,16 do
|
for i = 1,16 do
|
||||||
local item = self.context.introspectionModule.getInventory().getItemMeta(i)
|
local item = self.context.introspectionModule.getInventory().getItemMeta(i)
|
||||||
if item then
|
if item then
|
||||||
|
|||||||
@@ -26,12 +26,12 @@ listCount = 0,
|
|||||||
self.localName = modem.getNameLocal()
|
self.localName = modem.getNameLocal()
|
||||||
|
|
||||||
Event.on({ 'device_attach', 'device_detach' }, function(e, dev)
|
Event.on({ 'device_attach', 'device_detach' }, function(e, dev)
|
||||||
debug('%s: %s', e, tostring(dev))
|
_debug('%s: %s', e, tostring(dev))
|
||||||
self:initStorage()
|
self:initStorage()
|
||||||
end)
|
end)
|
||||||
Event.onInterval(15, function()
|
Event.onInterval(15, function()
|
||||||
self:showStorage()
|
self:showStorage()
|
||||||
debug('STORAGE: cache: %d/%d', self.hits, self.misses)
|
_debug('STORAGE: cache: %d/%d', self.hits, self.misses)
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -44,11 +44,11 @@ function Storage:showStorage()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
if #t > 0 then
|
if #t > 0 then
|
||||||
debug('Adapter:')
|
_debug('Adapter:')
|
||||||
for _, k in pairs(t) do
|
for _, k in pairs(t) do
|
||||||
debug(' offline: ' .. k)
|
_debug(' offline: ' .. k)
|
||||||
end
|
end
|
||||||
debug('')
|
_debug('')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -56,7 +56,7 @@ function Storage:setOnline(online)
|
|||||||
if online ~= self.storageOnline then
|
if online ~= self.storageOnline then
|
||||||
self.storageOnline = online
|
self.storageOnline = online
|
||||||
os.queueEvent(self.storageOnline and 'storage_online' or 'storage_offline', online)
|
os.queueEvent(self.storageOnline and 'storage_online' or 'storage_offline', online)
|
||||||
debug('Storage: %s', self.storageOnline and 'online' or 'offline')
|
_debug('Storage: %s', self.storageOnline and 'online' or 'offline')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -67,7 +67,7 @@ end
|
|||||||
function Storage:initStorage()
|
function Storage:initStorage()
|
||||||
local online = true
|
local online = true
|
||||||
|
|
||||||
debug('Initializing storage')
|
_debug('Initializing storage')
|
||||||
for k,v in pairs(self.remoteDefaults) do
|
for k,v in pairs(self.remoteDefaults) do
|
||||||
if v.adapter then
|
if v.adapter then
|
||||||
v.adapter.online = not not device[k]
|
v.adapter.online = not not device[k]
|
||||||
@@ -136,7 +136,7 @@ end
|
|||||||
|
|
||||||
function Storage:refresh(throttle)
|
function Storage:refresh(throttle)
|
||||||
self.dirty = true
|
self.dirty = true
|
||||||
debug('STORAGE: Forcing full refresh')
|
_debug('STORAGE: Forcing full refresh')
|
||||||
for _, adapter in self:onlineAdapters() do
|
for _, adapter in self:onlineAdapters() do
|
||||||
adapter.dirty = true
|
adapter.dirty = true
|
||||||
end
|
end
|
||||||
@@ -149,9 +149,8 @@ function Storage:listItems(throttle)
|
|||||||
return self.items
|
return self.items
|
||||||
end
|
end
|
||||||
self.listCount = self.listCount + 1
|
self.listCount = self.listCount + 1
|
||||||
--debug(self.listCount)
|
--_debug(self.listCount)
|
||||||
|
|
||||||
-- todo: only listItems from dirty remotes
|
|
||||||
local ct = os.clock()
|
local ct = os.clock()
|
||||||
local cache = { }
|
local cache = { }
|
||||||
local items = { }
|
local items = { }
|
||||||
@@ -159,7 +158,7 @@ local ct = os.clock()
|
|||||||
|
|
||||||
for _, adapter in self:onlineAdapters() do
|
for _, adapter in self:onlineAdapters() do
|
||||||
if adapter.dirty then
|
if adapter.dirty then
|
||||||
debug('STORAGE: refresh: ' .. adapter.name)
|
_debug('STORAGE: refresh: ' .. adapter.name)
|
||||||
adapter:listItems(throttle)
|
adapter:listItems(throttle)
|
||||||
adapter.dirty = false
|
adapter.dirty = false
|
||||||
end
|
end
|
||||||
@@ -180,7 +179,7 @@ debug('STORAGE: refresh: ' .. adapter.name)
|
|||||||
throttle()
|
throttle()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
debug('STORAGE: refresh in ' .. (os.clock() - ct))
|
_debug('STORAGE: refresh in ' .. (os.clock() - ct))
|
||||||
|
|
||||||
self.dirty = false
|
self.dirty = false
|
||||||
self.cache = cache
|
self.cache = cache
|
||||||
@@ -201,7 +200,7 @@ function Storage:provide(item, qty, slot, direction)
|
|||||||
local amount = adapter:provide(item, qty, slot, direction or self.localName)
|
local amount = adapter:provide(item, qty, slot, direction or self.localName)
|
||||||
if amount > 0 then
|
if amount > 0 then
|
||||||
self.hits = self.hits + 1
|
self.hits = self.hits + 1
|
||||||
debug('EXT: %s(%d): %s -> %s%s',
|
_debug('EXT: %s(%d): %s -> %s%s',
|
||||||
item.name, amount, adapter.name, direction or self.localName,
|
item.name, amount, adapter.name, direction or self.localName,
|
||||||
slot and string.format('[%d]', slot) or '')
|
slot and string.format('[%d]', slot) or '')
|
||||||
self.dirty = true
|
self.dirty = true
|
||||||
@@ -215,13 +214,13 @@ function Storage:provide(item, qty, slot, direction)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
debug('STORAGE: MISS: %s - %d', key, qty)
|
_debug('STORAGE: MISS: %s - %d', key, qty)
|
||||||
self.misses = self.misses + 1
|
self.misses = self.misses + 1
|
||||||
|
|
||||||
for _, adapter in self:onlineAdapters() do
|
for _, adapter in self:onlineAdapters() do
|
||||||
local amount = adapter:provide(item, qty, slot, direction or self.localName)
|
local amount = adapter:provide(item, qty, slot, direction or self.localName)
|
||||||
if amount > 0 then
|
if amount > 0 then
|
||||||
debug('EXT: %s(%d): %s -> %s%s',
|
_debug('EXT: %s(%d): %s -> %s%s',
|
||||||
item.name, amount, adapter.name, direction or self.localName,
|
item.name, amount, adapter.name, direction or self.localName,
|
||||||
slot and string.format('[%d]', slot) or '')
|
slot and string.format('[%d]', slot) or '')
|
||||||
self.dirty = true
|
self.dirty = true
|
||||||
@@ -240,7 +239,7 @@ end
|
|||||||
function Storage:trash(source, slot, count)
|
function Storage:trash(source, slot, count)
|
||||||
local trashcan = Util.find(self.remoteDefaults, 'mtype', 'trashcan')
|
local trashcan = Util.find(self.remoteDefaults, 'mtype', 'trashcan')
|
||||||
if trashcan and trashcan.adapter and trashcan.adapter.online then
|
if trashcan and trashcan.adapter and trashcan.adapter.online then
|
||||||
debug('TRA: %s[%d] (%d)', source or self.localName, slot, count or 64)
|
_debug('TRA: %s[%d] (%d)', 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
|
||||||
return 0
|
return 0
|
||||||
@@ -267,7 +266,8 @@ function Storage:insert(slot, qty, toSlot, item, source)
|
|||||||
local function insert(adapter)
|
local function insert(adapter)
|
||||||
local amount = adapter:insert(slot, qty, toSlot, source or self.localName)
|
local amount = adapter:insert(slot, qty, toSlot, source or self.localName)
|
||||||
if amount > 0 then
|
if amount > 0 then
|
||||||
debug('INS: %s(%d): %s[%d] -> %s',
|
-- TODO: change debug to _debug
|
||||||
|
_debug('INS: %s(%d): %s[%d] -> %s',
|
||||||
item.name, amount,
|
item.name, amount,
|
||||||
source or self.localName, slot, adapter.name)
|
source or self.localName, slot, adapter.name)
|
||||||
self.dirty = true
|
self.dirty = true
|
||||||
@@ -300,8 +300,7 @@ debug('INS: %s(%d): %s[%d] -> %s',
|
|||||||
end
|
end
|
||||||
|
|
||||||
if self.cache[key] then -- is this item in some chest
|
if self.cache[key] then -- is this item in some chest
|
||||||
-- low to high priority if the chest already contains that item
|
for _, adapter in self:onlineAdapters() do
|
||||||
for _, adapter in self:onlineAdapters(true --[[ reversed ]]) do
|
|
||||||
if qty <= 0 then
|
if qty <= 0 then
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -105,10 +105,21 @@ local function machineCraft(recipe, inventoryAdapter, machineName, request, coun
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local xferred = { }
|
||||||
for k,v in pairs(recipe.ingredients) do
|
for k,v in pairs(recipe.ingredients) do
|
||||||
if inventoryAdapter:provide(splitKey(v), count, k, machineName) ~= count then
|
local provided = inventoryAdapter:provide(splitKey(v), count, k, machineName)
|
||||||
-- TODO: suck em back out
|
xferred[k] = {
|
||||||
request.status = 'unknown error'
|
key = v,
|
||||||
|
count = provided,
|
||||||
|
}
|
||||||
|
if provided ~= count then
|
||||||
|
-- take back out whatever we put in
|
||||||
|
for k2,v2 in pairs(xferred) do
|
||||||
|
if v2.count > 0 then
|
||||||
|
inventoryAdapter:import(machineName, k2, v2.count, splitKey(v2.key))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
request.status = 'Invalid recipe'
|
||||||
request.statusCode = Craft.STATUS_ERROR
|
request.statusCode = Craft.STATUS_ERROR
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@@ -175,11 +186,11 @@ function Craft.craftRecipe(recipe, count, inventoryAdapter, origItem)
|
|||||||
--end
|
--end
|
||||||
|
|
||||||
for _, request in pairs(origItem.ingredients) do
|
for _, request in pairs(origItem.ingredients) do
|
||||||
|
if request.crafted >= request.count then
|
||||||
if request.pending then
|
if request.pending then
|
||||||
debug('??')
|
debug('??')
|
||||||
debug(request)
|
debug(request)
|
||||||
end
|
end
|
||||||
if request.crafted >= request.count then
|
|
||||||
request.status = nil
|
request.status = nil
|
||||||
request.statusCode = Craft.STATUS_SUCCESS
|
request.statusCode = Craft.STATUS_SUCCESS
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -7,9 +7,12 @@ local Util = require('util')
|
|||||||
|
|
||||||
local colors = _G.colors
|
local colors = _G.colors
|
||||||
local device = _G.device
|
local device = _G.device
|
||||||
|
local turtle = _G.turtle
|
||||||
|
|
||||||
local context = Milo:getContext()
|
local context = Milo:getContext()
|
||||||
|
|
||||||
|
-- TODO: no blacklist for export
|
||||||
|
|
||||||
local function saveConfig()
|
local function saveConfig()
|
||||||
local t = { }
|
local t = { }
|
||||||
for k,v in pairs(context.config.remoteDefaults) do
|
for k,v in pairs(context.config.remoteDefaults) do
|
||||||
@@ -266,7 +269,14 @@ function machineWizard.filter:show(entry, callback, whitelistOnly)
|
|||||||
self.form[3].inactive = whitelistOnly
|
self.form[3].inactive = whitelistOnly
|
||||||
|
|
||||||
UI.SlideOut.show(self)
|
UI.SlideOut.show(self)
|
||||||
-- self:setFocus(self.filter)
|
self:setFocus(self.form.scan)
|
||||||
|
|
||||||
|
Milo:pauseCrafting()
|
||||||
|
end
|
||||||
|
|
||||||
|
function machineWizard.filter:hide()
|
||||||
|
UI.SlideOut.hide(self)
|
||||||
|
Milo:resumeCrafting()
|
||||||
end
|
end
|
||||||
|
|
||||||
function machineWizard.filter:resetGrid()
|
function machineWizard.filter:resetGrid()
|
||||||
@@ -295,6 +305,7 @@ function machineWizard.filter:eventHandler(event)
|
|||||||
self:resetGrid()
|
self:resetGrid()
|
||||||
self.grid:update()
|
self.grid:update()
|
||||||
self.grid:draw()
|
self.grid:draw()
|
||||||
|
turtle.emptyInventory()
|
||||||
|
|
||||||
elseif event.type == 'remove_entry' then
|
elseif event.type == 'remove_entry' then
|
||||||
local row = self.grid:getSelected()
|
local row = self.grid:getSelected()
|
||||||
@@ -411,13 +422,6 @@ function machineWizard:eventHandler(event)
|
|||||||
UI:setPreviousPage()
|
UI:setPreviousPage()
|
||||||
|
|
||||||
elseif event.type == 'accept' then
|
elseif event.type == 'accept' then
|
||||||
-- todo: no need for calling this function - use validate instead
|
|
||||||
for _, v in pairs(self.wizard.pages) do
|
|
||||||
if v.save and v.index then -- only save if the page was valid for this mtype
|
|
||||||
v:save(self.machine)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
Util.prune(self.machine, function(v)
|
Util.prune(self.machine, function(v)
|
||||||
if type(v) == 'boolean' then
|
if type(v) == 'boolean' then
|
||||||
return v
|
return v
|
||||||
|
|||||||
@@ -1,26 +0,0 @@
|
|||||||
local Milo = require('milo')
|
|
||||||
local Util = require('util')
|
|
||||||
|
|
||||||
local Autocraft = {
|
|
||||||
name = 'autocraft',
|
|
||||||
priority = 100,
|
|
||||||
}
|
|
||||||
|
|
||||||
-- TODO: fix/test
|
|
||||||
function Autocraft:cycle(context)
|
|
||||||
local list = { }
|
|
||||||
|
|
||||||
for _,res in pairs(context.resources) do
|
|
||||||
if res.auto then
|
|
||||||
res = Util.shallowCopy(res)
|
|
||||||
res.count = 256
|
|
||||||
list[Milo:uniqueKey(res)] = res
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
if not Util.empty(list) then
|
|
||||||
Milo:craftItems(list)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
Milo:registerTask(Autocraft)
|
|
||||||
@@ -13,29 +13,57 @@ end
|
|||||||
function ExportTask:cycle(context)
|
function ExportTask:cycle(context)
|
||||||
for machine in context.storage:filterActive('machine', filter) do
|
for machine in context.storage:filterActive('machine', filter) do
|
||||||
for _, entry in pairs(machine.exports) do
|
for _, entry in pairs(machine.exports) do
|
||||||
local slotNo = type(entry.slot) == 'number' and entry.slot or nil -- '*' indicates any slot
|
|
||||||
|
|
||||||
local slot = (slotNo and machine.adapter.getItemMeta(slotNo)) or { count = 0 }
|
local function exportSlot(list, slotNo, item, count)
|
||||||
for key in pairs(entry.filter or { }) do
|
local slot = list[slotNo] or { count = 0 }
|
||||||
local item = itemDB:splitKey(key)
|
|
||||||
|
if slot.count == 0 or
|
||||||
|
(slot.name == item.name and
|
||||||
|
slot.damage == item.damage and
|
||||||
|
slot.nbtHash == item.nbtHash) then
|
||||||
|
|
||||||
|
local maxCount = itemDB:getMaxCount(item)
|
||||||
|
count = math.min(maxCount - slot.count, count)
|
||||||
|
|
||||||
-- is something else is in this slot
|
|
||||||
if not slot.name or slot.name == item.name then
|
|
||||||
local maxCount = slot.maxCount or itemDB:getMaxCount(item)
|
|
||||||
local count = maxCount - slot.count
|
|
||||||
if not slotNo then
|
|
||||||
-- TODO: should we just execute export -
|
|
||||||
-- or scan all slots for space ??
|
|
||||||
count = machine.adapter.size() * maxCount - slot.count
|
|
||||||
end
|
|
||||||
if count > 0 then
|
if count > 0 then
|
||||||
item = Milo:getItemWithQty(item)
|
-- _debug('attempting to export %s %d into slot %d', item.name, count, slotNo)
|
||||||
if item and count > 0 then
|
count = context.storage:export(machine.name, slotNo, count, item)
|
||||||
context.storage:export(
|
|
||||||
machine.name,
|
if count > 0 then
|
||||||
slotNo,
|
item.count = item.count - count
|
||||||
math.min(count, item.count),
|
list[slotNo] = {
|
||||||
item)
|
name = item.name,
|
||||||
|
damage = item.damage,
|
||||||
|
nbtHash = item.nbtHash,
|
||||||
|
count = count + slot.count,
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local list
|
||||||
|
local function getLazyList()
|
||||||
|
if not list then
|
||||||
|
list = machine.adapter.list()
|
||||||
|
end
|
||||||
|
return list
|
||||||
|
end
|
||||||
|
|
||||||
|
for key in pairs(entry.filter or { }) do
|
||||||
|
-- bad for perf to do listItems each time
|
||||||
|
local items = Milo:getMatches(Milo:listItems(), itemDB:splitKey(key), entry.ignoreDamage, entry.ignoreNbtHash)
|
||||||
|
for _,item in pairs(items) do
|
||||||
|
if item and item.count > 0 then
|
||||||
|
if type(entry.slot) == 'number' then
|
||||||
|
if exportSlot(getLazyList(), entry.slot, item, item.count) then
|
||||||
|
break
|
||||||
|
end
|
||||||
|
else
|
||||||
|
-- _debug('attempting to export %s %d', item.name, item.count)
|
||||||
|
-- TODO: always going to try and export even if the chest is full
|
||||||
|
context.storage:export(machine.name, nil, item.count, item)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ local function filter(a)
|
|||||||
return a.imports
|
return a.imports
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- TODO: ignore damage/nbt
|
||||||
|
|
||||||
function ImportTask:cycle(context)
|
function ImportTask:cycle(context)
|
||||||
for inventory in context.storage:filterActive('machine', filter) do
|
for inventory in context.storage:filterActive('machine', filter) do
|
||||||
for _, entry in pairs(inventory.imports) do
|
for _, entry in pairs(inventory.imports) do
|
||||||
|
|||||||
@@ -270,7 +270,7 @@ function itemPage:eventHandler(event)
|
|||||||
|
|
||||||
filtered.count = nil
|
filtered.count = nil
|
||||||
Milo:saveResources()
|
Milo:saveResources()
|
||||||
|
-- TODO: min not updated upon save until refresh
|
||||||
UI:setPreviousPage()
|
UI:setPreviousPage()
|
||||||
|
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -211,7 +211,7 @@ function listingPage:eventHandler(event)
|
|||||||
Util.writeTable(Craft.USER_RECIPES, context.userRecipes)
|
Util.writeTable(Craft.USER_RECIPES, context.userRecipes)
|
||||||
Craft.loadRecipes()
|
Craft.loadRecipes()
|
||||||
end
|
end
|
||||||
|
--TODO: remove machine assoc
|
||||||
if context.resources[key] then
|
if context.resources[key] then
|
||||||
context.resources[key] = nil
|
context.resources[key] = nil
|
||||||
Milo:saveResources()
|
Milo:saveResources()
|
||||||
@@ -242,7 +242,6 @@ function listingPage:enable()
|
|||||||
self:setFocus(self.statusBar.filter)
|
self:setFocus(self.statusBar.filter)
|
||||||
self.timer = Event.onInterval(5, function()
|
self.timer = Event.onInterval(5, function()
|
||||||
for _,v in pairs(self.allItems) do
|
for _,v in pairs(self.allItems) do
|
||||||
if not v.key then debug(v) error('') end
|
|
||||||
local c = context.storage.cache[v.key]
|
local c = context.storage.cache[v.key]
|
||||||
v.count = c and c.count or 0
|
v.count = c and c.count or 0
|
||||||
end
|
end
|
||||||
@@ -273,6 +272,7 @@ function listingPage:applyFilter()
|
|||||||
end
|
end
|
||||||
|
|
||||||
Event.on({ 'storage_offline', 'storage_online' }, function(e, isOnline)
|
Event.on({ 'storage_offline', 'storage_online' }, function(e, isOnline)
|
||||||
|
-- TODO: Fix button
|
||||||
listingPage.statusBar.storageStatus.text =
|
listingPage.statusBar.storageStatus.text =
|
||||||
isOnline and 'online' or 'offline'
|
isOnline and 'online' or 'offline'
|
||||||
listingPage.statusBar.storageStatus.textColor =
|
listingPage.statusBar.storageStatus.textColor =
|
||||||
|
|||||||
@@ -62,9 +62,6 @@ function pages.machines:enable()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function pages.machines:validate()
|
function pages.machines:validate()
|
||||||
|
|
||||||
-- TODO: index number validation in wizard
|
|
||||||
|
|
||||||
local selected = self.grid:getSelected()
|
local selected = self.grid:getSelected()
|
||||||
if not selected then
|
if not selected then
|
||||||
machineLearnWizard.notification:error('No machines configured')
|
machineLearnWizard.notification:error('No machines configured')
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ function RedstoneTask:cycle(context)
|
|||||||
if v.redstone then
|
if v.redstone then
|
||||||
local ri = device[v.redstone.integrator]
|
local ri = device[v.redstone.integrator]
|
||||||
if not ri or not v.adapter then
|
if not ri or not v.adapter then
|
||||||
debug(v.redstone)
|
_debug(v.redstone)
|
||||||
else
|
else
|
||||||
local function conditionsSatisfied()
|
local function conditionsSatisfied()
|
||||||
return not not next(v.adapter.list())
|
return not not next(v.adapter.list())
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ local function getManipulatorForUser(user)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function client(socket)
|
local function client(socket)
|
||||||
debug('connection from ' .. socket.dhost)
|
_debug('connection from ' .. socket.dhost)
|
||||||
|
|
||||||
local user = socket:read(2)
|
local user = socket:read(2)
|
||||||
if not user then
|
if not user then
|
||||||
@@ -36,7 +36,7 @@ local function client(socket)
|
|||||||
if not data then
|
if not data then
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
debug('remote: ' .. data.request)
|
_debug('remote: ' .. data.request)
|
||||||
if data.request == 'list' then
|
if data.request == 'list' then
|
||||||
local items = Milo:listItems()
|
local items = Milo:listItems()
|
||||||
Milo:mergeResources(items)
|
Milo:mergeResources(items)
|
||||||
@@ -89,12 +89,12 @@ debug('remote: ' .. data.request)
|
|||||||
end
|
end
|
||||||
until not socket.connected
|
until not socket.connected
|
||||||
|
|
||||||
debug('disconnected from ' .. socket.dhost)
|
_debug('disconnected from ' .. socket.dhost)
|
||||||
end
|
end
|
||||||
|
|
||||||
if device.wireless_modem then
|
if device.wireless_modem then
|
||||||
Event.addRoutine(function()
|
Event.addRoutine(function()
|
||||||
debug('Milo: listening on port 4242')
|
_debug('Milo: listening on port 4242')
|
||||||
while true do
|
while true do
|
||||||
local socket = Socket.server(4242)
|
local socket = Socket.server(4242)
|
||||||
Event.addRoutine(function()
|
Event.addRoutine(function()
|
||||||
|
|||||||
@@ -77,8 +77,8 @@ local function learnRecipe()
|
|||||||
end
|
end
|
||||||
|
|
||||||
if not recipe then
|
if not recipe then
|
||||||
debug(results)
|
_debug(results)
|
||||||
debug(newRecipe)
|
_debug(newRecipe)
|
||||||
error('Failed - view system log')
|
error('Failed - view system log')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user