lora wip
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
local Lora = require('lora/lora')
|
||||
local Lora = require('lora')
|
||||
local Util = require('util')
|
||||
|
||||
local Autocraft = {
|
||||
@@ -17,8 +17,8 @@ function Autocraft:cycle(context)
|
||||
end
|
||||
|
||||
if not Util.empty(list) then
|
||||
Lora:craftItems(list)
|
||||
end
|
||||
Lora:craftItems(list)
|
||||
end
|
||||
end
|
||||
|
||||
Lora:registerTask(Autocraft)
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
local Craft = require('turtle.craft')
|
||||
local itemDB = require('itemDB')
|
||||
local Lora = require('lora/lora')
|
||||
local UI = require('ui')
|
||||
local Util = require('util')
|
||||
local Craft = require('turtle.craft')
|
||||
local itemDB = require('itemDB')
|
||||
local Lora = require('lora')
|
||||
local UI = require('ui')
|
||||
local Util = require('util')
|
||||
|
||||
local colors = _G.colors
|
||||
local colors = _G.colors
|
||||
|
||||
local demandCrafting = { }
|
||||
|
||||
@@ -135,25 +135,35 @@ local demandCraftingTask = {
|
||||
priority = 20,
|
||||
}
|
||||
|
||||
function demandCraftingTask:cycle()
|
||||
if Util.size(demandCrafting) > 0 then
|
||||
local demandCrafted = Util.shallowCopy(demandCrafting)
|
||||
Lora:craftItems(demandCrafted)
|
||||
function demandCraftingTask:cycle(context)
|
||||
local demandCrafted = { }
|
||||
|
||||
for _, item in pairs(demandCrafting) do
|
||||
if item.crafted then
|
||||
item.count = math.max(0, item.count - item.crafted)
|
||||
if item.count <= 0 then
|
||||
item.statusCode = 'success'
|
||||
end
|
||||
end
|
||||
-- look directly at the adapter import activity to determine
|
||||
-- if the item was imported into storage from any source.
|
||||
-- The item does NOT need to come from the machine that did
|
||||
-- the crafting.
|
||||
for _,key in pairs(Util.keys(demandCrafting)) do
|
||||
local item = demandCrafting[key]
|
||||
|
||||
local imported = context.inventoryAdapter.activity[key]
|
||||
if imported then
|
||||
item.crafted = math.min(imported, item.count)
|
||||
item.count = math.max(0, item.count - item.crafted)
|
||||
context.inventoryAdapter.activity[key] = imported - item.crafted
|
||||
end
|
||||
demandCrafted[key] = item
|
||||
end
|
||||
|
||||
Lora:updateCraftingStatus(demandCrafted)
|
||||
if Util.size(demandCrafted) > 0 then
|
||||
Lora:craftItems(demandCrafted)
|
||||
end
|
||||
|
||||
for _,key in pairs(Util.keys(demandCrafting)) do
|
||||
local item = demandCrafting[key]
|
||||
if item.crafted and item.count <= 0 then
|
||||
for _,key in pairs(Util.keys(demandCrafting)) do
|
||||
local item = demandCrafting[key]
|
||||
if item.crafted then
|
||||
item.count = math.max(0, item.count - item.crafted)
|
||||
if item.count <= 0 then
|
||||
item.statusCode = 'success'
|
||||
demandCrafting[key] = nil
|
||||
if item.eject then
|
||||
Lora:eject(item, item.ocount)
|
||||
@@ -1,5 +1,5 @@
|
||||
local itemDB = require('itemDB')
|
||||
local Lora = require('lora/lora')
|
||||
local Lora = require('lora')
|
||||
|
||||
local device = _G.device
|
||||
|
||||
@@ -12,19 +12,20 @@ function ExportTask:cycle(context)
|
||||
if v.exports then
|
||||
local machine = device[target]
|
||||
if machine and machine.getItemMeta then
|
||||
for slotNo, item in pairs(v.exports) do
|
||||
local slot = machine.getItemMeta(slotNo) or { count = 0 }
|
||||
local maxCount = slot.maxCount or itemDB:getMaxCount(item)
|
||||
for _, entry in pairs(v.exports) do
|
||||
local slot = machine.getItemMeta(entry.slot) or { count = 0 }
|
||||
local maxCount = slot.maxCount or itemDB:getMaxCount(entry.name)
|
||||
local count = maxCount - slot.count
|
||||
if count > 0 then
|
||||
context.inventoryAdapter:provide(itemDB:splitKey(item), count, slotNo, target)
|
||||
context.inventoryAdapter:provide(
|
||||
itemDB:splitKey(entry.name), count, entry.slot, target)
|
||||
end
|
||||
end
|
||||
else
|
||||
debug('Invalid export target: ' .. target)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Lora:registerTask(ExportTask)
|
||||
|
||||
121
inventoryManager/plugins/exportView.lua
Normal file
121
inventoryManager/plugins/exportView.lua
Normal file
@@ -0,0 +1,121 @@
|
||||
local itemDB = require('itemDB')
|
||||
local Lora = require('lora')
|
||||
local UI = require('ui')
|
||||
local Util = require('util')
|
||||
|
||||
local colors = _G.colors
|
||||
local device = _G.device
|
||||
|
||||
local itemSlideout = UI.SlideOut {
|
||||
backgroundColor = colors.cyan,
|
||||
grid = UI.ScrollingGrid {
|
||||
y = 3, ey = -2,
|
||||
columns = {
|
||||
{ heading = 'Name', key = 'displayName', width = 31 },
|
||||
{ heading = 'Qty', key = 'count' , width = 5 },
|
||||
},
|
||||
sortColumn = 'displayName',
|
||||
},
|
||||
filter = UI.TextEntry {
|
||||
x = 2, ex = -2, y = 2,
|
||||
limit = 50,
|
||||
shadowText = 'filter',
|
||||
backgroundColor = colors.lightGray,
|
||||
backgroundFocusColor = colors.lightGray,
|
||||
},
|
||||
button1 = UI.Button {
|
||||
x = -14, y = -1,
|
||||
text = 'Ok', event = 'accept',
|
||||
},
|
||||
button2 = UI.Button {
|
||||
x = -9, y = -1,
|
||||
text = 'Cancel', event = 'collapse',
|
||||
},
|
||||
}
|
||||
|
||||
function itemSlideout:filterItems(t, filter)
|
||||
if filter then
|
||||
local r = {}
|
||||
filter = filter:lower()
|
||||
for _,v in pairs(t) do
|
||||
if string.find(v.lname, filter) then
|
||||
table.insert(r, v)
|
||||
end
|
||||
end
|
||||
return r
|
||||
end
|
||||
return t
|
||||
end
|
||||
|
||||
function itemSlideout.grid:enable()
|
||||
if not self.allItems then
|
||||
self.allItems = Lora:listItems()
|
||||
Lora:mergeResources(self.allItems)
|
||||
self:setValues(self.allItems)
|
||||
end
|
||||
UI.Grid.enable(self)
|
||||
end
|
||||
|
||||
function itemSlideout:eventHandler(event)
|
||||
if event.type == 'text_change' and event.element == self.filter then
|
||||
local t = self:filterItems(self.grid.allItems, event.text)
|
||||
self.grid:setValues(t)
|
||||
self.grid:draw()
|
||||
end
|
||||
return UI.SlideOut.eventHandler(self, event)
|
||||
end
|
||||
|
||||
local exportView = UI.Window {
|
||||
mtype = 'machine',
|
||||
title = 'Export item into machine',
|
||||
index = 3,
|
||||
grid = UI.ScrollingGrid {
|
||||
x = 2, ex = -6, y = 2, ey = -2,
|
||||
columns = {
|
||||
{ heading = 'Slot', key = 'slot', width = 4 },
|
||||
{ heading = 'Item', key = 'displayName' },
|
||||
},
|
||||
sortColumn = 'slot',
|
||||
},
|
||||
add = UI.Button {
|
||||
x = -4, y = 4,
|
||||
text = '+', event = 'add_export', help = '...',
|
||||
},
|
||||
remove = UI.Button {
|
||||
x = -4, y = 6,
|
||||
text = '-', event = 'remove_export', help = '...',
|
||||
},
|
||||
}
|
||||
|
||||
function exportView:save(machine)
|
||||
machine.exports = not Util.empty(self.grid.values) and self.grid.values or nil
|
||||
return true
|
||||
end
|
||||
|
||||
function exportView:setMachine(machine)
|
||||
local m = device[machine.name]
|
||||
self.slotCount = m.size()
|
||||
self.grid:setValues(machine.exports or { })
|
||||
end
|
||||
|
||||
function exportView.grid:getDisplayValues(row)
|
||||
row = Util.shallowCopy(row)
|
||||
row.displayName = itemDB:getName(row.name)
|
||||
return row
|
||||
end
|
||||
|
||||
function exportView:eventHandler(event)
|
||||
if event.type == 'grid_select' or event.type == 'add_export' then
|
||||
itemSlideout:show()
|
||||
elseif event.type == 'remove_export' then
|
||||
local row = self.grid:getSelected()
|
||||
if row then
|
||||
Util.removeByValue(self.grid.values, row)
|
||||
self.grid:update()
|
||||
self.grid:draw()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
UI:getPage('machineWizard'):add({ items = itemSlideout })
|
||||
UI:getPage('machineWizard').wizard:add({ export = exportView })
|
||||
@@ -1,4 +1,4 @@
|
||||
local Lora = require('lora/lora')
|
||||
local Lora = require('lora')
|
||||
|
||||
local device = _G.device
|
||||
|
||||
@@ -21,7 +21,7 @@ function ImportTask:cycle(context)
|
||||
debug('Invalid import source: ' .. source)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Lora:registerTask(ImportTask)
|
||||
|
||||
56
inventoryManager/plugins/importView.lua
Normal file
56
inventoryManager/plugins/importView.lua
Normal file
@@ -0,0 +1,56 @@
|
||||
local UI = require('ui')
|
||||
local Util = require('util')
|
||||
|
||||
local device = _G.device
|
||||
|
||||
local importView = UI.Window {
|
||||
mtype = 'machine',
|
||||
title = 'Import item from machine',
|
||||
index = 4,
|
||||
grid = UI.ScrollingGrid {
|
||||
y = 2, ey = -2,
|
||||
columns = {
|
||||
{ heading = 'Slot', key = 'slot', width = 4 },
|
||||
{ heading = 'Import', key = 'import' },
|
||||
},
|
||||
sortColumn = 'slot',
|
||||
help = 'Double-click to toggle'
|
||||
},
|
||||
}
|
||||
|
||||
function importView:setMachine(machine)
|
||||
local m = device[machine.name]
|
||||
|
||||
local t = { }
|
||||
for k = 1, m.size() do
|
||||
t[k] = { slot = k }
|
||||
end
|
||||
|
||||
if machine.imports then
|
||||
for k,v in pairs(machine.imports) do
|
||||
t[k] = { slot = k, import = v }
|
||||
end
|
||||
end
|
||||
|
||||
self.grid:setValues(t)
|
||||
end
|
||||
|
||||
function importView:save(machine)
|
||||
local t = { }
|
||||
for k,v in pairs(self.grid.values) do
|
||||
if v.import then
|
||||
t[k] = true
|
||||
end
|
||||
end
|
||||
machine.imports = not Util.empty(t) and t or nil
|
||||
return true
|
||||
end
|
||||
|
||||
function importView:eventHandler(event)
|
||||
if event.type == 'grid_select' then
|
||||
event.selected.import = not event.selected.import
|
||||
self.grid:draw()
|
||||
end
|
||||
end
|
||||
|
||||
UI:getPage('machineWizard').wizard:add({ import = importView })
|
||||
@@ -1,38 +1,24 @@
|
||||
local InventoryAdapter = require('inventoryAdapter')
|
||||
local Lora = require('lora/lora')
|
||||
local Lora = require('lora')
|
||||
|
||||
local device = _G.device
|
||||
local modem = device.wired_modem
|
||||
|
||||
local InputChest = {
|
||||
priority = 1,
|
||||
adapters = { },
|
||||
}
|
||||
|
||||
function InputChest:init(context)
|
||||
for k,v in pairs(context.config.remoteDefaults) do
|
||||
if v.mtype == 'input' then
|
||||
local adapter = InventoryAdapter.wrap({ side = k, direction = modem.getNameLocal() })
|
||||
if adapter then
|
||||
table.insert(self.adapters, adapter)
|
||||
end
|
||||
end
|
||||
function InputChest:cycle(context)
|
||||
for name,v in pairs(context.config.remoteDefaults) do
|
||||
if v.mtype == 'input' then
|
||||
local inventory = device[name]
|
||||
|
||||
local list = inventory and inventory.list and inventory.list()
|
||||
if list then
|
||||
for slotNo, slot in pairs(list) do
|
||||
context.inventoryAdapter:insert(slotNo, slot.count, nil, slot, name)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- TODO: clear grid
|
||||
-- TODO: extract directly to target
|
||||
|
||||
function InputChest:cycle(context)
|
||||
for _, adapter in pairs(self.adapters) do
|
||||
local list = adapter.list() -- raw list !
|
||||
for k,v in pairs(list) do
|
||||
adapter:extract(k, v.count, 1)
|
||||
context.inventoryAdapter:insert(1, v.count, nil, v)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
InputChest:init(Lora:getContext())
|
||||
|
||||
Lora:registerTask(InputChest)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
local Ansi = require('ansi')
|
||||
local Lora = require('lora/lora')
|
||||
local Lora = require('lora')
|
||||
local UI = require('ui')
|
||||
local Util = require('util')
|
||||
|
||||
@@ -24,6 +24,7 @@ local itemPage = UI.Page {
|
||||
width = 7,
|
||||
formLabel = 'Max', formKey = 'limit', help = 'Eject if above max'
|
||||
},
|
||||
--[[
|
||||
[3] = UI.Chooser {
|
||||
width = 7,
|
||||
formLabel = 'Autocraft', formKey = 'auto',
|
||||
@@ -34,6 +35,7 @@ local itemPage = UI.Page {
|
||||
},
|
||||
help = 'Craft until out of ingredients'
|
||||
},
|
||||
]]
|
||||
[4] = UI.Chooser {
|
||||
width = 7,
|
||||
formLabel = 'Ignore Dmg', formKey = 'ignoreDamage',
|
||||
@@ -125,9 +127,9 @@ local itemPage = UI.Page {
|
||||
}
|
||||
|
||||
function itemPage:enable(item)
|
||||
self.item = item
|
||||
self.item = Util.shallowCopy(item)
|
||||
|
||||
self.form:setValues(item)
|
||||
self.form:setValues(self.item)
|
||||
self.titleBar.title = item.displayName or item.name
|
||||
|
||||
UI.Page.enable(self)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
local Lora = require('lora/lora')
|
||||
local Lora = require('lora')
|
||||
local Peripheral = require('peripheral')
|
||||
local UI = require('ui')
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
local Craft = require('turtle.craft')
|
||||
local itemDB = require('itemDB')
|
||||
local Lora = require('lora/lora')
|
||||
local Lora = require('lora')
|
||||
local UI = require('ui')
|
||||
local Util = require('util')
|
||||
|
||||
|
||||
@@ -1,36 +1,35 @@
|
||||
local Lora = require('lora/lora')
|
||||
local Lora = require('lora')
|
||||
|
||||
local LimitTask = {
|
||||
priority = 10,
|
||||
}
|
||||
|
||||
function LimitTask:init(context)
|
||||
for k,v in pairs(context.config.remoteDefaults) do
|
||||
if v.mtype == 'trashcan' then
|
||||
self.trashcan = k
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function LimitTask:cycle(context)
|
||||
if not self.trashcan then
|
||||
local trashcan
|
||||
|
||||
for k,v in pairs(context.config.remoteDefaults) do
|
||||
if v.mtype == 'trashcan' then
|
||||
trashcan = k
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
if not trashcan then
|
||||
return
|
||||
end
|
||||
|
||||
for _,res in pairs(context.resources) do
|
||||
for _,res in pairs(context.resources) do
|
||||
if res.limit then
|
||||
local item = Lora:getItemWithQty(res, res.ignoreDamage, res.ignoreNbtHash)
|
||||
if item and item.count > res.limit then
|
||||
context.inventoryAdapter:provide(
|
||||
{ name = item.name, damage = item.damage, nbtHash = item.nbtHash },
|
||||
item.count - res.limit,
|
||||
nil,
|
||||
self.trashcan)
|
||||
end
|
||||
end
|
||||
end
|
||||
local item = Lora:getItemWithQty(res, res.ignoreDamage, res.ignoreNbtHash)
|
||||
if item and item.count > res.limit then
|
||||
context.inventoryAdapter:provide(
|
||||
{ name = item.name, damage = item.damage, nbtHash = item.nbtHash },
|
||||
item.count - res.limit,
|
||||
nil,
|
||||
trashcan)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
LimitTask:init(Lora:getContext())
|
||||
Lora:registerTask(LimitTask)
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
local Craft = require('turtle.craft')
|
||||
local itemDB = require('itemDB')
|
||||
local Lora = require('lora/lora')
|
||||
local Lora = require('lora')
|
||||
local UI = require('ui')
|
||||
local Util = require('util')
|
||||
|
||||
local colors = _G.colors
|
||||
local os = _G.os
|
||||
|
||||
local context = Lora:getContext()
|
||||
local context = Lora:getContext()
|
||||
|
||||
local function queue(fn)
|
||||
while Lora:isCraftingPaused() do
|
||||
@@ -16,37 +16,6 @@ local function queue(fn)
|
||||
fn()
|
||||
end
|
||||
|
||||
local function mergeResources(t)
|
||||
for _,v in pairs(context.resources) do
|
||||
local item = Lora:getItem(t, v)
|
||||
if item then
|
||||
Util.merge(item, v)
|
||||
else
|
||||
item = Util.shallowCopy(v)
|
||||
item.count = 0
|
||||
table.insert(t, item)
|
||||
end
|
||||
end
|
||||
|
||||
for k in pairs(Craft.recipes) do
|
||||
local v = itemDB:splitKey(k)
|
||||
local item = Lora:getItem(t, v)
|
||||
if not item then
|
||||
item = Util.shallowCopy(v)
|
||||
item.count = 0
|
||||
table.insert(t, item)
|
||||
end
|
||||
item.has_recipe = true
|
||||
end
|
||||
|
||||
for _,v in pairs(t) do
|
||||
if not v.displayName then
|
||||
v.displayName = itemDB:getName(v)
|
||||
end
|
||||
v.lname = v.displayName:lower()
|
||||
end
|
||||
end
|
||||
|
||||
local function filterItems(t, filter, displayMode)
|
||||
if filter or displayMode > 0 then
|
||||
local r = { }
|
||||
@@ -80,8 +49,8 @@ local listingPage = UI.Page {
|
||||
grid = UI.Grid {
|
||||
y = 2, ey = -2,
|
||||
columns = {
|
||||
{ heading = ' Qty', key = 'count' , width = 4, justify = 'right' },
|
||||
{ heading = 'Name', key = 'displayName' },
|
||||
{ heading = 'Qty', key = 'count' , width = 4 },
|
||||
{ heading = 'Min', key = 'low' , width = 4 },
|
||||
{ heading = 'Max', key = 'limit' , width = 4 },
|
||||
},
|
||||
@@ -95,6 +64,9 @@ local listingPage = UI.Page {
|
||||
shadowTextColor = colors.gray,
|
||||
backgroundColor = colors.cyan,
|
||||
backgroundFocusColor = colors.cyan,
|
||||
accelerators = {
|
||||
[ 'enter' ] = 'craft',
|
||||
},
|
||||
},
|
||||
display = UI.Button {
|
||||
x = -3,
|
||||
@@ -107,7 +79,6 @@ local listingPage = UI.Page {
|
||||
accelerators = {
|
||||
r = 'refresh',
|
||||
q = 'quit',
|
||||
grid_select_right = 'craft',
|
||||
[ 'control-e' ] = 'eject',
|
||||
[ 'control-s' ] = 'eject_stack',
|
||||
[ 'control-m' ] = 'machines',
|
||||
@@ -131,7 +102,7 @@ end
|
||||
|
||||
function listingPage.grid:getDisplayValues(row)
|
||||
row = Util.shallowCopy(row)
|
||||
row.count = Util.toBytes(row.count)
|
||||
row.count = row.count > 0 and Util.toBytes(row.count) or ''
|
||||
if row.low then
|
||||
row.low = Util.toBytes(row.low)
|
||||
end
|
||||
@@ -142,6 +113,7 @@ function listingPage.grid:getDisplayValues(row)
|
||||
end
|
||||
|
||||
function listingPage:eventHandler(event)
|
||||
debug(event)
|
||||
if event.type == 'quit' then
|
||||
UI:exitPullEvents()
|
||||
|
||||
@@ -160,9 +132,11 @@ function listingPage:eventHandler(event)
|
||||
elseif event.type == 'machines' then
|
||||
UI:setPage('machines')
|
||||
|
||||
elseif event.type == 'grid_select' then
|
||||
local selected = event.selected
|
||||
UI:setPage('item', selected)
|
||||
elseif event.type == 'details' or event.type == 'grid_select_right' then
|
||||
local item = self.grid:getSelected()
|
||||
if item then
|
||||
UI:setPage('item', item)
|
||||
end
|
||||
|
||||
elseif event.type == 'refresh' then
|
||||
self:refresh()
|
||||
@@ -186,7 +160,7 @@ function listingPage:eventHandler(event)
|
||||
elseif event.type == 'learn' then
|
||||
UI:setPage('learn')
|
||||
|
||||
elseif event.type == 'craft' or event.type == 'grid_select_right' then
|
||||
elseif event.type == 'craft' or event.type == 'grid_select' then
|
||||
local item = self.grid:getSelected()
|
||||
if Craft.findRecipe(item) or true then -- or item.is_craftable then
|
||||
UI:setPage('craft', self.grid:getSelected())
|
||||
@@ -238,7 +212,7 @@ end
|
||||
|
||||
function listingPage:refresh()
|
||||
self.allItems = Lora:listItems()
|
||||
mergeResources(self.allItems)
|
||||
Lora:mergeResources(self.allItems)
|
||||
self:applyFilter()
|
||||
end
|
||||
|
||||
|
||||
@@ -1,152 +0,0 @@
|
||||
local Config = require('config')
|
||||
local Lora = require('lora/lora')
|
||||
local UI = require('ui')
|
||||
local Util = require('util')
|
||||
|
||||
local colors = _G.colors
|
||||
|
||||
local context = Lora:getContext()
|
||||
|
||||
local machinesPage = UI.Page {
|
||||
titleBar = UI.TitleBar {
|
||||
previousPage = true,
|
||||
title = 'Machines',
|
||||
},
|
||||
grid = UI.ScrollingGrid {
|
||||
y = 2, ey = -2,
|
||||
values = context.config.remoteDefaults,
|
||||
columns = {
|
||||
{ heading = 'Name', key = 'displayName' },
|
||||
{ heading = 'Priority', key = 'priority', width = 5 },
|
||||
{ heading = 'Type', key = 'mtype', width = 5 },
|
||||
},
|
||||
sortColumn = 'name',
|
||||
},
|
||||
detail = UI.SlideOut {
|
||||
backgroundColor = colors.cyan,
|
||||
form = UI.Form {
|
||||
x = 1, y = 2, ex = -1, ey = -2,
|
||||
[7] = UI.Text {
|
||||
x = 12, y = 1,
|
||||
width = 28,
|
||||
},
|
||||
[1] = UI.TextEntry {
|
||||
formLabel = 'Name', formKey = 'displayName', help = '...',
|
||||
limit = 64,
|
||||
},
|
||||
[2] = UI.Chooser {
|
||||
width = 15,
|
||||
formLabel = 'Type', formKey = 'mtype',
|
||||
nochoice = 'Storage',
|
||||
choices = {
|
||||
{ name = 'Storage', value = 'storage' },
|
||||
{ name = 'Trashcan', value = 'trashcan' },
|
||||
{ name = 'Input chest', value = 'input' },
|
||||
{ name = 'Ignore', value = 'ignore' },
|
||||
},
|
||||
help = 'Check if machine is empty before crafting'
|
||||
},
|
||||
[3] = UI.Chooser {
|
||||
width = 7,
|
||||
formLabel = 'Empty', formKey = 'empty',
|
||||
nochoice = 'No',
|
||||
choices = {
|
||||
{ name = 'Yes', value = true },
|
||||
{ name = 'No', value = false },
|
||||
},
|
||||
help = 'Check if machine is empty before crafting'
|
||||
},
|
||||
[4] = UI.TextEntry {
|
||||
formLabel = 'Priority', formKey = 'priority', help = '...',
|
||||
limit = 4,
|
||||
},
|
||||
[5] = UI.TextEntry {
|
||||
formLabel = 'Max Craft', formKey = 'maxCount', help = '...',
|
||||
limit = 4,
|
||||
},
|
||||
[6] = UI.TextEntry {
|
||||
formLabel = 'Lock to', formKey = 'lockWith', help = '...',
|
||||
width = 18,
|
||||
limit = 64,
|
||||
},
|
||||
[8] = UI.Button {
|
||||
x = -9, ey = -4,
|
||||
text = 'Detect', help = '...',
|
||||
limit = 64,
|
||||
},
|
||||
},
|
||||
statusBar = UI.StatusBar(),
|
||||
},
|
||||
statusBar = UI.StatusBar {
|
||||
values = 'Select Machine',
|
||||
},
|
||||
accelerators = {
|
||||
h = 'toggle_hidden',
|
||||
}
|
||||
}
|
||||
|
||||
function machinesPage:enable()
|
||||
self.grid:update()
|
||||
UI.Page.enable(self)
|
||||
end
|
||||
|
||||
function machinesPage.detail:eventHandler(event)
|
||||
if event.type == 'focus_change' then
|
||||
self.statusBar:setStatus(event.focused.help)
|
||||
end
|
||||
return UI.SlideOut.eventHandler(self, event)
|
||||
end
|
||||
|
||||
function machinesPage.grid:getDisplayValues(row)
|
||||
row = Util.shallowCopy(row)
|
||||
row.displayName = row.displayName or row.name
|
||||
return row
|
||||
end
|
||||
|
||||
function machinesPage.grid:getRowTextColor(row, selected)
|
||||
if row.mtype == 'ignore' then
|
||||
return colors.lightGray
|
||||
end
|
||||
return UI.Grid:getRowTextColor(row, selected)
|
||||
end
|
||||
|
||||
function machinesPage:eventHandler(event)
|
||||
if event.type == 'grid_select' then
|
||||
self.detail.form:setValues(event.selected)
|
||||
self.detail.form[7].value = event.selected.name
|
||||
debug(event.selected)
|
||||
self.detail:show()
|
||||
|
||||
elseif event.type == 'toggle_hidden' then
|
||||
local selected = self.grid:getSelected()
|
||||
if selected then
|
||||
selected.ignore = not selected.ignore
|
||||
-- Util.writeTable(MACHINES_FILE, machines)
|
||||
self:draw()
|
||||
end
|
||||
|
||||
elseif event.type == 'form_complete' then
|
||||
self.detail.form.values.empty = self.detail.form.values.empty == true or nil
|
||||
self.detail.form.values.ignore = self.detail.form.values.ignore == true or nil
|
||||
self.detail.form.values.priority = tonumber(self.detail.form.values.priority)
|
||||
self.detail.form.values.maxCount = tonumber(self.detail.form.values.maxCount)
|
||||
if #self.detail.form.values.displayName == 0 then
|
||||
self.detail.form.values.displayName = nil
|
||||
end
|
||||
if #self.detail.form.values.lockWith == 0 then
|
||||
self.detail.form.values.lockWith = nil
|
||||
end
|
||||
Config.update('inventoryManager', context.config)
|
||||
self.detail:hide()
|
||||
self.grid:update()
|
||||
|
||||
elseif event.type == 'form_cancel' then
|
||||
self.detail:hide()
|
||||
|
||||
else
|
||||
UI.Page.eventHandler(self, event)
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
UI:addPage('machines', machinesPage)
|
||||
@@ -1,5 +1,5 @@
|
||||
local itemDB = require('itemDB')
|
||||
local Lora = require('lora/lora')
|
||||
local Lora = require('lora')
|
||||
|
||||
local ReplenishTask = {
|
||||
priority = 30,
|
||||
@@ -41,7 +41,6 @@ function ReplenishTask:cycle(context)
|
||||
end
|
||||
|
||||
Lora:craftItems(craftList)
|
||||
Lora:updateCraftingStatus(craftList)
|
||||
end
|
||||
|
||||
Lora:registerTask(ReplenishTask)
|
||||
|
||||
44
inventoryManager/plugins/storageView.lua
Normal file
44
inventoryManager/plugins/storageView.lua
Normal file
@@ -0,0 +1,44 @@
|
||||
local UI = require('ui')
|
||||
|
||||
local colors = _G.colors
|
||||
|
||||
local storageView = UI.Window {
|
||||
mtype = 'storage',
|
||||
title = 'Storage Options',
|
||||
index = 2,
|
||||
backgroundColor = colors.cyan,
|
||||
form = UI.Form {
|
||||
x = 1, y = 2, ex = -1, ey = -2,
|
||||
manualControls = true,
|
||||
[1] = UI.TextEntry {
|
||||
formLabel = 'Priority', formKey = 'priority',
|
||||
help = 'Larger values get precedence',
|
||||
limit = 4,
|
||||
validate = 'numeric', pruneEmpty = true,
|
||||
},
|
||||
[2] = UI.TextEntry {
|
||||
formLabel = 'Lock to', formKey = 'lockWith',
|
||||
help = 'Locks chest to a single item type',
|
||||
width = 18, limit = 64, pruneEmpty = true,
|
||||
},
|
||||
[3] = UI.Button {
|
||||
x = -9, ey = -4,
|
||||
text = 'Detect', help = 'Determine what is currently present',
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
function storageView:enable()
|
||||
UI.Window.enable(self)
|
||||
self:focusFirst()
|
||||
end
|
||||
|
||||
function storageView:validate()
|
||||
return self.form:save()
|
||||
end
|
||||
|
||||
function storageView:setMachine(machine)
|
||||
self.form:setValues(machine)
|
||||
end
|
||||
|
||||
UI:getPage('machineWizard').wizard:add({ storage = storageView })
|
||||
Reference in New Issue
Block a user