Ui enhancements 2.0 (#29)

* canvas overhaul

* editor 2.0

* more tweaks

* more editor work

* completions + refactor

* cleanup + editor additions

* cleanup + undo overhaul

* editor recent/peripherals/redo + cleanup

* editor path issues

* cleanup

* changes for deprecated ui methods - recolor milo - make turtle scripts run again - mob rancher improvements

* can now use named colors
This commit was merged in pull request #29.
This commit is contained in:
kepler155c
2020-04-21 22:40:47 -06:00
committed by GitHub
parent 47e0a90116
commit 4576969739
65 changed files with 1842 additions and 1310 deletions

142
neural/Equipment.lua Normal file
View File

@@ -0,0 +1,142 @@
local Event = require('opus.event')
local itemDB = require('core.itemDB')
local neural = require('neural.interface')
local UI = require('opus.ui')
local Util = require('opus.util')
local device = _G.device
neural.assertModules({
'plethora:sensor',
'plethora:kinetic',
'plethora:introspection',
})
UI:configure('Equipment', ...)
local equipment = device.neuralInterface.getEquipment()
local slots = {
'primary',
'offhand',
'boots',
'leggings',
'chest',
'helmet',
}
local page = UI.Page {
menuBar = UI.MenuBar {
buttons = {
{ text = 'Drop', event = 'drop' },
{ text = 'Suck', event = 'suck' },
},
},
grid = UI.Grid {
y = 2,
columns = {
{ heading = 'Slot', key = 'index', width = 7 },
{ heading = 'Name', key = 'displayName' },
{ heading = 'Count', key = 'count', width = 5, align = 'right' },
},
sortColumn = 'index',
accelerators = {
grid_select = 'show_detail',
},
getDisplayValues = function(_, row)
row = Util.shallowCopy(row)
if row.name then
local item = itemDB:get(
table.concat({ row.name, row.damage, row.nbtHash }, ':'),
function()
return equipment.getItemMeta(row.index)
end)
row.displayName = item.displayName
else
row.displayName = 'empty'
end
row.index = slots[row.index]
return row
end,
},
accelerators = {
[ 'control-q' ] = 'quit',
},
detail = UI.SlideOut {
menuBar = UI.MenuBar {
buttons = {
{ text = 'Back', event = 'slide_hide' },
},
},
grid = UI.ScrollingGrid {
y = 2,
columns = {
{ heading = 'Name', key = 'name' },
{ heading = 'Value', key = 'value' },
},
sortColumn = 'name',
accelerators = {
grid_select = 'inspect',
},
},
show = function(self, slot)
local detail = equipment.getItemMeta(slot.index)
local t = { }
for k,v in pairs(detail) do
table.insert(t, {
name = k,
value = v,
})
end
self.grid:setValues(t)
self.grid:setIndex(1)
UI.SlideOut.show(self)
end,
},
enable = function(self)
self:refresh()
UI.Page.enable(self)
end,
refresh = function(self)
local t = { }
local list = equipment.list()
for i = 1, equipment.size() do
local v = list[i] or { }
v.index = i
table.insert(t, v)
end
self.grid:setValues(t)
self.grid:draw()
end,
eventHandler = function(self, event)
if event.type == 'quit' then
UI:quit()
elseif event.type == 'show_detail' then
if event.selected.name then
self.detail:show(event.selected)
end
elseif event.type == 'drop' then
local selected = self.grid:getSelected()
equipment.drop(selected.index)
self:refresh()
elseif event.type == 'suck' then
local selected = self.grid:getSelected()
equipment.suck(selected.index)
self:refresh()
end
UI.Page.eventHandler(self, event)
end,
}
Event.onInterval(1, function()
page:refresh()
page:sync()
end)
UI:setPage(page)
UI:start()
itemDB:flush()

View File

@@ -182,7 +182,7 @@ end
function page:eventHandler(event)
if event.type == 'quit' then
Event.exitPullEvents()
UI:quit()
elseif event.type == 'scan' then
self:scan()
@@ -211,7 +211,7 @@ Event.onTimeout(0, function()
page:sync()
end)
UI:pullEvents()
UI:start()
if canvas then
canvas:clear()

View File

@@ -253,7 +253,7 @@ end
function page:eventHandler(event)
if event.type == 'quit' then
Event.exitPullEvents()
UI:quit()
elseif event.type == 'tab_activate' then
config.activeTab = event.activated.tabTitle
@@ -268,7 +268,7 @@ if config.activeTab then
end
UI:setPage(page)
UI:pullEvents()
UI:start()
if canvas then
canvas:clear()

View File

@@ -29,4 +29,10 @@
run = "ores.lua",
requires = "neuralInterface",
},
[ "7f2465ac7cefab2766e6ee0714647089df9364b0ff09858c84b21b8a436a845d" ] = {
title = "Equipment",
category = "Neural",
run = "Equipment",
requires = "neuralInterface",
}
}

View File

@@ -1,6 +1,15 @@
--[[
Breed either cows or sheep.
Must be run on a mob with the same height.
Changed to use a 2-high mob (smaller mobs may work ?)
Updated due to entity.look working correctly now.
The mob looks head-on to the lever. Make sure the
lever is accessible by the mob.
Laser is now optional - if no laser, the mobs will be
punched (or provide a stick). Best mob may be a
skeleton (unlimited ammo).
Feeding hand has been changed to off-hand.
]]
local Array = require('opus.array')
@@ -21,80 +30,100 @@ local WALK_SPEED = 1.5
neural.assertModules({
'plethora:sensor',
'plethora:scanner',
'plethora:laser',
--'plethora:laser',
'plethora:kinetic',
'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()
local slot = neural.getEquipment().list()[1]
local slot = neural.getEquipment().list()[2]
if slot and slot.count > 32 then
return
end
print('resupplying')
for _ = 1, 2 do
local dispenser = Map.find(neural.scan(), 'name', 'minecraft:dispenser')
local dispenser = Map.find(neural.scan(), 'name', 'minecraft:lever')
if not dispenser then
print('dispenser not found')
break
end
if math.abs(dispenser.x) <= 1 and math.abs(dispenser.z) <= 1 then
neural.lookAt(dispenser)
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(1, 64)
neural.getEquipment().suck(2, 64)
end
break
else
neural.walkTo({ x = dispenser.x, y = 0, z = dispenser.z }, WALK_SPEED)
neural.walkTo({ x = dispenser.x, y = 0, z = dispenser.z }, WALK_SPEED, .5)
end
end
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)
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')
neural.walkTo(entity, WALK_SPEED, 2.5)
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
neural.lookAt(entity)
neural.fireAt({ x = entity.x, y = 0, z = entity.z })
if neural.fire or neural.shoot then
neural.shootAt(entity)
else
neural.swing()
end
Sound.play('entity.firework.launch')
os.sleep(.2)
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)
@@ -105,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
@@ -120,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