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