Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.loadAPI('apis.lua')
- Peripheral.wrap('wireless_modem')
- local bossId
- local state
- local status
- Logger.disable()
- local terminal = UI.term
- if Peripheral.isPresent({ type = 'openperipheral_glassesbridge' }) then
- terminal = UI.Glasses({
- --height = 30,
- --width = 40,
- textScale = .5,
- })
- elseif Peripheral.isPresent({ type = 'monitor' }) then
- terminal = UI.Device({
- deviceType = 'monitor',
- textScale = .5
- })
- end
- local window = UI.Window({ parent = terminal })
- window:clear()
- statusPage = UI.Page({
- parent = window,
- titleBar = UI.TitleBar({
- title = 'Mining Status'
- }),
- statusInfo = UI.Window({
- totalHolesProgressBar = UI.ProgressBar({
- y = 7,
- x = 2,
- width = window.width - 2
- }),
- chunkHolesProgressBar = UI.ProgressBar({
- y = 10,
- x = 2,
- width = window.width - 2
- }),
- }),
- statusBar = UI.StatusBar({
- backgroundColor = colors.blue
- })
- })
- --statusPage.titleBar:draw()
- if terminal.height > 17 then
- statusPage:add({
- logTitleBar = UI.TitleBar({
- title = 'Log Messages',
- y = 13
- }),
- scrollingText = UI.ScrollingText({
- backgroundColor = colors.green,
- y = 14,
- height = terminal.height - 13
- })
- })
- Message.addHandler('log', function(h, id, msg)
- if bossId and id == bossId then
- statusPage.scrollingText:write(os.clock() .. ' ' .. msg.contents)
- end
- end)
- Message.addHandler('logClient', function(h, id)
- Message.send(id, 'logServer')
- end)
- end
- function statusPage.statusBar:draw()
- if state then
- self:setValue('status', state.status)
- end
- UI.StatusBar.draw(self)
- end
- function statusPage.statusInfo:draw()
- if not state or not status then
- return
- end
- if state.chunks ~= -1 then
- local totalHoles = state.chunks * 52 -- roughly
- local percentDone = state.holes * 100 / totalHoles
- self.totalHolesProgressBar:setProgress(percentDone)
- self:centeredWrite(8, string.format('Total: %d of ~%d holes (%d%%)',
- state.holes, totalHoles, percentDone))
- else
- self:centeredWrite(8, string.format('Total holes: %d', state.holes))
- self.totalHolesProgressBar:setProgress(Util.random(100))
- end
- local currentChunk = math.pow(state.diameter-2, 2) + state.chunkIndex + 1
- if state.diameter == 1 then
- currentChunk = 1
- end
- if state.chunks == -1 then
- self:write(2, 3, string.format('Chunk %d', currentChunk))
- else
- self:write(2, 3, string.format('Chunk %d of %d', currentChunk, state.chunks))
- end
- self:write(2, 4, string.format('Miners %d', status.count))
- if state.depth ~= 9000 then
- self:write(2, 5, string.format('Depth %d', state.depth))
- end
- local totalHoles = 52 -- roughly
- local holesRemaining = #state.locations
- if holesRemaining > totalHoles then
- totalHoles = holesRemaining
- end
- local percentDone = 100 - (holesRemaining * 100 / totalHoles)
- self.chunkHolesProgressBar:setProgress(percentDone)
- self:centeredWrite(11, string.format('Current Chunk: %d%%', percentDone))
- self.chunkHolesProgressBar:draw()
- self.totalHolesProgressBar:draw()
- end
- Message.addHandler('miningStatus', function(h, id, msg)
- bossId = id
- state = msg.contents.state
- status = msg.contents.status
- statusPage.statusInfo:draw()
- statusPage.statusBar:draw()
- end)
- Event.addHandler('heartbeat', function()
- Message.send(bossId, 'getMiningStatus')
- end)
- Event.addHandler('char', function()
- Event.exitPullEvents()
- end)
- statusPage:draw()
- Message.broadcast('getMiningStatus')
- Event.heartbeat(5)
- window:clear()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement