mirror of
https://github.com/kepler155c/opus
synced 2025-06-14 12:34:11 +00:00
cleanup
This commit is contained in:
parent
a074213b7c
commit
4546b9c726
@ -8,6 +8,15 @@ multishell.setTitle(multishell.getCurrent(), 'Turtles')
|
|||||||
UI.Button.defaults.focusIndicator = ' '
|
UI.Button.defaults.focusIndicator = ' '
|
||||||
UI:configure('Turtles', ...)
|
UI:configure('Turtles', ...)
|
||||||
|
|
||||||
|
local options = {
|
||||||
|
turtle = { arg = 'i', type = 'number', value = -1,
|
||||||
|
desc = 'Turtle ID' },
|
||||||
|
tab = { arg = 's', type = 'string', value = 'inventory',
|
||||||
|
desc = 'Selected tab to display' },
|
||||||
|
help = { arg = 'h', type = 'flag', value = false,
|
||||||
|
desc = 'Displays the options' },
|
||||||
|
}
|
||||||
|
|
||||||
local SCRIPTS_PATH = '/apps/scripts'
|
local SCRIPTS_PATH = '/apps/scripts'
|
||||||
|
|
||||||
local ct = term.current()
|
local ct = term.current()
|
||||||
@ -62,7 +71,7 @@ local page = UI.Page {
|
|||||||
},
|
},
|
||||||
]]
|
]]
|
||||||
coords = UI.Window {
|
coords = UI.Window {
|
||||||
x = 16, y = 2, height = 4, width = 9,
|
x = 14, y = 2, height = 5, rex = -2,
|
||||||
},
|
},
|
||||||
tabs = UI.Tabs {
|
tabs = UI.Tabs {
|
||||||
x = 1, y = 8, rey = -2,
|
x = 1, y = 8, rey = -2,
|
||||||
@ -146,7 +155,8 @@ function page.coords:draw()
|
|||||||
if t then
|
if t then
|
||||||
self:clear()
|
self:clear()
|
||||||
self:setCursorPos(1, 1)
|
self:setCursorPos(1, 1)
|
||||||
self:print(string.format('%s\nx: %d\ny: %d\nz: %d\n', t.coordSystem, t.point.x, t.point.y, t.point.z))
|
self:print(string.format('%s\nx: %d\ny: %d\nz: %d\nFuel: %s\n',
|
||||||
|
t.coordSystem, t.point.x, t.point.y, t.point.z, Util.toBytes(t.fuel)))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -282,7 +292,17 @@ local function updateThread()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if not Util.getOptions(options, { ... }, true) then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
if options.turtle.value then
|
||||||
|
page.turtle = _G.network[options.turtle.value]
|
||||||
|
end
|
||||||
|
|
||||||
UI:setPage(page)
|
UI:setPage(page)
|
||||||
|
|
||||||
|
page.tabs:activateTab(page.tabs[options.tab.value])
|
||||||
|
|
||||||
Event.pullEvents(updateThread)
|
Event.pullEvents(updateThread)
|
||||||
UI.term:reset()
|
UI.term:reset()
|
||||||
|
@ -40,12 +40,14 @@ function getItemDetails(item)
|
|||||||
detail = controller.findItem(item)
|
detail = controller.findItem(item)
|
||||||
if detail then
|
if detail then
|
||||||
Util.merge(detail, detail.getMetadata())
|
Util.merge(detail, detail.getMetadata())
|
||||||
detail.displayName = safeString(detail.displayName)
|
if detail.displayName then
|
||||||
if detail.maxDamage and detail.maxDamage > 0 and detail.damage > 0 then
|
detail.displayName = safeString(detail.displayName)
|
||||||
detail.displayName = detail.displayName .. ' (damaged)'
|
if detail.maxDamage and detail.maxDamage > 0 and detail.damage > 0 then
|
||||||
|
detail.displayName = detail.displayName .. ' (damaged)'
|
||||||
|
end
|
||||||
|
detail.lname = detail.displayName:lower()
|
||||||
|
cache[key] = detail
|
||||||
end
|
end
|
||||||
detail.lname = detail.displayName:lower()
|
|
||||||
cache[key] = detail
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return detail
|
return detail
|
||||||
@ -303,7 +305,6 @@ function itemPage.displayName:draw()
|
|||||||
if item.nbtHash then
|
if item.nbtHash then
|
||||||
str = str .. string.format('\nNBT: %s\n', item.nbtHash)
|
str = str .. string.format('\nNBT: %s\n', item.nbtHash)
|
||||||
end
|
end
|
||||||
debug(str)
|
|
||||||
self:setCursorPos(1, 1)
|
self:setCursorPos(1, 1)
|
||||||
self:print(str)
|
self:print(str)
|
||||||
end
|
end
|
||||||
@ -478,11 +479,7 @@ function listingPage:enable()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function listingPage:refresh()
|
function listingPage:refresh()
|
||||||
local t = os.clock()
|
|
||||||
|
|
||||||
self.allItems = listItems()
|
self.allItems = listItems()
|
||||||
debug('list items')
|
|
||||||
debug(os.clock() - t)
|
|
||||||
mergeResources(self.allItems)
|
mergeResources(self.allItems)
|
||||||
self:applyFilter()
|
self:applyFilter()
|
||||||
end
|
end
|
||||||
@ -492,43 +489,6 @@ function listingPage:applyFilter()
|
|||||||
self.grid:setValues(t)
|
self.grid:setValues(t)
|
||||||
end
|
end
|
||||||
|
|
||||||
local nullDevice = {
|
|
||||||
setCursorPos = function(...) end,
|
|
||||||
write = function(...) end,
|
|
||||||
getSize = function() return 13, 20 end,
|
|
||||||
isColor = function() return false end,
|
|
||||||
setBackgroundColor = function(...) end,
|
|
||||||
setTextColor = function(...) end,
|
|
||||||
clear = function(...) end,
|
|
||||||
sync = function(...) end,
|
|
||||||
}
|
|
||||||
|
|
||||||
local function jobMonitor(jobList)
|
|
||||||
|
|
||||||
local mon = Peripheral.getByType('monitor')
|
|
||||||
|
|
||||||
if mon then
|
|
||||||
mon = UI.Device({
|
|
||||||
device = mon,
|
|
||||||
textScale = .5,
|
|
||||||
})
|
|
||||||
else
|
|
||||||
mon = UI.Device({
|
|
||||||
device = nullDevice
|
|
||||||
})
|
|
||||||
end
|
|
||||||
|
|
||||||
jobListGrid = UI.Grid {
|
|
||||||
parent = mon,
|
|
||||||
sortColumn = 'displayName',
|
|
||||||
columns = {
|
|
||||||
{ heading = 'Qty', key = 'count', width = 6 },
|
|
||||||
{ heading = 'Crafting', key = 'displayName', width = mon.width / 2 - 10 },
|
|
||||||
{ heading = 'Status', key = 'status', width = mon.width - 10 },
|
|
||||||
},
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
local function jobMonitor(jobList)
|
local function jobMonitor(jobList)
|
||||||
|
|
||||||
local mon = Peripheral.getByType('monitor')
|
local mon = Peripheral.getByType('monitor')
|
||||||
|
@ -1,13 +1,10 @@
|
|||||||
require = requireInjector(getfenv(1))
|
require = requireInjector(getfenv(1))
|
||||||
|
local Util = require('util')
|
||||||
local Event = require('event')
|
local Event = require('event')
|
||||||
local UI = require('ui')
|
local UI = require('ui')
|
||||||
local RefinedProvider = require('refinedProvider')
|
local RefinedProvider = require('refinedProvider')
|
||||||
local MEProvider = require('meProvider')
|
local MEProvider = require('meProvider')
|
||||||
|
|
||||||
if not device.monitor then
|
|
||||||
error('Monitor not found')
|
|
||||||
end
|
|
||||||
|
|
||||||
local storage = RefinedProvider()
|
local storage = RefinedProvider()
|
||||||
if not storage:isValid() then
|
if not storage:isValid() then
|
||||||
storage = MEProvider()
|
storage = MEProvider()
|
||||||
@ -17,45 +14,21 @@ if not storage:isValid() then
|
|||||||
error('Not connected to a storage device')
|
error('Not connected to a storage device')
|
||||||
end
|
end
|
||||||
|
|
||||||
local monitor = UI.Device({
|
|
||||||
deviceType = 'monitor',
|
|
||||||
textScale = .5
|
|
||||||
})
|
|
||||||
UI:setDefaultDevice(monitor)
|
|
||||||
|
|
||||||
multishell.setTitle(multishell.getCurrent(), 'Storage Activity')
|
multishell.setTitle(multishell.getCurrent(), 'Storage Activity')
|
||||||
UI:configure('StorageActivity', ...)
|
UI:configure('StorageActivity', ...)
|
||||||
|
|
||||||
-- Strip off color prefix
|
|
||||||
local function safeString(text)
|
|
||||||
|
|
||||||
local val = text:byte(1)
|
|
||||||
|
|
||||||
if val < 32 or val > 128 then
|
|
||||||
|
|
||||||
local newText = {}
|
|
||||||
for i = 4, #text do
|
|
||||||
local val = text:byte(i)
|
|
||||||
newText[i - 3] = (val > 31 and val < 127) and val or 63
|
|
||||||
end
|
|
||||||
return string.char(unpack(newText))
|
|
||||||
end
|
|
||||||
|
|
||||||
return text
|
|
||||||
end
|
|
||||||
|
|
||||||
local changedPage = UI.Page({
|
local changedPage = UI.Page({
|
||||||
grid = UI.Grid({
|
grid = UI.Grid({
|
||||||
columns = {
|
columns = {
|
||||||
{ heading = 'Qty', key = 'dispQty', width = 5 },
|
{ heading = 'Qty', key = 'qty', width = 5 },
|
||||||
{ heading = 'Change', key = 'change', width = 6 },
|
{ heading = 'Change', key = 'change', width = 6 },
|
||||||
{ heading = 'Name', key = 'name', width = monitor.width - 15 },
|
{ heading = 'Name', key = 'display_name', width = UI.term.width - 15 },
|
||||||
},
|
},
|
||||||
sortColumn = 'name',
|
sortColumn = 'display_name',
|
||||||
height = monitor.height - 6,
|
rey = -6,
|
||||||
}),
|
}),
|
||||||
buttons = UI.Window({
|
buttons = UI.Window({
|
||||||
y = monitor.height - 5,
|
ry = -4,
|
||||||
height = 5,
|
height = 5,
|
||||||
backgroundColor = colors.gray,
|
backgroundColor = colors.gray,
|
||||||
prevButton = UI.Button({
|
prevButton = UI.Button({
|
||||||
@ -73,31 +46,37 @@ local changedPage = UI.Page({
|
|||||||
x = 8,
|
x = 8,
|
||||||
y = 2,
|
y = 2,
|
||||||
height = 3,
|
height = 3,
|
||||||
width = monitor.width - 14,
|
rex = -8,
|
||||||
text = 'Reset'
|
text = 'Reset'
|
||||||
}),
|
}),
|
||||||
nextButton = UI.Button({
|
nextButton = UI.Button({
|
||||||
event = 'next',
|
event = 'next',
|
||||||
backgroundColor = colors.lightGray,
|
backgroundColor = colors.lightGray,
|
||||||
x = monitor.width - 5,
|
rx = -5,
|
||||||
y = 2,
|
y = 2,
|
||||||
height = 3,
|
height = 3,
|
||||||
width = 5,
|
width = 5,
|
||||||
text = ' > '
|
text = ' > '
|
||||||
})
|
})
|
||||||
}),
|
}),
|
||||||
statusBar = UI.StatusBar({
|
|
||||||
columns = {
|
|
||||||
{ '', 'slots', 18 },
|
|
||||||
{ '', 'spacer', monitor.width-36 },
|
|
||||||
{ '', 'space', 15 }
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
accelerators = {
|
accelerators = {
|
||||||
q = 'quit',
|
q = 'quit',
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
function changedPage.grid:getDisplayValues(row)
|
||||||
|
row = Util.shallowCopy(row)
|
||||||
|
|
||||||
|
local ind = '+'
|
||||||
|
if row.change < 0 then
|
||||||
|
ind = ''
|
||||||
|
end
|
||||||
|
row.change = ind .. Util.toBytes(row.change)
|
||||||
|
row.qty = Util.toBytes(row.qty)
|
||||||
|
|
||||||
|
return row
|
||||||
|
end
|
||||||
|
|
||||||
function changedPage:eventHandler(event)
|
function changedPage:eventHandler(event)
|
||||||
|
|
||||||
if event.type == 'reset' then
|
if event.type == 'reset' then
|
||||||
@ -132,11 +111,7 @@ function changedPage:refresh()
|
|||||||
end
|
end
|
||||||
|
|
||||||
for k,v in pairs(t) do
|
for k,v in pairs(t) do
|
||||||
--v.id = v.id
|
|
||||||
--v.dmg = v.dmg
|
|
||||||
v.name = safeString(v.display_name)
|
|
||||||
t[k] = Util.shallowCopy(v)
|
t[k] = Util.shallowCopy(v)
|
||||||
--v.qty = v.qty
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if not self.lastItems then
|
if not self.lastItems then
|
||||||
@ -172,22 +147,14 @@ function changedPage:refresh()
|
|||||||
v.lastQty = 0
|
v.lastQty = 0
|
||||||
table.insert(changedItems, v)
|
table.insert(changedItems, v)
|
||||||
end
|
end
|
||||||
|
|
||||||
for k,v in pairs(changedItems) do
|
for k,v in pairs(changedItems) do
|
||||||
local diff = v.qty - v.lastQty
|
v.change = v.qty - v.lastQty
|
||||||
local ind = '+'
|
|
||||||
if v.qty < v.lastQty then
|
|
||||||
ind = ''
|
|
||||||
end
|
|
||||||
v.change = ind .. diff
|
|
||||||
v.dispQty = v.qty
|
|
||||||
if v.dispQty > 10000 then
|
|
||||||
v.dispQty = math.floor(v.qty / 1000) .. 'k'
|
|
||||||
end
|
|
||||||
v.iddmg = tostring(v.id) .. ':' .. tostring(v.dmg)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
self.grid:setValues(changedItems)
|
self.grid:setValues(changedItems)
|
||||||
end
|
end
|
||||||
self:draw()
|
self.grid:draw()
|
||||||
end
|
end
|
||||||
|
|
||||||
Event.addTimer(5, true, function()
|
Event.addTimer(5, true, function()
|
||||||
@ -196,5 +163,5 @@ Event.addTimer(5, true, function()
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
UI:setPage(changedPage)
|
UI:setPage(changedPage)
|
||||||
Event.pullEvents()
|
UI:pullEvents()
|
||||||
UI.term:reset()
|
UI.term:reset()
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
local class = require('class')
|
local class = require('class')
|
||||||
local Logger = require('logger')
|
|
||||||
|
|
||||||
local ChestProvider = class()
|
local ChestProvider = class()
|
||||||
|
|
||||||
|
@ -357,9 +357,9 @@ end
|
|||||||
|
|
||||||
--[[ String functions ]] --
|
--[[ String functions ]] --
|
||||||
function Util.toBytes(n)
|
function Util.toBytes(n)
|
||||||
if n >= 1000000 then
|
if n >= 1000000 or n <= -1000000 then
|
||||||
return string.format('%sM', Util.round(n/1000000, 1))
|
return string.format('%sM', Util.round(n/1000000, 1))
|
||||||
elseif n >= 1000 then
|
elseif n >= 1000 or n <= -1000 then
|
||||||
return string.format('%sK', Util.round(n/1000, 1))
|
return string.format('%sK', Util.round(n/1000, 1))
|
||||||
end
|
end
|
||||||
return tostring(n)
|
return tostring(n)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user