Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local component = require( "component" )
- local gpu = component.gpu
- local event = require( "event" )
- local filesystem = require("filesystem")
- local internet = require("internet")
- local oldW, oldH = gpu.getResolution()
- local url = "http://writeescape.com/points.php"
- gpu.setResolution( 160, 50 )
- JSON = (loadfile "JSON.lua")()
- function compareCaseInsensitive(a, b)
- return a:lower() < b:lower()
- end
- function getScoreboard()
- local payload = ""
- for chunk in internet.request(url) do
- payload = payload .. chunk
- end
- local scores = JSON:decode(payload)
- local temp = {}
- for n in pairs(scores) do
- table.insert(temp, n)
- end
- table.sort(temp, compareCaseInsensitive)
- local i = 0
- local iter = function()
- i = i + 1
- if temp[i] == nil then
- return nil
- else
- return temp[i], scores[temp[i]]
- end
- end
- return iter
- end
- function clearScreen()
- local oldColor = gpu.getBackground( false )
- local w,h = gpu.getResolution()
- gpu.setBackground( 0x000000, false )
- gpu.fill( 1, 1, w, h, " " )
- gpu.setBackground( oldColor, false )
- end
- function progressBar( label, y, value, maxVal, color, show, unit )
- local oldColor = gpu.getBackground( false )
- gpu.setBackground(0x000000, false)
- gpu.fill( 3, y, 155, 2, " " )
- w = math.floor( value * (75 / maxVal) )
- p = math.floor( (w / 155) * 100 )
- gpu.set( 3, y, label .. ": " .. tostring( value ) .. " Points" )
- gpu.setBackground( 0x222222, false )
- gpu.fill( 3, y+2, 155, 2, " " )
- gpu.setBackground( color, false )
- gpu.fill( 3, y+2, w, 2, " " )
- gpu.setBackground( oldColor, false )
- if show then
- local valStr = formatBig( value ) .. unit
- local n = string.len( valStr )
- gpu.set( 78 - n, y, valStr )
- end
- end
- clearScreen()
- local max = 100
- local cur = 0
- local yLevel = 10
- while true do
- local _,_,x,y = event.pull( 1, "touch" )
- if x and y then goto quit end
- for name, value in getScoreboard() do
- progressBar(name, yLevel, value["pts"], value["total"], value["color"], false, "Points")
- yLevel = yLevel + 5
- end
- yLevel = 10
- os.sleep(5)
- end
- ::quit::
- gpu.setResolution( oldW, oldH )
- clearScreen()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement