compression package - debugger fixes

This commit is contained in:
kepler155c@gmail.com
2020-06-01 16:54:28 -06:00
parent fb5e69f703
commit b289594c7f
10 changed files with 3676 additions and 443 deletions

View File

@@ -1,15 +0,0 @@
local w, h = term.getSize()
term.clear()
term.setCursorPos(1, 1)
local t = { }
for i = 1, 8 do
table.insert(t, '---')
end
for i = 1, 255 do
table.insert(t, string.format('%d %c', i, i))
end
textutils.pagedTabulate(t)

View File

@@ -1,196 +0,0 @@
local class = require('opus.class')
local UI = require('opus.ui')
local Event = require('opus.event')
local Peripheral = require('opus.peripheral')
--[[-- Glasses device --]]--
local Glasses = class()
function Glasses:init(args)
local defaults = {
backgroundColor = colors.black,
textColor = colors.white,
textScale = .5,
backgroundOpacity = .5,
multiplier = 2.6665,
-- multiplier = 2.333,
}
defaults.width, defaults.height = term.getSize()
UI:setProperties(defaults, args)
UI:setProperties(self, defaults)
self.bridge = Peripheral.get({
type = 'openperipheral_bridge',
method = 'addBox',
})
self.bridge.clear()
self.setBackgroundColor = function(...) end
self.setTextColor = function(...) end
self.t = { }
for i = 1, self.height do
self.t[i] = {
text = string.rep(' ', self.width+1),
--text = self.bridge.addText(0, 40+i*4, string.rep(' ', self.width+1), 0xffffff),
bg = { },
textFields = { },
}
end
end
function Glasses:setBackgroundBox(boxes, ax, bx, y, bgColor)
local colors = {
[ colors.black ] = 0x000000,
[ colors.brown ] = 0x7F664C,
[ colors.blue ] = 0x253192,
[ colors.red ] = 0xFF0000,
[ colors.gray ] = 0x272727,
[ colors.lime ] = 0x426A0D,
[ colors.green ] = 0x2D5628,
[ colors.white ] = 0xFFFFFF
}
local function overlap(box, ax, bx)
if bx < box.ax or ax > box.bx then
return false
end
return true
end
for _,box in pairs(boxes) do
if overlap(box, ax, bx) then
if box.bgColor == bgColor then
ax = math.min(ax, box.ax)
bx = math.max(bx, box.bx)
box.ax = box.bx + 1
elseif ax == box.ax then
box.ax = bx + 1
elseif ax > box.ax then
if bx < box.bx then
table.insert(boxes, { -- split
ax = bx + 1,
bx = box.bx,
bgColor = box.bgColor
})
box.bx = ax - 1
break
else
box.ax = box.bx + 1
end
elseif ax < box.ax then
if bx > box.bx then
box.ax = box.bx + 1 -- delete
else
box.ax = bx + 1
end
end
end
end
if bgColor ~= colors.black then
table.insert(boxes, {
ax = ax,
bx = bx,
bgColor = bgColor
})
end
local deleted
repeat
deleted = false
for k,box in pairs(boxes) do
if box.ax > box.bx then
if box.box then
box.box.delete()
end
table.remove(boxes, k)
deleted = true
break
end
if not box.box then
box.box = self.bridge.addBox(
math.floor(self.x + (box.ax - 1) * self.multiplier),
self.y + y * 4,
math.ceil((box.bx - box.ax + 1) * self.multiplier),
4,
colors[bgColor],
self.backgroundOpacity)
else
box.box.setX(self.x + math.floor((box.ax - 1) * self.multiplier))
box.box.setWidth(math.ceil((box.bx - box.ax + 1) * self.multiplier))
end
end
until not deleted
end
function Glasses:write(x, y, text, bg)
if x < 1 then
error(' less ', 6)
end
if y <= #self.t then
local line = self.t[y]
local str = line.text
str = str:sub(1, x-1) .. text .. str:sub(x + #text)
self.t[y].text = str
for _,tf in pairs(line.textFields) do
tf.delete()
end
line.textFields = { }
local function split(st)
local words = { }
local offset = 0
while true do
local b,e,w = st:find('(%S+)')
if not b then
break
end
table.insert(words, {
offset = b + offset - 1,
text = w,
})
offset = offset + e
st = st:sub(e + 1)
end
return words
end
local words = split(str)
for _,word in pairs(words) do
local tf = self.bridge.addText(self.x + word.offset * self.multiplier,
self.y+y*4, '', 0xffffff)
tf.setScale(self.textScale)
tf.setZ(1)
tf.setText(word.text)
table.insert(line.textFields, tf)
end
self:setBackgroundBox(line.bg, x, x + #text - 1, y, bg)
end
end
function Glasses:clear(bg)
for _,line in pairs(self.t) do
for _,tf in pairs(line.textFields) do
tf.delete()
end
line.textFields = { }
line.text = string.rep(' ', self.width+1)
-- self.t[i].text.setText('')
end
end
function Glasses:reset()
self:clear()
self.bridge.clear()
self.bridge.sync()
end
function Glasses:sync()
self.bridge.sync()
end
return Glasses

View File

@@ -1,173 +0,0 @@
--[[
Breed rabbits with a rabbit.
]]
local neural = require('neural.interface')
local Point = require('point')
local Sound = require('sound')
local Util = require('util')
local os = _G.os
local BREEDING = 'Rabbit'
local WALK_SPEED = 1.3
local MAX_GROWN = 100
local BREED_DELAY = 120
neural.assertModules({
'plethora:sensor',
'plethora:scanner',
'plethora:laser',
'plethora:kinetic',
'plethora:introspection',
})
local ID = neural.getID()
local fed = { }
local function resupply()
local slot = neural.getEquipment().list()[1]
if slot and slot.count > 32 then
return
end
print('resupplying')
local dispenser = Util.find(neural.scan(), 'name', 'minecraft:wooden_pressure_plate')
if dispenser then
if math.abs(dispenser.x) > 1 or math.abs(dispenser.z) > 1 then
neural.walkTo({ x = dispenser.x, y = 0, z = dispenser.z }, WALK_SPEED)
end
neural.lookAt(dispenser)
neural.getEquipment().suck(1, 64)
end
end
local function breed(entity)
print('breeding')
entity.lastFed = os.clock()
fed[entity.id] = entity
neural.walkTo(entity, WALK_SPEED, .5)
entity = neural.getMetaByID(entity.id)
if entity and not entity.isChild then
neural.lookAt(entity)
neural.use(1)
os.sleep(.1)
end
end
local function kill(entity)
print('killing')
neural.walkTo(entity, WALK_SPEED, 2)
entity = neural.getMetaByID(entity.id)
if entity and not entity.isChild then
neural.lookAt(entity)
neural.fireAt({ x = entity.x, y = 0, z = entity.z })
Sound.play('entity.firework.launch')
os.sleep(.2)
end
end
local function getEntities()
return Util.filter(neural.sense(), function(entity)
if entity.name == BREEDING and entity.y > -.5 and entity.id ~= ID then
return true
end
end)
end
local function getHungry(entities)
for _,v in pairs(entities) do
if not fed[v.id] or
os.clock() - fed[v.id].lastFed > BREED_DELAY then
return v
end
end
end
local function randomEntity(entities)
local r = math.random(1, Util.size(entities))
local i = 1
for _, v in pairs(entities) do
i = i + 1
if i > r then
return v
end
end
end
local function dropOff()
print('dropping')
if neural.getEquipment().list()[2] then
local b = Util.find(neural.scan(), 'name', 'minecraft:hopper')
if b then
neural.walkTo({ x = b.x, y = 0, z = b.z }, 2)
b = Util.find(neural.scan(), 'name', 'minecraft:hopper')
if b and math.abs(b.x) < 1 and math.abs(b.z) < 1 then
print('dropped')
neural.getEquipment().drop(2)
end
end
end
end
local function pickup(id)
local b = neural.getMetaByID(id)
if b then
neural.walkTo(b, 2)
local main = neural.getEquipment().list()[1]
local amount = neural.getEquipment().suck(not main and 2 or nil)
print('sucked: ' .. amount)
if amount > 0 then
Sound.play('entity.item.pickup')
return true
end
end
end
local function drops()
local sensed = Util.reduce(neural.sense(), function(acc, s)
if Util.round(s.y) == 0 and s.name == 'Item' then
acc[s.id] = s
end
return acc
end, { })
local pt = { x = 0, y = 0, z = 0 }
while true do
local b = Point.closest(pt, sensed)
if not b then
break
end
sensed[b.id] = nil
if pickup(b.id) then
pt = b
else
dropOff()
break
end
end
end
while true do
resupply()
local entities = getEntities()
if Util.size(entities) > MAX_GROWN then
kill(randomEntity(entities))
else
local entity = getHungry(entities)
if entity then
breed(entity)
else
print('sleeping')
os.sleep(5)
end
drops()
end
end