neural cleanup
This commit is contained in:
@@ -4,27 +4,18 @@ local Project = require('neural.project')
|
|||||||
local UI = require('ui')
|
local UI = require('ui')
|
||||||
local Util = require('util')
|
local Util = require('util')
|
||||||
|
|
||||||
local peripheral = _G.peripheral
|
local device = _G.device
|
||||||
local turtle = _G.turtle
|
|
||||||
|
|
||||||
local function equip(side, rawName)
|
local glasses = device['plethora:glasses']
|
||||||
return turtle and turtle.equip(side, rawName) and peripheral.wrap(side)
|
local intro = device['plethora:introspection']
|
||||||
end
|
local sensor = device['plethora:sensor'] or
|
||||||
|
|
||||||
local target = nil
|
|
||||||
local ni = peripheral.find('neuralInterface')
|
|
||||||
local sensor = ni or
|
|
||||||
peripheral.find('plethora:sensor') or
|
|
||||||
peripheral.find('manipulator') or
|
|
||||||
equip('left', 'plethora:module:3')
|
|
||||||
|
|
||||||
if not sensor or not sensor.sense then
|
|
||||||
error('Plethora sensor must be equipped')
|
error('Plethora sensor must be equipped')
|
||||||
end
|
|
||||||
|
|
||||||
UI:configure('Entities', ...)
|
UI:configure('Sensor', ...)
|
||||||
|
|
||||||
local config = Config.load('Entities', {
|
local target
|
||||||
|
|
||||||
|
local config = Config.load('Sensor', {
|
||||||
ignore = { }
|
ignore = { }
|
||||||
})
|
})
|
||||||
if not config.ignore then
|
if not config.ignore then
|
||||||
@@ -127,7 +118,7 @@ function page:eventHandler(event)
|
|||||||
|
|
||||||
elseif event.type == 'totals' then
|
elseif event.type == 'totals' then
|
||||||
config.totals = not config.totals
|
config.totals = not config.totals
|
||||||
Config.update('Entities', config)
|
Config.update('Sensor', config)
|
||||||
|
|
||||||
elseif event.type == 'detail' or event.type == 'grid_select' then
|
elseif event.type == 'detail' or event.type == 'grid_select' then
|
||||||
local selected = self.grid:getSelected()
|
local selected = self.grid:getSelected()
|
||||||
@@ -144,20 +135,22 @@ function page:eventHandler(event)
|
|||||||
if selected then
|
if selected then
|
||||||
config.ignore[selected.name] = true
|
config.ignore[selected.name] = true
|
||||||
end
|
end
|
||||||
Config.update('Entities', config)
|
Config.update('Sensor', config)
|
||||||
|
|
||||||
elseif event.type == 'project' or event.type == 'project-target' then
|
elseif event.type == 'project' or event.type == 'project-target' then
|
||||||
if event.type == 'project' then
|
if event.type == 'project' then
|
||||||
target = nil
|
target = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
config.projecting = not config.projecting
|
if glasses then
|
||||||
if config.projecting then
|
config.projecting = not config.projecting
|
||||||
Project:init(ni.canvas())
|
if config.projecting then
|
||||||
else
|
Project:init(glasses.canvas())
|
||||||
Project.canvas:clear()
|
else
|
||||||
|
Project.canvas:clear()
|
||||||
|
end
|
||||||
end
|
end
|
||||||
Config.update('Entities', config)
|
Config.update('Sensor', config)
|
||||||
end
|
end
|
||||||
|
|
||||||
UI.Page.eventHandler(self, event)
|
UI.Page.eventHandler(self, event)
|
||||||
@@ -167,8 +160,8 @@ Event.onInterval(.5, function()
|
|||||||
local entities = sensor.sense()
|
local entities = sensor.sense()
|
||||||
Util.filterInplace(entities, function(e) return not config.ignore[e.name] end)
|
Util.filterInplace(entities, function(e) return not config.ignore[e.name] end)
|
||||||
|
|
||||||
if config.projecting then
|
if config.projecting and glasses and intro then
|
||||||
local meta = ni.getMetaOwner()
|
local meta = intro.getMetaOwner()
|
||||||
Project.canvas:clear()
|
Project.canvas:clear()
|
||||||
local t = entities
|
local t = entities
|
||||||
if target then
|
if target then
|
||||||
@@ -194,13 +187,13 @@ Event.onInterval(.5, function()
|
|||||||
page:sync()
|
page:sync()
|
||||||
end)
|
end)
|
||||||
|
|
||||||
if config.projecting then
|
if config.projecting and glasses then
|
||||||
Project:init(ni.canvas())
|
Project:init(glasses.canvas())
|
||||||
end
|
end
|
||||||
|
|
||||||
UI:setPage(page)
|
UI:setPage(page)
|
||||||
UI:pullEvents()
|
UI:pullEvents()
|
||||||
|
|
||||||
if config.projecting then
|
if config.projecting and glasses then
|
||||||
Project.canvas:clear()
|
Project.canvas:clear()
|
||||||
end
|
end
|
||||||
|
|||||||
16
neural/apis/kinetic.lua
Normal file
16
neural/apis/kinetic.lua
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
local Angle = require('neural.angle')
|
||||||
|
local Util = require('util')
|
||||||
|
|
||||||
|
local device = _G.device
|
||||||
|
|
||||||
|
local module = device['plethora:kinetic'] or error('Missing kinetic')
|
||||||
|
|
||||||
|
local Kinetic = Util.shallowCopy(module)
|
||||||
|
|
||||||
|
function Kinetic.lookAt(pt)
|
||||||
|
--local x = pt.x < 0 and pt.x + .5 or pt.x - .5
|
||||||
|
local yaw, pitch = Angle.towards(pt.x, pt.y, pt.z)
|
||||||
|
return Kinetic.look(yaw, pitch)
|
||||||
|
end
|
||||||
|
|
||||||
|
return Kinetic
|
||||||
@@ -1,17 +1,19 @@
|
|||||||
local ni = require('neural.interface')
|
local Array = require('array')
|
||||||
local Point = require('point')
|
local kinetic = require('plethora.kinetic')
|
||||||
local Util = require('util')
|
local Point = require('point')
|
||||||
|
|
||||||
local os = _G.os
|
local device = _G.device
|
||||||
|
local os = _G.os
|
||||||
|
|
||||||
local pos = { x = 0, y = 0, z = 0 }
|
local pos = { x = 0, y = 0, z = 0 }
|
||||||
local meta = ni.getMetaOwner()
|
local sensor = device['plethora:sensor'] or error('Missing sensor')
|
||||||
|
local intro = device['plethora:introspection'] or error('Missing introspection module')
|
||||||
|
|
||||||
|
local ID = intro.getMetaOwner()
|
||||||
|
|
||||||
local function findTargets()
|
local function findTargets()
|
||||||
local l = ni.sense()
|
local l = Array.filter(sensor.sense(), function(a)
|
||||||
|
return math.abs(a.motionY) > 0 and ID ~= a.id
|
||||||
Util.filterInplace(l, function(a)
|
|
||||||
return math.abs(a.motionY) > 0 and meta.id ~= a.id
|
|
||||||
end)
|
end)
|
||||||
table.sort(l, function(e1, e2)
|
table.sort(l, function(e1, e2)
|
||||||
return Point.distance(e1, pos) < Point.distance(e2, pos)
|
return Point.distance(e1, pos) < Point.distance(e2, pos)
|
||||||
@@ -26,24 +28,19 @@ local count = 0
|
|||||||
while true do
|
while true do
|
||||||
local target = findTargets()
|
local target = findTargets()
|
||||||
if target and (not last or Point.distance(last, target) > .2) then
|
if target and (not last or Point.distance(last, target) > .2) then
|
||||||
-- last = target
|
last = target
|
||||||
if last then print(Point.distance(last, target)) end
|
kinetic.lookAt(target)
|
||||||
last = target
|
count = 0
|
||||||
--print(target.x, target.y, target.z, count)
|
os.sleep(0)
|
||||||
ni.lookAt(target)
|
|
||||||
count = 0
|
|
||||||
os.sleep(0)
|
|
||||||
-- elseif count < 10 then
|
|
||||||
-- count = count + 1
|
|
||||||
-- os.sleep(.1)
|
|
||||||
-- end
|
|
||||||
else
|
else
|
||||||
count = count + 1
|
count = count + 1
|
||||||
if count > 50 or not target then
|
if count > 50 or not target then
|
||||||
ni.lookAt({ x = math.random(-10, 10),
|
kinetic.lookAt({
|
||||||
y = math.random(-10, 10),
|
x = math.random(-10, 10),
|
||||||
z = math.random(-10, 10) })
|
y = math.random(-10, 10),
|
||||||
os.sleep(3)
|
z = math.random(-10, 10)
|
||||||
|
})
|
||||||
|
os.sleep(3)
|
||||||
else
|
else
|
||||||
os.sleep(.1)
|
os.sleep(.1)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,12 +1,10 @@
|
|||||||
_G.requireInjector(_ENV)
|
|
||||||
|
|
||||||
local ni = require('neural.interface')
|
local ni = require('neural.interface')
|
||||||
local Util = require('util')
|
local Util = require('util')
|
||||||
|
|
||||||
local os = _G.os
|
local os = _G.os
|
||||||
|
|
||||||
while true do
|
while true do
|
||||||
local target = Util.find(ni.sense(), 'name', 'joebodo')
|
local target = Util.find(ni.sense(), 'name', '///////')
|
||||||
if target then
|
if target then
|
||||||
if math.abs(target.x) < 2 and
|
if math.abs(target.x) < 2 and
|
||||||
math.abs(target.z) < 2 then
|
math.abs(target.z) < 2 then
|
||||||
|
|||||||
@@ -1,31 +0,0 @@
|
|||||||
_G.requireInjector(_ENV)
|
|
||||||
|
|
||||||
local ni = require('neural.interface')
|
|
||||||
local uid = ni.getID and ni.getID() or error('Introspection module is required')
|
|
||||||
|
|
||||||
local os = _G.os
|
|
||||||
|
|
||||||
local args = { ... }
|
|
||||||
|
|
||||||
local function findEntity(name)
|
|
||||||
for _,v in pairs(ni.sense()) do
|
|
||||||
if v.id ~= uid and v.name == name then
|
|
||||||
return v
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
print('Targets:')
|
|
||||||
for _,v in pairs(ni.sense()) do
|
|
||||||
print(v.name)
|
|
||||||
end
|
|
||||||
|
|
||||||
local target = args[1] or error('specify target name')
|
|
||||||
|
|
||||||
repeat
|
|
||||||
local entity = findEntity(target)
|
|
||||||
if entity then
|
|
||||||
ni.shootAt(entity, 1)
|
|
||||||
end
|
|
||||||
os.sleep(.5)
|
|
||||||
until not entity
|
|
||||||
Reference in New Issue
Block a user