spaces->tab, equipper improvements, supertreefarm rewrite, follow improvements, sensor cleanup, milo multiple items allowed in recipes, remote canvas access
This commit is contained in:
@@ -4,18 +4,18 @@ local args = { ... }
|
||||
local context = args[1]
|
||||
|
||||
local function learn()
|
||||
context:sendRequest({
|
||||
request = 'craft',
|
||||
slot = 15,
|
||||
})
|
||||
context:sendRequest({
|
||||
request = 'craft',
|
||||
slot = 15,
|
||||
})
|
||||
end
|
||||
|
||||
context.responseHandlers['craft'] = function(response)
|
||||
if response.success then
|
||||
Sound.play('entity.item.pickup')
|
||||
else
|
||||
Sound.play('entity.villager.no')
|
||||
end
|
||||
if response.success then
|
||||
Sound.play('entity.item.pickup')
|
||||
else
|
||||
Sound.play('entity.villager.no')
|
||||
end
|
||||
end
|
||||
|
||||
return {
|
||||
|
||||
@@ -9,36 +9,36 @@ local context = args[1]
|
||||
local SHIELD_SLOT = 2
|
||||
|
||||
Event.addRoutine(function()
|
||||
local lastTransfer
|
||||
while true do
|
||||
local sleepTime = 1.5
|
||||
if lastTransfer and os.clock() - lastTransfer < 2 then
|
||||
sleepTime = .1
|
||||
end
|
||||
local lastTransfer
|
||||
while true do
|
||||
local sleepTime = 1.5
|
||||
if lastTransfer and os.clock() - lastTransfer < 2 then
|
||||
sleepTime = .1
|
||||
end
|
||||
|
||||
os.sleep(context.socket and sleepTime or 5)
|
||||
if context.state.deposit and context.state.server and (context.state.useShield or context.state.slot) then
|
||||
local neural = device.neuralInterface
|
||||
local inv = context.state.useShield and 'getEquipment' or 'getInventory'
|
||||
if neural and neural[inv] then
|
||||
local s, m = pcall(function()
|
||||
local method = neural[inv]
|
||||
local item = method and method().list()[context.state.useShield and SHIELD_SLOT or context.state.slot]
|
||||
if item then
|
||||
if context:sendRequest({
|
||||
request = 'deposit',
|
||||
source = context.state.useShield and 'equipment' or 'inventory',
|
||||
slot = context.state.useShield and SHIELD_SLOT or context.state.slot,
|
||||
count = item.count,
|
||||
}) then
|
||||
lastTransfer = os.clock()
|
||||
end
|
||||
end
|
||||
end)
|
||||
if not s and m then
|
||||
_G._syslog(m)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
os.sleep(context.socket and sleepTime or 5)
|
||||
if context.state.deposit and context.state.server and (context.state.useShield or context.state.slot) then
|
||||
local neural = device.neuralInterface
|
||||
local inv = context.state.useShield and 'getEquipment' or 'getInventory'
|
||||
if neural and neural[inv] then
|
||||
local s, m = pcall(function()
|
||||
local method = neural[inv]
|
||||
local item = method and method().list()[context.state.useShield and SHIELD_SLOT or context.state.slot]
|
||||
if item then
|
||||
if context:sendRequest({
|
||||
request = 'deposit',
|
||||
source = context.state.useShield and 'equipment' or 'inventory',
|
||||
slot = context.state.useShield and SHIELD_SLOT or context.state.slot,
|
||||
count = item.count,
|
||||
}) then
|
||||
lastTransfer = os.clock()
|
||||
end
|
||||
end
|
||||
end)
|
||||
if not s and m then
|
||||
_G._syslog(m)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
@@ -10,70 +10,70 @@ local context = args[1]
|
||||
local ni = peripheral.find('neuralInterface')
|
||||
|
||||
if not context.state.depositAll then
|
||||
context.state.depositAll = { }
|
||||
context.state.depositAll = { }
|
||||
end
|
||||
if not context.state.depositAll.retain then
|
||||
context.state.depositAll.retain = { }
|
||||
context.state.depositAll.retain = { }
|
||||
end
|
||||
|
||||
local page = UI.Page {
|
||||
titleBar = UI.TitleBar {
|
||||
backgroundColor = colors.gray,
|
||||
title = 'Deposit full inventory',
|
||||
previousPage = true,
|
||||
},
|
||||
items = UI.ScrollingGrid {
|
||||
x = 2, ex = -2, y = 2, ey = -4,
|
||||
columns = {
|
||||
{ heading = 'Qty', key = 'count', width = 3 },
|
||||
{ heading = 'Name', key = 'displayName', },
|
||||
},
|
||||
sortColumn = 'count',
|
||||
inverseSort = true
|
||||
},
|
||||
form = UI.Form {
|
||||
x = 2, ex = -2, y = -2, ey = -2,
|
||||
margin = 1,
|
||||
[1] = UI.Checkbox {
|
||||
formLabel = 'Include hotbar', formKey = 'includeHotbar',
|
||||
help = 'Also send the contents of the hotbar to Milo (excluding the neural connector)'
|
||||
}
|
||||
},
|
||||
notification = UI.Notification(),
|
||||
titleBar = UI.TitleBar {
|
||||
backgroundColor = colors.gray,
|
||||
title = 'Deposit full inventory',
|
||||
previousPage = true,
|
||||
},
|
||||
items = UI.ScrollingGrid {
|
||||
x = 2, ex = -2, y = 2, ey = -4,
|
||||
columns = {
|
||||
{ heading = 'Qty', key = 'count', width = 3 },
|
||||
{ heading = 'Name', key = 'displayName', },
|
||||
},
|
||||
sortColumn = 'count',
|
||||
inverseSort = true
|
||||
},
|
||||
form = UI.Form {
|
||||
x = 2, ex = -2, y = -2, ey = -2,
|
||||
margin = 1,
|
||||
[1] = UI.Checkbox {
|
||||
formLabel = 'Include hotbar', formKey = 'includeHotbar',
|
||||
help = 'Also send the contents of the hotbar to Milo (excluding the neural connector)'
|
||||
}
|
||||
},
|
||||
notification = UI.Notification(),
|
||||
}
|
||||
|
||||
local function makeKey(item) -- group items regardless of damage
|
||||
local damage = item.maxDamage == 0 and item.damage
|
||||
return itemDB:makeKey({ name = item.name, damage = damage })
|
||||
local damage = item.maxDamage == 0 and item.damage
|
||||
return itemDB:makeKey({ name = item.name, damage = damage })
|
||||
end
|
||||
|
||||
function page:updateInventoryList()
|
||||
local inv = ni.getInventory().list()
|
||||
local list = { }
|
||||
local inv = ni.getInventory().list()
|
||||
local list = { }
|
||||
|
||||
for slot, item in pairs(inv) do
|
||||
if (context.state.depositAll.includeHotbar or slot > 9) and item.name ~= 'plethora:neuralconnector' then
|
||||
item = itemDB:get(item, function() return ni.getInventory().getItemMeta(slot) end)
|
||||
local key = makeKey(item)
|
||||
if not list[key] then
|
||||
item.displayName = item.displayName:match('(.+) %(damage:.+%)') or item.displayName
|
||||
list[key] = item
|
||||
else
|
||||
list[key].count = list[key].count + item.count
|
||||
end
|
||||
list[key].key = key
|
||||
end
|
||||
end
|
||||
for slot, item in pairs(inv) do
|
||||
if (context.state.depositAll.includeHotbar or slot > 9) and item.name ~= 'plethora:neuralconnector' then
|
||||
item = itemDB:get(item, function() return ni.getInventory().getItemMeta(slot) end)
|
||||
local key = makeKey(item)
|
||||
if not list[key] then
|
||||
item.displayName = item.displayName:match('(.+) %(damage:.+%)') or item.displayName
|
||||
list[key] = item
|
||||
else
|
||||
list[key].count = list[key].count + item.count
|
||||
end
|
||||
list[key].key = key
|
||||
end
|
||||
end
|
||||
|
||||
self.items:setValues(list)
|
||||
self.items:draw()
|
||||
itemDB:flush()
|
||||
self.items:setValues(list)
|
||||
self.items:draw()
|
||||
itemDB:flush()
|
||||
end
|
||||
|
||||
function page:enable()
|
||||
self.form:setValues(context.state.depositAll)
|
||||
self:updateInventoryList()
|
||||
UI.Page.enable(self)
|
||||
self.form:setValues(context.state.depositAll)
|
||||
self:updateInventoryList()
|
||||
UI.Page.enable(self)
|
||||
end
|
||||
|
||||
function page.items:getRowTextColor(row)
|
||||
@@ -84,57 +84,57 @@ function page.items:getRowTextColor(row)
|
||||
end
|
||||
|
||||
function page:depositAll()
|
||||
self.notification:info('Depositing all items...')
|
||||
self.notification:info('Depositing all items...')
|
||||
|
||||
local inv = ni.getInventory().list()
|
||||
local inv = ni.getInventory().list()
|
||||
|
||||
for slot, item in pairs(inv) do
|
||||
item = itemDB:get(item, function() return ni.getInventory().getItemMeta(slot) end)
|
||||
local key = makeKey(item)
|
||||
if not context.state.depositAll.retain[key] then
|
||||
if (context.state.depositAll.includeHotbar or slot > 9) and item.name ~= 'plethora:neuralconnector' then
|
||||
context:sendRequest({
|
||||
request = 'deposit',
|
||||
source = 'inventory',
|
||||
slot = slot,
|
||||
count = item.count,
|
||||
})
|
||||
end
|
||||
end
|
||||
end
|
||||
for slot, item in pairs(inv) do
|
||||
item = itemDB:get(item, function() return ni.getInventory().getItemMeta(slot) end)
|
||||
local key = makeKey(item)
|
||||
if not context.state.depositAll.retain[key] then
|
||||
if (context.state.depositAll.includeHotbar or slot > 9) and item.name ~= 'plethora:neuralconnector' then
|
||||
context:sendRequest({
|
||||
request = 'deposit',
|
||||
source = 'inventory',
|
||||
slot = slot,
|
||||
count = item.count,
|
||||
})
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function page:eventHandler(event)
|
||||
if event.type == 'checkbox_change' and event.element.formKey == 'includeHotbar' then
|
||||
context.state.depositAll.includeHotbar = event.checked
|
||||
page:updateInventoryList()
|
||||
if event.type == 'checkbox_change' and event.element.formKey == 'includeHotbar' then
|
||||
context.state.depositAll.includeHotbar = event.checked
|
||||
page:updateInventoryList()
|
||||
|
||||
elseif event.type == 'grid_select' then
|
||||
local key = event.selected.key
|
||||
if context.state.depositAll.retain[key] then
|
||||
context.state.depositAll.retain[key] = nil
|
||||
else
|
||||
context.state.depositAll.retain[key] = true
|
||||
end
|
||||
context:setState('depositAll', context.state.depositAll)
|
||||
self.items:draw()
|
||||
elseif event.type == 'grid_select' then
|
||||
local key = event.selected.key
|
||||
if context.state.depositAll.retain[key] then
|
||||
context.state.depositAll.retain[key] = nil
|
||||
else
|
||||
context.state.depositAll.retain[key] = true
|
||||
end
|
||||
context:setState('depositAll', context.state.depositAll)
|
||||
self.items:draw()
|
||||
|
||||
elseif event.type == 'form_complete' then
|
||||
Config.update('miloRemote', context.state)
|
||||
page:depositAll()
|
||||
UI:setPreviousPage()
|
||||
elseif event.type == 'form_complete' then
|
||||
Config.update('miloRemote', context.state)
|
||||
page:depositAll()
|
||||
UI:setPreviousPage()
|
||||
|
||||
elseif event.type == 'form_cancel' then
|
||||
UI:setPreviousPage()
|
||||
elseif event.type == 'form_cancel' then
|
||||
UI:setPreviousPage()
|
||||
|
||||
else
|
||||
return UI.Page.eventHandler(self, event)
|
||||
end
|
||||
else
|
||||
return UI.Page.eventHandler(self, event)
|
||||
end
|
||||
end
|
||||
|
||||
return {
|
||||
menuItem = 'Deposit all',
|
||||
callback = function()
|
||||
UI:setPage(page)
|
||||
end,
|
||||
menuItem = 'Deposit all',
|
||||
callback = function()
|
||||
UI:setPage(page)
|
||||
end,
|
||||
}
|
||||
|
||||
@@ -16,13 +16,13 @@ local page = UI.Page {
|
||||
title = 'Auto-feeder',
|
||||
previousPage = true,
|
||||
},
|
||||
grid = UI.ScrollingGrid {
|
||||
y = 2, ey = -2,
|
||||
columns = {
|
||||
{ heading = 'Name', key = 'displayName' },
|
||||
},
|
||||
sortColumn = 'displayName',
|
||||
},
|
||||
grid = UI.ScrollingGrid {
|
||||
y = 2, ey = -2,
|
||||
columns = {
|
||||
{ heading = 'Name', key = 'displayName' },
|
||||
},
|
||||
sortColumn = 'displayName',
|
||||
},
|
||||
statusBar = UI.StatusBar {
|
||||
values = 'Double-click to toggle'
|
||||
},
|
||||
@@ -55,45 +55,45 @@ function page.grid:getRowTextColor(row)
|
||||
end
|
||||
|
||||
local function getFood(food)
|
||||
for slot,v in pairs(ni.getInventory().list()) do
|
||||
local key = itemDB:makeKey(v)
|
||||
if key == food then
|
||||
local item = ni.getInventory().getItem(slot)
|
||||
if item and item.consume then
|
||||
return item
|
||||
end
|
||||
break
|
||||
end
|
||||
end
|
||||
for slot,v in pairs(ni.getInventory().list()) do
|
||||
local key = itemDB:makeKey(v)
|
||||
if key == food then
|
||||
local item = ni.getInventory().getItem(slot)
|
||||
if item and item.consume then
|
||||
return item
|
||||
end
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function page:eventHandler(event)
|
||||
if event.type == 'grid_select' then
|
||||
if context.state.food == event.selected.key then
|
||||
context:setState('food')
|
||||
self.grid:draw()
|
||||
elseif getFood(event.selected.key) then
|
||||
context:setState('food', event.selected.key)
|
||||
self.grid:draw()
|
||||
else
|
||||
Sound.play('entity.villager.no')
|
||||
end
|
||||
if event.type == 'grid_select' then
|
||||
if context.state.food == event.selected.key then
|
||||
context:setState('food')
|
||||
self.grid:draw()
|
||||
elseif getFood(event.selected.key) then
|
||||
context:setState('food', event.selected.key)
|
||||
self.grid:draw()
|
||||
else
|
||||
Sound.play('entity.villager.no')
|
||||
end
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
Event.onInterval(5, function()
|
||||
local s, m = pcall(function() -- prevent errors from some mod items
|
||||
if context.state.food and ni.getMetaOwner().food.hungry then
|
||||
local item = getFood(context.state.food)
|
||||
if item then
|
||||
item.consume()
|
||||
end
|
||||
end
|
||||
end)
|
||||
if not s and m then
|
||||
_G._syslog(m)
|
||||
end
|
||||
local s, m = pcall(function() -- prevent errors from some mod items
|
||||
if context.state.food and ni.getMetaOwner().food.hungry then
|
||||
local item = getFood(context.state.food)
|
||||
if item then
|
||||
item.consume()
|
||||
end
|
||||
end
|
||||
end)
|
||||
if not s and m then
|
||||
_G._syslog(m)
|
||||
end
|
||||
end)
|
||||
|
||||
return {
|
||||
|
||||
@@ -10,78 +10,78 @@ local STARTUP_FILE = 'usr/autorun/miloRemote.lua'
|
||||
local context = ({ ... })[1]
|
||||
|
||||
local setup = UI.SlideOut {
|
||||
backgroundColor = colors.cyan,
|
||||
titleBar = UI.TitleBar {
|
||||
title = 'Remote Setup',
|
||||
},
|
||||
form = UI.Form {
|
||||
x = 2, ex = -2, y = 2, ey = -1,
|
||||
[1] = UI.TextEntry {
|
||||
formLabel = 'Server', formKey = 'server',
|
||||
help = 'ID for the server',
|
||||
shadowText = 'Milo server ID',
|
||||
limit = 6,
|
||||
validate = 'numeric',
|
||||
required = true,
|
||||
},
|
||||
[2] = UI.TextEntry {
|
||||
formLabel = 'Return Slot', formKey = 'slot',
|
||||
help = 'Use a slot for sending to storage',
|
||||
shadowText = 'Inventory slot #',
|
||||
limit = 5,
|
||||
validate = 'numeric',
|
||||
required = false,
|
||||
},
|
||||
[3] = UI.Checkbox {
|
||||
formLabel = 'Shield Slot', formKey = 'useShield',
|
||||
help = 'Or, use the shield slot for sending'
|
||||
},
|
||||
[4] = UI.Checkbox {
|
||||
formLabel = 'Run on startup', formKey = 'runOnStartup',
|
||||
help = 'Run this program on startup'
|
||||
},
|
||||
info = UI.TextArea {
|
||||
x = 1, ex = -1, y = 6, ey = -4,
|
||||
textColor = colors.yellow,
|
||||
marginLeft = 0,
|
||||
marginRight = 0,
|
||||
value = [[The Milo turtle must connect to a manipulator with a ]] ..
|
||||
[[bound introspection module. The neural interface must ]] ..
|
||||
[[also have an introspection module.]],
|
||||
},
|
||||
},
|
||||
statusBar = UI.StatusBar {
|
||||
backgroundColor = colors.cyan,
|
||||
},
|
||||
backgroundColor = colors.cyan,
|
||||
titleBar = UI.TitleBar {
|
||||
title = 'Remote Setup',
|
||||
},
|
||||
form = UI.Form {
|
||||
x = 2, ex = -2, y = 2, ey = -1,
|
||||
[1] = UI.TextEntry {
|
||||
formLabel = 'Server', formKey = 'server',
|
||||
help = 'ID for the server',
|
||||
shadowText = 'Milo server ID',
|
||||
limit = 6,
|
||||
validate = 'numeric',
|
||||
required = true,
|
||||
},
|
||||
[2] = UI.TextEntry {
|
||||
formLabel = 'Return Slot', formKey = 'slot',
|
||||
help = 'Use a slot for sending to storage',
|
||||
shadowText = 'Inventory slot #',
|
||||
limit = 5,
|
||||
validate = 'numeric',
|
||||
required = false,
|
||||
},
|
||||
[3] = UI.Checkbox {
|
||||
formLabel = 'Shield Slot', formKey = 'useShield',
|
||||
help = 'Or, use the shield slot for sending'
|
||||
},
|
||||
[4] = UI.Checkbox {
|
||||
formLabel = 'Run on startup', formKey = 'runOnStartup',
|
||||
help = 'Run this program on startup'
|
||||
},
|
||||
info = UI.TextArea {
|
||||
x = 1, ex = -1, y = 6, ey = -4,
|
||||
textColor = colors.yellow,
|
||||
marginLeft = 0,
|
||||
marginRight = 0,
|
||||
value = [[The Milo turtle must connect to a manipulator with a ]] ..
|
||||
[[bound introspection module. The neural interface must ]] ..
|
||||
[[also have an introspection module.]],
|
||||
},
|
||||
},
|
||||
statusBar = UI.StatusBar {
|
||||
backgroundColor = colors.cyan,
|
||||
},
|
||||
}
|
||||
|
||||
function setup:eventHandler(event)
|
||||
if event.type == 'focus_change' then
|
||||
self.statusBar:setStatus(event.focused.help)
|
||||
if event.type == 'focus_change' then
|
||||
self.statusBar:setStatus(event.focused.help)
|
||||
|
||||
elseif event.type == 'form_complete' then
|
||||
Config.update('miloRemote', context.state)
|
||||
self:hide()
|
||||
context.page:refresh('list')
|
||||
context.page.grid:draw()
|
||||
context.page:setFocus(context.page.statusBar.filter)
|
||||
elseif event.type == 'form_complete' then
|
||||
Config.update('miloRemote', context.state)
|
||||
self:hide()
|
||||
context.page:refresh('list')
|
||||
context.page.grid:draw()
|
||||
context.page:setFocus(context.page.statusBar.filter)
|
||||
|
||||
if context.state.runOnStartup then
|
||||
if not fs.exists(STARTUP_FILE) then
|
||||
Util.writeFile(STARTUP_FILE,
|
||||
[[os.sleep(1)
|
||||
if context.state.runOnStartup then
|
||||
if not fs.exists(STARTUP_FILE) then
|
||||
Util.writeFile(STARTUP_FILE,
|
||||
[[os.sleep(1)
|
||||
shell.openForegroundTab('packages/milo/MiloRemote')]])
|
||||
end
|
||||
elseif fs.exists(STARTUP_FILE) then
|
||||
fs.delete(STARTUP_FILE)
|
||||
end
|
||||
end
|
||||
elseif fs.exists(STARTUP_FILE) then
|
||||
fs.delete(STARTUP_FILE)
|
||||
end
|
||||
|
||||
elseif event.type == 'form_cancel' then
|
||||
self:hide()
|
||||
context.page:setFocus(context.page.statusBar.filter)
|
||||
end
|
||||
elseif event.type == 'form_cancel' then
|
||||
self:hide()
|
||||
context.page:setFocus(context.page.statusBar.filter)
|
||||
end
|
||||
|
||||
return UI.SlideOut.eventHandler(self, event)
|
||||
return UI.SlideOut.eventHandler(self, event)
|
||||
end
|
||||
|
||||
context.page:add({ setup = setup })
|
||||
|
||||
Reference in New Issue
Block a user