milo: drop from trashcans
This commit is contained in:
@@ -251,27 +251,13 @@ The settings will take effect immediately!]],
|
||||
x = 2, y = -4, height = 3,
|
||||
margin = 1,
|
||||
manualControls = true,
|
||||
[1] = UI.Chooser {
|
||||
width = 7,
|
||||
[1] = UI.Checkbox {
|
||||
formLabel = 'Ignore Dmg', formKey = 'ignoreDamage',
|
||||
pruneEmpty = true,
|
||||
nochoice = 'No',
|
||||
choices = {
|
||||
{ name = 'Yes', value = true },
|
||||
{ name = 'No', value = false },
|
||||
},
|
||||
help = 'Ignore damage of item'
|
||||
help = 'Ignore damage of item',
|
||||
},
|
||||
[2] = UI.Chooser {
|
||||
width = 7,
|
||||
[2] = UI.Checkbox {
|
||||
formLabel = 'Ignore NBT', formKey = 'ignoreNbtHash',
|
||||
pruneEmpty = true,
|
||||
nochoice = 'No',
|
||||
choices = {
|
||||
{ name = 'Yes', value = true },
|
||||
{ name = 'No', value = false },
|
||||
},
|
||||
help = 'Ignore NBT of item'
|
||||
help = 'Ignore NBT of item',
|
||||
},
|
||||
[3] = UI.Chooser {
|
||||
width = 13,
|
||||
|
||||
@@ -1,29 +1,52 @@
|
||||
local Ansi = require('ansi')
|
||||
local UI = require('ui')
|
||||
local Milo = require('milo')
|
||||
local UI = require('ui')
|
||||
|
||||
local colors = _G.colors
|
||||
local device = _G.device
|
||||
local colors = _G.colors
|
||||
local device = _G.device
|
||||
|
||||
--[[ Configuration Screen ]]
|
||||
local template =
|
||||
[[%sUse this inventory as a trashcan%s
|
||||
|
||||
If the number of items exceed the maximum value will be sent to this inventory.
|
||||
|
||||
Any items that cannot fit into a locked chest will automatically be sent to this inventory.
|
||||
]]
|
||||
|
||||
local trashcanWizardPage = UI.Window {
|
||||
local wizardPage = UI.Window {
|
||||
title = 'Trashcan',
|
||||
index = 2,
|
||||
backgroundColor = colors.cyan,
|
||||
[1] = UI.TextArea {
|
||||
x = 2, ex = -2, y = 2, ey = -2,
|
||||
value = string.format(template, Ansi.yellow, Ansi.reset),
|
||||
form = UI.Form {
|
||||
x = 1, y = 1, ex = -1, ey = -2,
|
||||
manualControls = true,
|
||||
[1] = UI.Checkbox {
|
||||
formLabel = 'Drop', formKey = 'drop',
|
||||
help = 'Drop the items out of this inventory',
|
||||
},
|
||||
[2] = UI.Chooser {
|
||||
width = 9,
|
||||
formLabel = 'Drop direction', formKey = 'dropDirection',
|
||||
nochoice = 'Down',
|
||||
choices = {
|
||||
{ name = 'Down', value = 'down' },
|
||||
{ name = 'Up', value = 'up' },
|
||||
{ name = 'North', value = 'north' },
|
||||
{ name = 'South', value = 'south' },
|
||||
{ name = 'East', value = 'east' },
|
||||
{ name = 'West', value = 'west' },
|
||||
},
|
||||
help = 'Drop in a specified direction'
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
function trashcanWizardPage:isValidType(node)
|
||||
function wizardPage:enable()
|
||||
UI.Window.enable(self)
|
||||
self:focusFirst()
|
||||
end
|
||||
|
||||
function wizardPage:validate()
|
||||
return self.form:save()
|
||||
end
|
||||
|
||||
function wizardPage:setNode(node)
|
||||
self.form:setValues(node)
|
||||
end
|
||||
|
||||
function wizardPage:isValidType(node)
|
||||
local m = device[node.name]
|
||||
return m and m.pullItems and {
|
||||
name = 'Trashcan',
|
||||
@@ -32,8 +55,29 @@ function trashcanWizardPage:isValidType(node)
|
||||
}
|
||||
end
|
||||
|
||||
function trashcanWizardPage:isValidFor(node)
|
||||
function wizardPage:isValidFor(node)
|
||||
return node.mtype == 'trashcan'
|
||||
end
|
||||
|
||||
UI:getPage('nodeWizard').wizard:add({ trashcan = trashcanWizardPage })
|
||||
UI:getPage('nodeWizard').wizard:add({ trashcan = wizardPage })
|
||||
|
||||
--[[ TASK ]]--
|
||||
local task = {
|
||||
name = 'trashcan',
|
||||
priority = 90,
|
||||
}
|
||||
|
||||
local function filter(a)
|
||||
return a.drop
|
||||
end
|
||||
|
||||
function task:cycle(context)
|
||||
for node in context.storage:filterActive('trashcan', filter) do
|
||||
for k in pairs(node.adapter.list()) do
|
||||
local direction = node.dropDirection or 'down'
|
||||
node.adapter.drop(k, 64, direction)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Milo:registerTask(task)
|
||||
|
||||
Reference in New Issue
Block a user