From afcbfd1b0427d92debf6f2cf2b4be29a5607c397 Mon Sep 17 00:00:00 2001 From: Anavrins Date: Mon, 24 Feb 2020 21:10:30 -0500 Subject: [PATCH] Added a "Level Emitter" to Milo --- milo/plugins/emitterTask.lua | 29 +++++++++ milo/plugins/emitterView.lua | 109 ++++++++++++++++++++++++++++++++++ milo/plugins/item/infoTab.lua | 3 + 3 files changed, 141 insertions(+) create mode 100644 milo/plugins/emitterTask.lua create mode 100644 milo/plugins/emitterView.lua diff --git a/milo/plugins/emitterTask.lua b/milo/plugins/emitterTask.lua new file mode 100644 index 0000000..b5088dd --- /dev/null +++ b/milo/plugins/emitterTask.lua @@ -0,0 +1,29 @@ +local itemDB = require('core.itemDB') +local Milo = require('milo') + +local device = _G.device + +local EmitterTask = { + name = 'emitter', + priority = 5, +} + +local function filter(a) + return a.emitter +end + +function EmitterTask:cycle(context) + for node in context.storage:filterActive('emitter', filter) do + local config = node.emitter + local item = Milo:getItem(itemDB:splitKey(config.item)) + + config.signal = not not config.signal + if item and item.count >= config.amount then + device[node.name].setOutput(config.side, config.signal) + else + device[node.name].setOutput(config.side, not config.signal) + end + end +end + +Milo:registerTask(EmitterTask) diff --git a/milo/plugins/emitterView.lua b/milo/plugins/emitterView.lua new file mode 100644 index 0000000..f3c51d3 --- /dev/null +++ b/milo/plugins/emitterView.lua @@ -0,0 +1,109 @@ +local Milo = require('milo') +local UI = require('opus.ui') +local itemDB = require('core.itemDB') + +local colors = _G.colors +local device = _G.device +local context = Milo:getContext() + +local wizardPage = UI.WizardPage { + title = 'Level Emitter', + index = 2, + backgroundColor = colors.cyan, + [1] = UI.TextArea { + x = 2, y = 1, + height = 2, + textColor = colors.yellow, + value = 'Emit a redstone signal if an\nitem amount if over a threshold', + }, + form = UI.Form { + x = 1, ex = -1, y = 3, ey = -1, + manualControls = true, + + itemName = UI.TextEntry { + formLabel = 'Item', formKey = 'item', formIndex = 1, + help = 'Item to monitor', + required = true, + }, + side = UI.Chooser { + formLabel = 'Side', formKey = 'side', formIndex = 2, + width = 10, + choices = { + {name = 'Down', value = 'down'}, + {name = 'Up', value = 'up'}, + {name = 'North', value = 'north'}, + {name = 'South', value = 'south'}, + {name = 'West', value = 'west'}, + {name = 'East', value = 'east'}, + }, + required = true, + }, + amount = UI.TextEntry { + formLabel = 'Amount', formKey = 'amount', formIndex = 3, + width = 7, + transform = 'number', + help = 'Threshold value', + required = true, + }, + signal = UI.Checkbox { + formLabel = 'Signal', formKey = 'signal', formIndex = 4, + help = 'Enable redstone signal when over threshold', + }, + scanItem = UI.Button { + x = 15, y = 6, + text = 'Scan item', event = 'scan_turtle', + help = 'Scan an item from the turtle inventory', + }, + }, +} + +function wizardPage:setNode(node) + self.node = node + if not self.node.emitter then + self.node.emitter = { + signal = { value = true } + } + end + self.form:setValues(self.node.emitter) +end + +function wizardPage:validate() + return self.form:save() +end + +function wizardPage:isValidType(node) + local m = device[node.name] + return m and m.type == 'redstone_integrator' and { + name = 'Level Emitter', + value = 'emitter', + category = 'custom', + help = 'Emit redstone signals', + } +end + +function wizardPage:isValidFor(node) + return node.mtype == 'emitter' +end + +function wizardPage:enable() + Milo:pauseCrafting({ key = 'gridInUse', msg = 'Crafting paused' }) + UI.WizardPage.enable(self) +end +function wizardPage:disable() + Milo:resumeCrafting({ key = 'gridInUse' }) + UI.WizardPage.disable(self) +end + +function wizardPage:eventHandler(event) + if event.type == 'scan_turtle' then + local inventory = Milo:getTurtleInventory() + for _,item in pairs(inventory) do + self.form.itemName.value = itemDB:makeKey(item) + break + end + self:draw() + Milo:emptyInventory() + end +end + +UI:getPage('nodeWizard').wizard:add({ emiter = wizardPage }) diff --git a/milo/plugins/item/infoTab.lua b/milo/plugins/item/infoTab.lua index 7ae99c7..92bb37d 100644 --- a/milo/plugins/item/infoTab.lua +++ b/milo/plugins/item/infoTab.lua @@ -27,6 +27,9 @@ function infoTab:draw() value = value .. item.nbtHash .. '\n' end + value = value .. string.format('\n%sCount:%s %s', + Ansi.yellow, Ansi.reset, item.count) + value = value .. string.format('\n%sDamage:%s %s', Ansi.yellow, Ansi.reset, item.damage)