mirror of
https://github.com/kepler155c/opus
synced 2024-12-31 19:00:27 +00:00
reduce net traffic
This commit is contained in:
parent
ccc7693f46
commit
4c2d121562
@ -121,8 +121,7 @@ print('discovery: listening on port 999')
|
||||
|
||||
Event.on('modem_message', function(_, _, sport, id, info, distance)
|
||||
if sport == 999 and tonumber(id) and type(info) == 'table' then
|
||||
if info.label and info.id and
|
||||
type(info.label) == 'string' and type(info.id) == 'number' then
|
||||
if type(info.label) == 'string' and type(info.id) == 'number' then
|
||||
|
||||
if not network[id] then
|
||||
network[id] = { }
|
||||
@ -150,6 +149,15 @@ local info = {
|
||||
}
|
||||
local infoTimer = os.clock()
|
||||
|
||||
local function getSlots()
|
||||
return Util.reduce(turtle.getInventory(), function(acc, v)
|
||||
if v.count > 0 then
|
||||
acc[v.index .. ',' .. v.count] = v.key
|
||||
end
|
||||
return acc
|
||||
end, { })
|
||||
end
|
||||
|
||||
local function sendInfo()
|
||||
if os.clock() - infoTimer >= 1 then -- don't flood
|
||||
infoTimer = os.clock()
|
||||
@ -160,7 +168,7 @@ local function sendInfo()
|
||||
info.fuel = turtle.getFuelLevel()
|
||||
info.status = turtle.getStatus()
|
||||
info.point = turtle.point
|
||||
info.inventory = turtle.getInventory()
|
||||
info.inv = getSlots()
|
||||
info.slotIndex = turtle.getSelectedSlot()
|
||||
end
|
||||
if device.neuralInterface then
|
||||
@ -168,28 +176,24 @@ local function sendInfo()
|
||||
if not info.status and device.neuralInterface.getMetaOwner then
|
||||
pcall(function()
|
||||
local meta = device.neuralInterface.getMetaOwner()
|
||||
|
||||
if meta.isWet then
|
||||
info.status = 'Swimming'
|
||||
elseif meta.isElytraFlying then
|
||||
info.status = 'Flying'
|
||||
elseif meta.isBurning then
|
||||
info.status = 'Burning'
|
||||
elseif meta.isDead then
|
||||
info.status = 'Deceased'
|
||||
elseif meta.isOnLadder then
|
||||
info.status = 'Climbing'
|
||||
elseif meta.isRiding then
|
||||
info.status = 'Riding'
|
||||
elseif meta.isSneaking then
|
||||
info.status = 'Sneaking'
|
||||
elseif meta.isSprinting then
|
||||
info.status = 'Running'
|
||||
else
|
||||
info.status = 'health: ' ..
|
||||
math.floor(meta.health /
|
||||
meta.maxHealth * 100)
|
||||
local states = {
|
||||
isWet = 'Swimming',
|
||||
isElytraFlying = 'Flying',
|
||||
isBurning = 'Burning',
|
||||
isDead = 'Deceased',
|
||||
isOnLadder = 'Climbing',
|
||||
isRiding = 'Riding',
|
||||
isSneaking = 'Sneaking',
|
||||
isSprinting = 'Running',
|
||||
}
|
||||
for k,v in pairs(states) do
|
||||
if meta[k] then
|
||||
info.status = v
|
||||
break
|
||||
end
|
||||
end
|
||||
info.status = info.status or 'health: ' ..
|
||||
math.floor(meta.health / meta.maxHealth * 100)
|
||||
end)
|
||||
end
|
||||
end
|
||||
@ -216,4 +220,4 @@ Event.on('turtle_response', function()
|
||||
end
|
||||
end)
|
||||
|
||||
sendInfo()
|
||||
Event.onTimeout(1, sendInfo)
|
||||
|
@ -45,8 +45,8 @@ local tab = UI.Tab {
|
||||
ex = -2,
|
||||
},
|
||||
percentage = UI.Text {
|
||||
x = 11, y = -1,
|
||||
ex = -2,
|
||||
x = 11, y = -3,
|
||||
ex = '47%',
|
||||
align = 'center',
|
||||
},
|
||||
icon = UI.NftImage {
|
||||
@ -57,19 +57,16 @@ local tab = UI.Tab {
|
||||
|
||||
local function getDrives()
|
||||
local unique = { ['hdd'] = true, ['virt'] = true }
|
||||
local exclude = {}
|
||||
local drives = {
|
||||
{name = 'hdd', side = ''},
|
||||
}
|
||||
local drives = { { name = 'hdd', side = '' } }
|
||||
|
||||
for _, drive in pairs(fs.list('/')) do
|
||||
local side = fs.getDrive(drive)
|
||||
if side and not unique[side] then
|
||||
unique[side] = true
|
||||
exclude[drive] = true
|
||||
table.insert(drives, {name=drive, side=side})
|
||||
table.insert(drives, { name = drive, side = side })
|
||||
end
|
||||
end
|
||||
return drives, exclude
|
||||
return drives
|
||||
end
|
||||
|
||||
local function getDriveInfo(p)
|
||||
@ -125,8 +122,7 @@ function tab:updateInfo()
|
||||
end
|
||||
|
||||
function tab:updateDrives()
|
||||
local drives, exclude = getDrives()
|
||||
self.exclude = exclude
|
||||
local drives = getDrives()
|
||||
self.drives:setValues(drives)
|
||||
end
|
||||
|
||||
@ -139,7 +135,8 @@ end
|
||||
function tab:eventHandler(event)
|
||||
if event.type == 'grid_focus_row' then
|
||||
self:updateInfo()
|
||||
else return UI.Tab.eventHandler(self, event)
|
||||
else
|
||||
return UI.Tab.eventHandler(self, event)
|
||||
end
|
||||
return true
|
||||
end
|
||||
@ -151,4 +148,4 @@ Event.on({ 'disk', 'disk_eject' }, function()
|
||||
tab:sync()
|
||||
end)
|
||||
|
||||
return tab
|
||||
return tab
|
||||
|
Loading…
Reference in New Issue
Block a user