rename debug function + milo wip

This commit is contained in:
kepler155c
2018-10-31 00:05:56 -04:00
parent 871f44a170
commit 4d3a896d6b
20 changed files with 167 additions and 162 deletions

View File

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

View File

@@ -13,29 +13,57 @@ end
function ExportTask:cycle(context)
for machine in context.storage:filterActive('machine', filter) 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 }
for key in pairs(entry.filter or { }) do
local item = itemDB:splitKey(key)
local function exportSlot(list, slotNo, item, count)
local slot = list[slotNo] or { count = 0 }
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
item = Milo:getItemWithQty(item)
if item and count > 0 then
context.storage:export(
machine.name,
slotNo,
math.min(count, item.count),
item)
-- _debug('attempting to export %s %d into slot %d', item.name, count, slotNo)
count = context.storage:export(machine.name, slotNo, count, item)
if count > 0 then
item.count = item.count - count
list[slotNo] = {
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

View File

@@ -9,6 +9,8 @@ local function filter(a)
return a.imports
end
-- TODO: ignore damage/nbt
function ImportTask:cycle(context)
for inventory in context.storage:filterActive('machine', filter) do
for _, entry in pairs(inventory.imports) do

View File

@@ -270,7 +270,7 @@ function itemPage:eventHandler(event)
filtered.count = nil
Milo:saveResources()
-- TODO: min not updated upon save until refresh
UI:setPreviousPage()
else

View File

@@ -211,7 +211,7 @@ function listingPage:eventHandler(event)
Util.writeTable(Craft.USER_RECIPES, context.userRecipes)
Craft.loadRecipes()
end
--TODO: remove machine assoc
if context.resources[key] then
context.resources[key] = nil
Milo:saveResources()
@@ -242,7 +242,6 @@ function listingPage:enable()
self:setFocus(self.statusBar.filter)
self.timer = Event.onInterval(5, function()
for _,v in pairs(self.allItems) do
if not v.key then debug(v) error('') end
local c = context.storage.cache[v.key]
v.count = c and c.count or 0
end
@@ -273,6 +272,7 @@ function listingPage:applyFilter()
end
Event.on({ 'storage_offline', 'storage_online' }, function(e, isOnline)
-- TODO: Fix button
listingPage.statusBar.storageStatus.text =
isOnline and 'online' or 'offline'
listingPage.statusBar.storageStatus.textColor =

View File

@@ -62,9 +62,6 @@ function pages.machines:enable()
end
function pages.machines:validate()
-- TODO: index number validation in wizard
local selected = self.grid:getSelected()
if not selected then
machineLearnWizard.notification:error('No machines configured')

View File

@@ -13,7 +13,7 @@ function RedstoneTask:cycle(context)
if v.redstone then
local ri = device[v.redstone.integrator]
if not ri or not v.adapter then
debug(v.redstone)
_debug(v.redstone)
else
local function conditionsSatisfied()
return not not next(v.adapter.list())

View File

@@ -19,7 +19,7 @@ local function getManipulatorForUser(user)
end
local function client(socket)
debug('connection from ' .. socket.dhost)
_debug('connection from ' .. socket.dhost)
local user = socket:read(2)
if not user then
@@ -36,7 +36,7 @@ local function client(socket)
if not data then
break
end
debug('remote: ' .. data.request)
_debug('remote: ' .. data.request)
if data.request == 'list' then
local items = Milo:listItems()
Milo:mergeResources(items)
@@ -89,12 +89,12 @@ debug('remote: ' .. data.request)
end
until not socket.connected
debug('disconnected from ' .. socket.dhost)
_debug('disconnected from ' .. socket.dhost)
end
if device.wireless_modem then
Event.addRoutine(function()
debug('Milo: listening on port 4242')
_debug('Milo: listening on port 4242')
while true do
local socket = Socket.server(4242)
Event.addRoutine(function()

View File

@@ -77,8 +77,8 @@ local function learnRecipe()
end
if not recipe then
debug(results)
debug(newRecipe)
_debug(results)
_debug(newRecipe)
error('Failed - view system log')
end