diff --git a/common/Devices.lua b/common/Devices.lua index 22177b9..fc2cecd 100644 --- a/common/Devices.lua +++ b/common/Devices.lua @@ -3,7 +3,6 @@ local Event = require('opus.event') local UI = require('opus.ui') local Util = require('opus.util') -local colors = _G.colors local peripheral = _G.peripheral --[[ -- PeripheralsPage -- ]] -- @@ -16,6 +15,20 @@ local peripheralsPage = UI.Page { }, sortColumn = 'type', autospace = true, + enable = function(self) + local sides = peripheral.getNames() + + Util.clear(self.values) + for _,side in pairs(sides) do + table.insert(self.values, { + type = peripheral.getType(side), + side = side + }) + end + self:update() + self:adjustWidth() + UI.Grid.enable(self) + end, }, statusBar = UI.StatusBar { values = 'Select peripheral', @@ -23,47 +36,30 @@ local peripheralsPage = UI.Page { accelerators = { [ 'control-q' ] = 'quit', }, + updatePeripherals = function(self) + if UI:getCurrentPage() == self then + self.grid:draw() + self:sync() + end + end, + eventHandler = function(self, event) + if event.type == 'quit' then + UI:quit() + + elseif event.type == 'grid_select' then + UI:setPage('methods', event.selected) + + end + return UI.Page.eventHandler(self, event) + end, } -function peripheralsPage.grid:enable() - local sides = peripheral.getNames() - - Util.clear(self.values) - for _,side in pairs(sides) do - table.insert(self.values, { - type = peripheral.getType(side), - side = side - }) - end - self:update() - self:adjustWidth() - UI.Grid.enable(self) -end - -function peripheralsPage:updatePeripherals() - if UI:getCurrentPage() == self then - self.grid:draw() - self:sync() - end -end - -function peripheralsPage:eventHandler(event) - if event.type == 'quit' then - UI:quit() - - elseif event.type == 'grid_select' then - UI:setPage('methods', event.selected) - - end - return UI.Page.eventHandler(self, event) -end - --[[ -- MethodsPage -- ]] -- local methodsPage = UI.Page { - backgroundColor = colors.black, doc = UI.TextArea { - backgroundColor = colors.black, - x = 2, y = 2, ex = -1, ey = -7, + backgroundColor = 'black', + ey = -7, + marginLeft = 1, marginTop = 1, }, grid = UI.ScrollingGrid { y = -6, ey = -2, diff --git a/common/DiskCopy.lua b/common/DiskCopy.lua index ef1f4a6..b3efc4e 100644 --- a/common/DiskCopy.lua +++ b/common/DiskCopy.lua @@ -137,6 +137,7 @@ function page:scan() self.copyButton.inactive = not valid self:draw() + self.progress:clear() self.progress:centeredWrite(1, 'Analyzing Disks..') self.progress:sync() @@ -166,6 +167,7 @@ function page:copy() throttle() end + self.progress:clear() self.progress:centeredWrite(1, 'Computing..') self.progress:sync() @@ -210,6 +212,8 @@ function page:copy() self.progress:clear() rawCopy(sdrive.getMountPath(), tdrive.getMountPath()) cleanup() + + self.progress:clear() self.progress:centeredWrite(1, 'Copy Complete', colors.lime, colors.black) self.progress:sync() diff --git a/common/Turtles.lua b/common/Turtles.lua index 38bf888..cc48825 100644 --- a/common/Turtles.lua +++ b/common/Turtles.lua @@ -131,7 +131,7 @@ page = UI.Page { columns = { { heading = '', key = 'index', width = 2 }, { heading = '', key = 'count', width = 2 }, - { heading = 'Inventory', key = 'key', width = UI.term.width - 7 }, + { heading = 'Inventory', key = 'key' }, }, disableHeader = true, sortColumn = 'index', diff --git a/common/edit.lua b/common/edit.lua index 7dcd028..804d40c 100644 --- a/common/edit.lua +++ b/common/edit.lua @@ -4,7 +4,6 @@ local fuzzy = require('opus.fuzzy') local UI = require('opus.ui') local Util = require('opus.util') -local colors = _G.colors local device = _G.device local fs = _G.fs local multishell = _ENV.multishell @@ -39,19 +38,25 @@ local undo = { chain = { }, redo = { } } h = h - 1 +local bgColor = 'gray' local color = { - textColor = '0', - keywordColor = '4', - commentColor = 'd', - stringColor = 'e', + text = '0', + keyword = '2', + comment = 'd', + string = '1', + mark = '8', + bg = '7', } if not term.isColor() then + bgColor = 'black' color = { - textColor = '0', - keywordColor = '8', - commentColor = '8', - stringColor = '8', + text = '0', + keyword = '8', + comment = '8', + string = '8', + mark = '7', + bg = 'f', } end @@ -161,7 +166,7 @@ local page = UI.Page { } }, }, status = UI.Text { - textColor = colors.gray, + textColor = 'gray', x = -9, width = 9, align = 'right', }, @@ -172,8 +177,6 @@ local page = UI.Page { lineNo = UI.TextEntry { x = 7, width = 7, limit = 5, - backgroundFocusColor = colors.gray, - backgroundColor = colors.gray, transform = 'number', accelerators = { [ 'enter' ] = 'accept', @@ -200,9 +203,6 @@ local page = UI.Page { search = UI.TextEntry { x = 7, ex = -3, limit = 512, - markBackgroundColor = colors.lightGray, - backgroundFocusColor = colors.gray, - backgroundColor = colors.gray, accelerators = { [ 'enter' ] = 'accept', }, @@ -233,9 +233,6 @@ local page = UI.Page { filename = UI.TextEntry { x = 7, ex = -3, limit = 512, - markBackgroundColor = colors.lightGray, - backgroundFocusColor = colors.gray, - backgroundColor = colors.gray, accelerators = { [ 'enter' ] = 'accept', }, @@ -263,7 +260,7 @@ local page = UI.Page { cancel = UI.Button { x = 16, text = 'Cancel', - backgroundColor = UI.colors.primary, + backgroundColor = 'primary', event = 'question_cancel', }, show = function(self, action) @@ -355,7 +352,7 @@ local page = UI.Page { disableHeader = true, columns = { { key = 'name' }, - { key = 'dir', textColor = colors.lightGray }, + { key = 'dir', textColor = 'lightGray' }, }, accelerators = { grid_select = 'accept', @@ -453,9 +450,9 @@ local page = UI.Page { cancel = UI.Button { y = -1, x = -9, text = 'Cancel', - backgroundColor = colors.black, - backgroundFocusColor = colors.black, - textColor = colors.lightGray, + backgroundColor = 'black', + backgroundFocusColor = 'black', + textColor = 'lightGray', event = 'slide_hide', }, show = function(self, values) @@ -540,9 +537,9 @@ local page = UI.Page { cancel = UI.Button { y = -1, x = -9, text = 'Cancel', - backgroundColor = colors.black, - backgroundFocusColor = colors.black, - textColor = colors.lightGray, + backgroundColor = 'black', + backgroundFocusColor = 'black', + textColor = 'lightGray', event = 'slide_hide', }, eventHandler = function(self, event) @@ -562,7 +559,7 @@ local page = UI.Page { }, editor = UI.Window { y = 2, - backgroundColor = colors.black, + backgroundColor = bgColor, transitionHint = 'slideRight', cursorBlink = true, focus = function(self) @@ -687,15 +684,15 @@ local function writeHighlighted(sLine, ny, dy) while #sLine > 0 do sLine = -- tryWrite(sLine, "^[%\26]", '7' ) or - tryWrite(sLine, "^%-%-%[%[.-%]%]", color.commentColor ) or - tryWrite(sLine, "^%-%-.*", color.commentColor ) or - tryWrite(sLine, "^\".-[^\\]\"", color.stringColor ) or - tryWrite(sLine, "^\'.-[^\\]\'", color.stringColor ) or - tryWrite(sLine, "^%[%[.-%]%]", color.stringColor ) or + tryWrite(sLine, "^%-%-%[%[.-%]%]", color.comment ) or + tryWrite(sLine, "^%-%-.*", color.comment ) or + tryWrite(sLine, "^\".-[^\\]\"", color.string ) or + tryWrite(sLine, "^\'.-[^\\]\'", color.string ) or + tryWrite(sLine, "^%[%[.-%]%]", color.string ) or tryWrite(sLine, "^[%w_]+", function(match) - return keywords[match] and color.keywordColor or color.textColor + return keywords[match] and color.keyword or color.text end) or - tryWrite(sLine, "^[^%w_]", color.textColor) + tryWrite(sLine, "^[^%w_]", color.text) end buffer.fg = _concat(buffer.fg) .. '7' @@ -704,11 +701,11 @@ local function writeHighlighted(sLine, ny, dy) if mark.active and ny >= mark.y and ny <= mark.ey then local sx = ny == mark.y and mark.x or 1 local ex = ny == mark.ey and mark.ex or #buffer.text - buffer.bg = _rep('f', sx - 1) .. - _rep('7', ex - sx) .. - _rep('f', #buffer.text - ex + 1) + buffer.bg = _rep(color.bg, sx - 1) .. + _rep(color.mark, ex - sx) .. + _rep(color.bg, #buffer.text - ex + 1) else - buffer.bg = _rep('f', #buffer.text) + buffer.bg = _rep(color.bg, #buffer.text) end page.editor:blit(1 - scrollX, dy, buffer.text, buffer.bg, buffer.fg) @@ -860,7 +857,6 @@ actions = { end actions.go_to(nx, ny) actions.mark_to(nx + #pattern, ny) - actions.go_to(nx, ny) return end sx = 1 diff --git a/common/recorder.lua b/common/recorder.lua index 908e58f..4ea8824 100644 --- a/common/recorder.lua +++ b/common/recorder.lua @@ -19,10 +19,14 @@ local Util = require('opus.util') local multishell = _ENV.multishell local os = _G.os -local recTerm, oldTerm, arg, showInput, skipLast, lastDelay, curInput = {}, Util.shallowCopy(multishell.term), {...}, false, false, 2, "" +local colours = _G.colors + +local args, options = Util.parse(...) + +local oldTerm, showInput, skipLast, lastDelay, curInput = Util.shallowCopy(multishell.term), false, false, 2, "" local curBlink, oldBlink, tTerm, buffer, colourNum, xPos, yPos, oldXPos, oldYPos, tCol, bCol, xSize, ySize = false, false, {}, {}, {}, 1, 1, 1, 1, colours.white, colours.black, oldTerm.getSize() local greys, buttons = {["0"] = true, ["7"] = true, ["8"] = true, ["f"] = true}, {"l", "r", "m"} -local charW, charH, chars, resp +local charW, charH, chars local calls = { } local curCalls = { delay = 0 } @@ -32,38 +36,44 @@ local callCount = 0 local function showSyntax() print('Gif Recorder by Bomb Bloke\n') print('Syntax: recGif [-i] [-s] [-ld:] filename') - print(' -i : show input') - print(' -s : skip last') - print(' -ld : last delay') + print(' --showInput : show input') + print(' --skipLast : skip last') + print(' --lastDelay : last delay') + print(' --noResize : dont resize') end -for i = #arg, 1, -1 do - local curArg = arg[i]:lower() - - if curArg == "-i" then - showInput, ySize = true, ySize + 1 - table.remove(arg, i) - elseif curArg == "-s" then - skipLast = true - table.remove(arg, i) - elseif curArg:sub(1, 4) == "-ld:" then - curArg = tonumber(curArg:sub(5)) - if curArg then lastDelay = curArg end - table.remove(arg, i) - elseif curArg == '-?' then - showSyntax() - return - elseif i ~= #arg then - showSyntax() - printError('\nInvalid argument') - return - end +if options.showInput then + showInput, ySize = true, ySize + 1 end -print('Gif Recorder by Bomb Bloke\n') -print('Press control-p to stop recording') +if options.skipLast then + skipLast = true +end -local filename = arg[#arg] +if options.lastDelay then + lastDelay = options.lastDelay +end + +if options.help then + showSyntax() + return +end + +if options.daemon then + device.keyboard.addHotkey('control-P', function() + multishell.openTab({ + path = 'sys/apps/shell.lua', + args = { arg[0], '--noResize', '--rawOutput', 'recorder.gif' }, + }) + end) + return +end + +print('Gif Recorder by Bomb Bloke') +print(version) +print('\nPress control-p to stop recording') + +local filename = args[1] if not filename then print('Enter file name:') filename = read() @@ -131,7 +141,7 @@ end -- Build a terminal that records stuff: -recTerm = multishell.term +local recTerm = multishell.term for key, func in pairs(oldTerm) do if type(func) == 'function' then @@ -149,21 +159,16 @@ for key, func in pairs(oldTerm) do end local tabId = multishell.getCurrent() +multishell.hideTab(tabId) + +if not options.noResize then + os.queueEvent('term_resize') +end _G.device.keyboard.addHotkey('control-p', function() os.queueEvent('recorder_stop') end) -local tabs = multishell.getTabs() -for _,tab in pairs(tabs) do - if tab.isOverview then - multishell.hideTab(tabId) - multishell.setFocus(tab.tabId) - os.queueEvent('term_resize') - break - end -end - local curTime = os.clock() - 1 while true do @@ -202,8 +207,12 @@ if skipLast and #calls > 1 then calls[#calls] = nil end calls[#calls].delay = lastDelay +if options.rawOutput then + Util.writeTable('tmp/raw.txt', calls) + return +end + print(string.format("Encoding %d frames...", #calls)) ---Util.writeTable('tmp/raw.txt', calls) -- Perform a quick re-parse of the recorded data (adding frames for when the cursor blinks): diff --git a/milo/MiloRemote.lua b/milo/MiloRemote.lua index f9c6e8c..1f2caa8 100644 --- a/milo/MiloRemote.lua +++ b/milo/MiloRemote.lua @@ -63,8 +63,8 @@ local page = UI.Page { x = 1, ex = -13, limit = 50, shadowText = 'filter', - backgroundColor = UI.colors.primary, - backgroundFocusColor = UI.colors.primary, + backgroundColor = 'primary', + backgroundFocusColor = 'primary', accelerators = { [ 'enter' ] = 'eject', [ 'up' ] = 'grid_up', diff --git a/milo/apis/massAdapter.lua b/milo/apis/massAdapter.lua deleted file mode 100644 index f272e4b..0000000 --- a/milo/apis/massAdapter.lua +++ /dev/null @@ -1,53 +0,0 @@ -local class = require('opus.class') -local itemDB = require('core.itemDB') -local Mini = require('milo.miniAdapter') - -local os = _G.os - -local Adapter = class(Mini) - -function Adapter:init(args) - Mini.init(self, args) - - self._rawList = self.list - - function self.list() - -- wait for up to 1 sec until any items that have been inserted - -- into interface are added to the system - for _ = 0, 20 do - if #self._rawList() == 0 then - break - end - os.sleep(0) - end - - local list = { } - for _, v in pairs(self.listAvailableItems()) do - list[itemDB:makeKey(v)] = v - end - return list - end - - function self.getItemMeta(key) - local item = self.findItem(itemDB:splitKey(key)) - if item and item.getMetadata then - return item.getMetadata() - end - end - - function self.pushItems(target, key, amount, slot) - local item = self.findItem(itemDB:splitKey(key)) - if item and item.export then - return item.export(target, amount, slot) - end - return 0 - end - - function self.pullItems(target, key, amount, slot) - _G._syslog({target, key, amount, slot }) - return 0 - end - -end - -return Adapter diff --git a/milo/core/listing.lua b/milo/core/listing.lua index aa23978..34f1b6c 100644 --- a/milo/core/listing.lua +++ b/milo/core/listing.lua @@ -54,8 +54,8 @@ local page = UI.Page { limit = 50, shadowText = 'filter', shadowTextColor = colors.gray, - backgroundColor = UI.colors.primary, - backgroundFocusColor = UI.colors.primary, + backgroundColor = 'primary', + backgroundFocusColor = 'primary', accelerators = { [ 'enter' ] = 'eject', [ 'up' ] = 'grid_up', @@ -66,7 +66,7 @@ local page = UI.Page { storageStatus = UI.Text { x = -17, ex = -10, textColor = colors.lime, - backgroundColor = UI.colors.primary, + backgroundColor = 'primary', value = '', }, amount = UI.TextEntry { diff --git a/milo/core/machines.lua b/milo/core/machines.lua index 23cb9f1..b3779db 100644 --- a/milo/core/machines.lua +++ b/milo/core/machines.lua @@ -21,8 +21,8 @@ local networkPage = UI.Page { y = -2, x = 1, ex = -9, limit = 50, shadowText = 'filter', - backgroundColor = UI.colors.primary, - backgroundFocusColor = UI.colors.primary, + backgroundColor = 'primary', + backgroundFocusColor = 'primary', }, grid = UI.ScrollingGrid { y = 2, ey = -3, @@ -234,7 +234,7 @@ The settings will take effect immediately!]], }, }, statusBar = UI.StatusBar { - backgroundColor = UI.colors.primary, + backgroundColor = 'primary', }, notification = UI.Notification { }, filter = UI.SlideOut { @@ -289,7 +289,7 @@ The settings will take effect immediately!]], }, }, statusBar = UI.StatusBar { - backgroundColor = UI.colors.primary, + backgroundColor = 'primary', }, }, } diff --git a/milo/plugins/item.lua b/milo/plugins/item.lua index c6dcd85..75c2fc4 100644 --- a/milo/plugins/item.lua +++ b/milo/plugins/item.lua @@ -41,7 +41,6 @@ function page:eventHandler(event) elseif event.type == 'focus_change' then self.statusBar:setStatus(event.focused.help) - self.statusBar:draw() elseif event.type == 'success_message' then self.notification:success(event.message) diff --git a/milo/plugins/massStorageView.lua b/milo/plugins/massStorageView.lua deleted file mode 100644 index e198b3e..0000000 --- a/milo/plugins/massStorageView.lua +++ /dev/null @@ -1,43 +0,0 @@ -local Ansi = require('opus.ansi') -local UI = require('opus.ui') - -local colors = _G.colors -local device = _G.device - ---[[ Configuration Screen ]] -local template = -[[%sWarning%s - -Must an interface for Refined Storage / Applied Energistics. - -Add all speed upgrades possible. -]] - -local wizardPage = UI.WizardPage { - title = 'Mass Storage', - index = 2, - backgroundColor = colors.cyan, - [1] = UI.TextArea { - x = 2, ex = -2, y = 2, ey = -2, - value = string.format(template, Ansi.red, Ansi.reset), - }, -} - -function wizardPage:isValidFor(node) - if node.mtype == 'storage' then - local m = device[node.name] - return m and m.listAvailableItems - end -end - -function wizardPage:setNode(node) - self.node = node -end - -function wizardPage:validate() - self.node.adapterType = 'massAdapter' - return true -end - --- disable until a way is found to transfer between 2 non-transferrable nodes --- UI:getPage('nodeWizard').wizard:add({ inputChest = wizardPage }) diff --git a/milo/plugins/remote/setup.lua b/milo/plugins/remote/setup.lua index 4688300..856278d 100644 --- a/milo/plugins/remote/setup.lua +++ b/milo/plugins/remote/setup.lua @@ -50,7 +50,7 @@ local setup = UI.SlideOut { [[also have an introspection module.]], }, statusBar = UI.StatusBar { - backgroundColor = UI.colors.primary, + backgroundColor = 'primary', }, } diff --git a/neural/mobRancher.lua b/neural/mobRancher.lua index 51ce614..cef0975 100644 --- a/neural/mobRancher.lua +++ b/neural/mobRancher.lua @@ -35,6 +35,12 @@ neural.assertModules({ 'plethora:introspection', }) +local caninimals = config.animals or { [ config.animal ] = true } +local animals = { } +for k in pairs(caninimals) do + animals[k] = { } +end + local fed = { } local function resupply() @@ -49,10 +55,12 @@ local function resupply() print('dispenser not found') break end - if math.abs(dispenser.x) <= 1 and math.abs(dispenser.z) <= 1 then + if math.abs(dispenser.x) <= 1.2 and math.abs(dispenser.z) <= 1.2 then neural.lookAt({ x = dispenser.x, y = dispenser.y, z = dispenser.z }) for _ = 1, 8 do - neural.use(0, 'off') + if not neural.use(0, 'off') then + break + end os.sleep(.2) neural.getEquipment().suck(2, 64) end @@ -64,21 +72,22 @@ local function resupply() end local function breed(entity) - print('breeding') - entity.lastFed = os.clock() - fed[entity.id] = entity + print('breeding ' .. entity.name) neural.walkTo(entity, WALK_SPEED, 1) entity = neural.getMetaByID(entity.id) if entity then neural.lookAt(entity) - neural.use(1, 'off') + if neural.use(1, 'off') then + entity.lastFed = os.clock() + fed[entity.id] = entity + end os.sleep(.1) end end local function kill(entity) - print('killing') + print('killing ' .. entity.name) neural.walkTo(entity, WALK_SPEED, (neural.fire or neural.shoot) and 2.5 or .5) entity = neural.getMetaByID(entity.id) if entity then @@ -93,21 +102,28 @@ local function kill(entity) end end -local function getEntities() - local sheep = Array.filter(neural.sense(), function(entity) - if entity.name == 'Sheep' and entity.y > -.5 then - return true - end - end) - if #sheep > config.maxAdults then - return sheep +local function shuffle(tbl) + for i = #tbl, 2, -1 do + local j = math.random(i) + tbl[i], tbl[j] = tbl[j], tbl[i] end + return tbl +end - return Map.filter(neural.sense(), function(entity) - if entity.name == config.animal and entity.y > -.5 then - return true +local function getEntities() + return shuffle(Array.filter(neural.sense(), function(entity) + if animals[entity.name] then + if not animals[entity.name].height then + entity = neural.getMetaByID(entity.id) + if entity and not entity.isChild and entity.motionX == 0 and entity.motionZ == 0 then + animals[entity.name].height = entity.y + return true + end + elseif entity.y == animals[entity.name].height then + return true + end end - end) + end)) end local function getHungry(entities) @@ -118,13 +134,25 @@ local function getHungry(entities) end end -local function randomEntity(entities) - local r = math.random(1, Map.size(entities)) - local i = 1 +local function getCount(entities, name) + local c = 0 for _, v in pairs(entities) do - i = i + 1 - if i > r then - return v + if v.name == name then + c = c + 1 + end + end + print(name .. ' ' .. c) + return c +end + +local function getKillable(entities) + print('map: ' .. Map.size(fed)) + if Map.size(fed) > 1000 then + fed = { } + end + for name in pairs(animals) do + if getCount(entities, name) > config.maxAdults then + return Array.find(entities, 'name', name) end end end @@ -133,9 +161,10 @@ while true do resupply() local entities = getEntities() + local killable = getKillable(entities) - if Map.size(entities) > config.maxAdults then - kill(randomEntity(entities)) + if killable then + kill(killable) else local entity = getHungry(entities) if entity then diff --git a/swshop/shopConfig.lua b/swshop/shopConfig.lua index 761b587..857d0c1 100644 --- a/swshop/shopConfig.lua +++ b/swshop/shopConfig.lua @@ -110,7 +110,7 @@ local passwordPage = UI.WizardPage { preview = UI.TextEntry { formIndex = 4, formLabel = 'Using address', formKey = 'address', - backgroundColor = UI.colors.primary, + backgroundColor = 'primary', textColor = colors.yellow, inactive = true, },