can now use named colors

This commit is contained in:
kepler155c@gmail.com
2020-04-21 22:32:53 -06:00
parent 949c485539
commit d17162b49d
14 changed files with 190 additions and 253 deletions

View File

@@ -3,7 +3,6 @@ local Event = require('opus.event')
local UI = require('opus.ui') local UI = require('opus.ui')
local Util = require('opus.util') local Util = require('opus.util')
local colors = _G.colors
local peripheral = _G.peripheral local peripheral = _G.peripheral
--[[ -- PeripheralsPage -- ]] -- --[[ -- PeripheralsPage -- ]] --
@@ -16,6 +15,20 @@ local peripheralsPage = UI.Page {
}, },
sortColumn = 'type', sortColumn = 'type',
autospace = true, 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 { statusBar = UI.StatusBar {
values = 'Select peripheral', values = 'Select peripheral',
@@ -23,47 +36,30 @@ local peripheralsPage = UI.Page {
accelerators = { accelerators = {
[ 'control-q' ] = 'quit', [ '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 -- ]] -- --[[ -- MethodsPage -- ]] --
local methodsPage = UI.Page { local methodsPage = UI.Page {
backgroundColor = colors.black,
doc = UI.TextArea { doc = UI.TextArea {
backgroundColor = colors.black, backgroundColor = 'black',
x = 2, y = 2, ex = -1, ey = -7, ey = -7,
marginLeft = 1, marginTop = 1,
}, },
grid = UI.ScrollingGrid { grid = UI.ScrollingGrid {
y = -6, ey = -2, y = -6, ey = -2,

View File

@@ -137,6 +137,7 @@ function page:scan()
self.copyButton.inactive = not valid self.copyButton.inactive = not valid
self:draw() self:draw()
self.progress:clear()
self.progress:centeredWrite(1, 'Analyzing Disks..') self.progress:centeredWrite(1, 'Analyzing Disks..')
self.progress:sync() self.progress:sync()
@@ -166,6 +167,7 @@ function page:copy()
throttle() throttle()
end end
self.progress:clear()
self.progress:centeredWrite(1, 'Computing..') self.progress:centeredWrite(1, 'Computing..')
self.progress:sync() self.progress:sync()
@@ -210,6 +212,8 @@ function page:copy()
self.progress:clear() self.progress:clear()
rawCopy(sdrive.getMountPath(), tdrive.getMountPath()) rawCopy(sdrive.getMountPath(), tdrive.getMountPath())
cleanup() cleanup()
self.progress:clear()
self.progress:centeredWrite(1, 'Copy Complete', colors.lime, colors.black) self.progress:centeredWrite(1, 'Copy Complete', colors.lime, colors.black)
self.progress:sync() self.progress:sync()

View File

@@ -131,7 +131,7 @@ page = UI.Page {
columns = { columns = {
{ heading = '', key = 'index', width = 2 }, { heading = '', key = 'index', width = 2 },
{ heading = '', key = 'count', width = 2 }, { heading = '', key = 'count', width = 2 },
{ heading = 'Inventory', key = 'key', width = UI.term.width - 7 }, { heading = 'Inventory', key = 'key' },
}, },
disableHeader = true, disableHeader = true,
sortColumn = 'index', sortColumn = 'index',

View File

@@ -4,7 +4,6 @@ local fuzzy = require('opus.fuzzy')
local UI = require('opus.ui') local UI = require('opus.ui')
local Util = require('opus.util') local Util = require('opus.util')
local colors = _G.colors
local device = _G.device local device = _G.device
local fs = _G.fs local fs = _G.fs
local multishell = _ENV.multishell local multishell = _ENV.multishell
@@ -39,19 +38,25 @@ local undo = { chain = { }, redo = { } }
h = h - 1 h = h - 1
local bgColor = 'gray'
local color = { local color = {
textColor = '0', text = '0',
keywordColor = '4', keyword = '2',
commentColor = 'd', comment = 'd',
stringColor = 'e', string = '1',
mark = '8',
bg = '7',
} }
if not term.isColor() then if not term.isColor() then
bgColor = 'black'
color = { color = {
textColor = '0', text = '0',
keywordColor = '8', keyword = '8',
commentColor = '8', comment = '8',
stringColor = '8', string = '8',
mark = '7',
bg = 'f',
} }
end end
@@ -161,7 +166,7 @@ local page = UI.Page {
} }, } },
}, },
status = UI.Text { status = UI.Text {
textColor = colors.gray, textColor = 'gray',
x = -9, width = 9, x = -9, width = 9,
align = 'right', align = 'right',
}, },
@@ -172,8 +177,6 @@ local page = UI.Page {
lineNo = UI.TextEntry { lineNo = UI.TextEntry {
x = 7, width = 7, x = 7, width = 7,
limit = 5, limit = 5,
backgroundFocusColor = colors.gray,
backgroundColor = colors.gray,
transform = 'number', transform = 'number',
accelerators = { accelerators = {
[ 'enter' ] = 'accept', [ 'enter' ] = 'accept',
@@ -200,9 +203,6 @@ local page = UI.Page {
search = UI.TextEntry { search = UI.TextEntry {
x = 7, ex = -3, x = 7, ex = -3,
limit = 512, limit = 512,
markBackgroundColor = colors.lightGray,
backgroundFocusColor = colors.gray,
backgroundColor = colors.gray,
accelerators = { accelerators = {
[ 'enter' ] = 'accept', [ 'enter' ] = 'accept',
}, },
@@ -233,9 +233,6 @@ local page = UI.Page {
filename = UI.TextEntry { filename = UI.TextEntry {
x = 7, ex = -3, x = 7, ex = -3,
limit = 512, limit = 512,
markBackgroundColor = colors.lightGray,
backgroundFocusColor = colors.gray,
backgroundColor = colors.gray,
accelerators = { accelerators = {
[ 'enter' ] = 'accept', [ 'enter' ] = 'accept',
}, },
@@ -263,7 +260,7 @@ local page = UI.Page {
cancel = UI.Button { cancel = UI.Button {
x = 16, x = 16,
text = 'Cancel', text = 'Cancel',
backgroundColor = UI.colors.primary, backgroundColor = 'primary',
event = 'question_cancel', event = 'question_cancel',
}, },
show = function(self, action) show = function(self, action)
@@ -355,7 +352,7 @@ local page = UI.Page {
disableHeader = true, disableHeader = true,
columns = { columns = {
{ key = 'name' }, { key = 'name' },
{ key = 'dir', textColor = colors.lightGray }, { key = 'dir', textColor = 'lightGray' },
}, },
accelerators = { accelerators = {
grid_select = 'accept', grid_select = 'accept',
@@ -453,9 +450,9 @@ local page = UI.Page {
cancel = UI.Button { cancel = UI.Button {
y = -1, x = -9, y = -1, x = -9,
text = 'Cancel', text = 'Cancel',
backgroundColor = colors.black, backgroundColor = 'black',
backgroundFocusColor = colors.black, backgroundFocusColor = 'black',
textColor = colors.lightGray, textColor = 'lightGray',
event = 'slide_hide', event = 'slide_hide',
}, },
show = function(self, values) show = function(self, values)
@@ -540,9 +537,9 @@ local page = UI.Page {
cancel = UI.Button { cancel = UI.Button {
y = -1, x = -9, y = -1, x = -9,
text = 'Cancel', text = 'Cancel',
backgroundColor = colors.black, backgroundColor = 'black',
backgroundFocusColor = colors.black, backgroundFocusColor = 'black',
textColor = colors.lightGray, textColor = 'lightGray',
event = 'slide_hide', event = 'slide_hide',
}, },
eventHandler = function(self, event) eventHandler = function(self, event)
@@ -562,7 +559,7 @@ local page = UI.Page {
}, },
editor = UI.Window { editor = UI.Window {
y = 2, y = 2,
backgroundColor = colors.black, backgroundColor = bgColor,
transitionHint = 'slideRight', transitionHint = 'slideRight',
cursorBlink = true, cursorBlink = true,
focus = function(self) focus = function(self)
@@ -687,15 +684,15 @@ local function writeHighlighted(sLine, ny, dy)
while #sLine > 0 do while #sLine > 0 do
sLine = sLine =
-- tryWrite(sLine, "^[%\26]", '7' ) or -- tryWrite(sLine, "^[%\26]", '7' ) or
tryWrite(sLine, "^%-%-%[%[.-%]%]", color.commentColor ) or tryWrite(sLine, "^%-%-%[%[.-%]%]", color.comment ) or
tryWrite(sLine, "^%-%-.*", color.commentColor ) or tryWrite(sLine, "^%-%-.*", color.comment ) or
tryWrite(sLine, "^\".-[^\\]\"", color.stringColor ) or tryWrite(sLine, "^\".-[^\\]\"", color.string ) or
tryWrite(sLine, "^\'.-[^\\]\'", color.stringColor ) or tryWrite(sLine, "^\'.-[^\\]\'", color.string ) or
tryWrite(sLine, "^%[%[.-%]%]", color.stringColor ) or tryWrite(sLine, "^%[%[.-%]%]", color.string ) or
tryWrite(sLine, "^[%w_]+", function(match) 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 end) or
tryWrite(sLine, "^[^%w_]", color.textColor) tryWrite(sLine, "^[^%w_]", color.text)
end end
buffer.fg = _concat(buffer.fg) .. '7' 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 if mark.active and ny >= mark.y and ny <= mark.ey then
local sx = ny == mark.y and mark.x or 1 local sx = ny == mark.y and mark.x or 1
local ex = ny == mark.ey and mark.ex or #buffer.text local ex = ny == mark.ey and mark.ex or #buffer.text
buffer.bg = _rep('f', sx - 1) .. buffer.bg = _rep(color.bg, sx - 1) ..
_rep('7', ex - sx) .. _rep(color.mark, ex - sx) ..
_rep('f', #buffer.text - ex + 1) _rep(color.bg, #buffer.text - ex + 1)
else else
buffer.bg = _rep('f', #buffer.text) buffer.bg = _rep(color.bg, #buffer.text)
end end
page.editor:blit(1 - scrollX, dy, buffer.text, buffer.bg, buffer.fg) page.editor:blit(1 - scrollX, dy, buffer.text, buffer.bg, buffer.fg)
@@ -860,7 +857,6 @@ actions = {
end end
actions.go_to(nx, ny) actions.go_to(nx, ny)
actions.mark_to(nx + #pattern, ny) actions.mark_to(nx + #pattern, ny)
actions.go_to(nx, ny)
return return
end end
sx = 1 sx = 1

View File

@@ -19,10 +19,14 @@ local Util = require('opus.util')
local multishell = _ENV.multishell local multishell = _ENV.multishell
local os = _G.os 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 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 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 calls = { }
local curCalls = { delay = 0 } local curCalls = { delay = 0 }
@@ -32,38 +36,44 @@ local callCount = 0
local function showSyntax() local function showSyntax()
print('Gif Recorder by Bomb Bloke\n') print('Gif Recorder by Bomb Bloke\n')
print('Syntax: recGif [-i] [-s] [-ld:<delay>] filename') print('Syntax: recGif [-i] [-s] [-ld:<delay>] filename')
print(' -i : show input') print(' --showInput : show input')
print(' -s : skip last') print(' --skipLast : skip last')
print(' -ld : last delay') print(' --lastDelay : last delay')
print(' --noResize : dont resize')
end end
for i = #arg, 1, -1 do if options.showInput then
local curArg = arg[i]:lower() showInput, ySize = true, ySize + 1
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
end end
print('Gif Recorder by Bomb Bloke\n') if options.skipLast then
print('Press control-p to stop recording') 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 if not filename then
print('Enter file name:') print('Enter file name:')
filename = read() filename = read()
@@ -131,7 +141,7 @@ end
-- Build a terminal that records stuff: -- Build a terminal that records stuff:
recTerm = multishell.term local recTerm = multishell.term
for key, func in pairs(oldTerm) do for key, func in pairs(oldTerm) do
if type(func) == 'function' then if type(func) == 'function' then
@@ -149,21 +159,16 @@ for key, func in pairs(oldTerm) do
end end
local tabId = multishell.getCurrent() local tabId = multishell.getCurrent()
multishell.hideTab(tabId)
if not options.noResize then
os.queueEvent('term_resize')
end
_G.device.keyboard.addHotkey('control-p', function() _G.device.keyboard.addHotkey('control-p', function()
os.queueEvent('recorder_stop') os.queueEvent('recorder_stop')
end) 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 local curTime = os.clock() - 1
while true do while true do
@@ -202,8 +207,12 @@ if skipLast and #calls > 1 then calls[#calls] = nil end
calls[#calls].delay = lastDelay calls[#calls].delay = lastDelay
if options.rawOutput then
Util.writeTable('tmp/raw.txt', calls)
return
end
print(string.format("Encoding %d frames...", #calls)) 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): -- Perform a quick re-parse of the recorded data (adding frames for when the cursor blinks):

View File

@@ -63,8 +63,8 @@ local page = UI.Page {
x = 1, ex = -13, x = 1, ex = -13,
limit = 50, limit = 50,
shadowText = 'filter', shadowText = 'filter',
backgroundColor = UI.colors.primary, backgroundColor = 'primary',
backgroundFocusColor = UI.colors.primary, backgroundFocusColor = 'primary',
accelerators = { accelerators = {
[ 'enter' ] = 'eject', [ 'enter' ] = 'eject',
[ 'up' ] = 'grid_up', [ 'up' ] = 'grid_up',

View File

@@ -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

View File

@@ -54,8 +54,8 @@ local page = UI.Page {
limit = 50, limit = 50,
shadowText = 'filter', shadowText = 'filter',
shadowTextColor = colors.gray, shadowTextColor = colors.gray,
backgroundColor = UI.colors.primary, backgroundColor = 'primary',
backgroundFocusColor = UI.colors.primary, backgroundFocusColor = 'primary',
accelerators = { accelerators = {
[ 'enter' ] = 'eject', [ 'enter' ] = 'eject',
[ 'up' ] = 'grid_up', [ 'up' ] = 'grid_up',
@@ -66,7 +66,7 @@ local page = UI.Page {
storageStatus = UI.Text { storageStatus = UI.Text {
x = -17, ex = -10, x = -17, ex = -10,
textColor = colors.lime, textColor = colors.lime,
backgroundColor = UI.colors.primary, backgroundColor = 'primary',
value = '', value = '',
}, },
amount = UI.TextEntry { amount = UI.TextEntry {

View File

@@ -21,8 +21,8 @@ local networkPage = UI.Page {
y = -2, x = 1, ex = -9, y = -2, x = 1, ex = -9,
limit = 50, limit = 50,
shadowText = 'filter', shadowText = 'filter',
backgroundColor = UI.colors.primary, backgroundColor = 'primary',
backgroundFocusColor = UI.colors.primary, backgroundFocusColor = 'primary',
}, },
grid = UI.ScrollingGrid { grid = UI.ScrollingGrid {
y = 2, ey = -3, y = 2, ey = -3,
@@ -234,7 +234,7 @@ The settings will take effect immediately!]],
}, },
}, },
statusBar = UI.StatusBar { statusBar = UI.StatusBar {
backgroundColor = UI.colors.primary, backgroundColor = 'primary',
}, },
notification = UI.Notification { }, notification = UI.Notification { },
filter = UI.SlideOut { filter = UI.SlideOut {
@@ -289,7 +289,7 @@ The settings will take effect immediately!]],
}, },
}, },
statusBar = UI.StatusBar { statusBar = UI.StatusBar {
backgroundColor = UI.colors.primary, backgroundColor = 'primary',
}, },
}, },
} }

View File

@@ -41,7 +41,6 @@ function page:eventHandler(event)
elseif event.type == 'focus_change' then elseif event.type == 'focus_change' then
self.statusBar:setStatus(event.focused.help) self.statusBar:setStatus(event.focused.help)
self.statusBar:draw()
elseif event.type == 'success_message' then elseif event.type == 'success_message' then
self.notification:success(event.message) self.notification:success(event.message)

View File

@@ -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 })

View File

@@ -50,7 +50,7 @@ local setup = UI.SlideOut {
[[also have an introspection module.]], [[also have an introspection module.]],
}, },
statusBar = UI.StatusBar { statusBar = UI.StatusBar {
backgroundColor = UI.colors.primary, backgroundColor = 'primary',
}, },
} }

View File

@@ -35,6 +35,12 @@ neural.assertModules({
'plethora:introspection', 'plethora:introspection',
}) })
local caninimals = config.animals or { [ config.animal ] = true }
local animals = { }
for k in pairs(caninimals) do
animals[k] = { }
end
local fed = { } local fed = { }
local function resupply() local function resupply()
@@ -49,10 +55,12 @@ local function resupply()
print('dispenser not found') print('dispenser not found')
break break
end 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 }) neural.lookAt({ x = dispenser.x, y = dispenser.y, z = dispenser.z })
for _ = 1, 8 do for _ = 1, 8 do
neural.use(0, 'off') if not neural.use(0, 'off') then
break
end
os.sleep(.2) os.sleep(.2)
neural.getEquipment().suck(2, 64) neural.getEquipment().suck(2, 64)
end end
@@ -64,21 +72,22 @@ local function resupply()
end end
local function breed(entity) local function breed(entity)
print('breeding') print('breeding ' .. entity.name)
entity.lastFed = os.clock()
fed[entity.id] = entity
neural.walkTo(entity, WALK_SPEED, 1) neural.walkTo(entity, WALK_SPEED, 1)
entity = neural.getMetaByID(entity.id) entity = neural.getMetaByID(entity.id)
if entity then if entity then
neural.lookAt(entity) 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) os.sleep(.1)
end end
end end
local function kill(entity) 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) neural.walkTo(entity, WALK_SPEED, (neural.fire or neural.shoot) and 2.5 or .5)
entity = neural.getMetaByID(entity.id) entity = neural.getMetaByID(entity.id)
if entity then if entity then
@@ -93,21 +102,28 @@ local function kill(entity)
end end
end end
local function getEntities() local function shuffle(tbl)
local sheep = Array.filter(neural.sense(), function(entity) for i = #tbl, 2, -1 do
if entity.name == 'Sheep' and entity.y > -.5 then local j = math.random(i)
return true tbl[i], tbl[j] = tbl[j], tbl[i]
end
end)
if #sheep > config.maxAdults then
return sheep
end end
return tbl
end
return Map.filter(neural.sense(), function(entity) local function getEntities()
if entity.name == config.animal and entity.y > -.5 then return shuffle(Array.filter(neural.sense(), function(entity)
return true 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))
end end
local function getHungry(entities) local function getHungry(entities)
@@ -118,13 +134,25 @@ local function getHungry(entities)
end end
end end
local function randomEntity(entities) local function getCount(entities, name)
local r = math.random(1, Map.size(entities)) local c = 0
local i = 1
for _, v in pairs(entities) do for _, v in pairs(entities) do
i = i + 1 if v.name == name then
if i > r then c = c + 1
return v 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 end
end end
@@ -133,9 +161,10 @@ while true do
resupply() resupply()
local entities = getEntities() local entities = getEntities()
local killable = getKillable(entities)
if Map.size(entities) > config.maxAdults then if killable then
kill(randomEntity(entities)) kill(killable)
else else
local entity = getHungry(entities) local entity = getHungry(entities)
if entity then if entity then

View File

@@ -110,7 +110,7 @@ local passwordPage = UI.WizardPage {
preview = UI.TextEntry { preview = UI.TextEntry {
formIndex = 4, formIndex = 4,
formLabel = 'Using address', formKey = 'address', formLabel = 'Using address', formKey = 'address',
backgroundColor = UI.colors.primary, backgroundColor = 'primary',
textColor = colors.yellow, textColor = colors.yellow,
inactive = true, inactive = true,
}, },