Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- cobalt = {
- graphics = { },
- filesystem = { },
- event = { },
- window = { },
- _mainloop = true,
- vars = {
- backgroundcolour = colours.black,
- textcolour = colours.white
- },
- keyboard = {
- keysdown = { },
- },
- rednet = {
- },
- mouse = { },
- table = { },
- state = "MAIN",
- version = "1.0",
- updatespeed = 0.1
- }
- cobalt.updatetimer = os.startTimer( cobalt.updatespeed )
- function cobalt.debug( item )
- term.setBackgroundColour( colours.black )
- term.setTextColour( colours.white )
- term.clear()
- term.setCursorPos( 1,1 )
- print( "COBALT DEBUG" )
- print( item )
- cobalt.exit()
- end
- args = { ... }
- if args[1] == "version" then
- print( "Cobalt " .. cobalt.version )
- elseif args[1] == "help" then
- print( "You can find help resources here: ")
- print( "https://github.com/ebernerd/Cobalt/wiki")
- elseif args[1] == "examples" then
- if fs.isDir( "cobalt-examples" ) then
- if args[2] then
- if fs.exists( "cobalt-examples/" .. args[2] ) then
- shell.run( "cobalt-examples/" .. args[2] )
- else
- print( "List of Cobalt examples: ")
- for i, v in pairs( fs.list( "cobalt-examples" ) ) do
- print( "-" .. v )
- end
- end
- else
- print( "List of Cobalt examples: ")
- for i, v in pairs( fs.list( "cobalt-examples" ) ) do
- print( "-" .. v )
- end
- end
- else
- print( "Download the Cobalt examples here" )
- print( "http://github.com/ebernerd")
- end
- end
- cobalt.g = cobalt.graphics
- cobalt.k = cobalt.keyboard
- cobalt.fs = cobalt.filesystem
- cobalt.e = cobalt.event
- cobalt.w = cobalt.window
- cobalt.m = cobalt.mouse
- local graphics_lighten = {
- [32768] = colours.grey,
- [128] = colours.lightGrey,
- [256] = colours.white,
- [1] = colours.white,
- [2048] = colours.cyan,
- [512] = colours.lightBlue,
- [8] = colours.white,
- [8192] = colours.lime,
- [32] = colours.white,
- [4096] = colours.orange,
- [2] = colours.yellow,
- [16] = colours.white,
- [16384] = colours.pink,
- [64] = colours.white,
- [1024] = colours.magenta,
- [4] = colours.white,
- }
- local graphics_darken = {
- }
- --[=[ GRAPHICS FUNCTIONS ]=]--
- function cobalt.graphics.print( text, x, y, colour )
- term.setTextColour( colour or term.getTextColour() )
- term.setCursorPos( x, y )
- print( text )
- end
- function cobalt.graphics.write( text, x, y, colour )
- term.setTextColour( colour or term.getTextColour() )
- term.setCursorPos( x, y )
- write( text )
- end
- function cobalt.graphics.rect( mode, x, y, w, h, colour )
- if mode == "fill" then
- paintutils.drawFilledBox( x, y, x+w, y+h, colour )
- elseif mode == "line" then
- paintutils.drawBox( x, y, x+w, y+h, colour )
- end
- end
- function cobalt.graphics.center( text, y, offset )
- text = text or "Some Text"
- y = y or 1
- offset = offset or 0
- cobalt.graphics.print( text, (cobalt.window.getWidth()/2-#text/2)-offset, y )
- end
- function cobalt.graphics.centerInArea( text, x1, y1, x2, y2 )
- text = text or "Some Text"
- x1 = x1 or 1
- x2 = x2 or cobalt.window.getWidth()
- y1 = y1 or 1
- y2 = y2 or cobalt.window.getHeight()
- cobalt.graphics.print( text, (x1+x2)/2-#text/2, (y1+y2)/2 )
- end
- cobalt.graphics.rectangle = cobalt.graphics.rect
- cobalt.graphics.pixel = paintutils.drawPixel
- cobalt.graphics.line = paintutils.drawLine
- --[=[function cobalt.graphics.setBackgroundColour( colour )
- cobalt.vars.backgroundcolour = colour
- end--]=]
- cobalt.graphics.setBackgroundColour = term.setBackgroundColour
- --[=[function cobalt.graphics.setColour( colour )
- cobalt.vars.textcolour = colour
- end--]=]
- cobalt.graphics.setColour = term.setTextColour
- function cobalt.graphics.lighten( colour )
- return graphics_lighten[colour]
- end
- function cobalt.graphics.darken( colour )
- return graphics_darken[colour]
- end
- --[=[WINDOW FUNCTIONS]=]--
- function cobalt.window.getWidth()
- local x, _ = term.getSize()
- return x
- end
- function cobalt.window.getHeight()
- local _, y = term.getSize()
- return y
- end
- --[=[KEYBOARD FUNCTIONS]=]--
- function cobalt._keypressed( key, keycode )
- cobalt.keyboard.keysdown[key] = true
- cobalt.keyboard.keysdown[keycode] = true
- if cobalt.keypressed then cobalt.keypressed( key, keycode ) end
- end
- function cobalt._keyreleased( key, keycode )
- cobalt.keyboard.keysdown[key] = nil
- cobalt.keyboard.keysdown[keycode] = nil
- if cobalt.keyreleased then cobalt.keyreleased( key, keycode ) end
- end
- function cobalt.keyboard.isDown( key )
- if cobalt.keyboard.keysdown[key] then
- return true
- end
- return false
- end
- --[=[REDNET FUNCTIONS]=]--
- function cobalt.rednet.receive(time, ret)
- end
- --[=[STATE FUNCTIONS]=]--
- function cobalt.getState()
- return cobalt.state
- end
- --[=[FILESYSTEM FUNCTIONS]=]--
- cobalt.filesystem.list = fs.list
- cobalt.filesystem.getDirectoryItems = fs.list
- cobalt.filesystem.isFile = fs.exists
- cobalt.filesystem.isDirectory = fs.isDir
- --cobalt.filesystem.currentDir = shell.dir()
- cobalt.raw = false
- function cobalt.exit()
- cobalt._mainloop = false
- term.setBackgroundColour(colours.black)
- term.setTextColour( colours.white )
- term.clear()
- term.setCursorPos( 1, 1 )
- return
- end
- function cobalt._draw()
- term.setBackgroundColour( cobalt.vars.backgroundcolour )
- term.clear()
- term.setCursorPos( 1, 1 )
- term.setTextColour( cobalt.vars.textcolour )
- cobalt.draw()
- end
- function cobalt.initLoop( runOnce )
- while cobalt._mainloop do
- local e, a, b, c, d, e
- if cobalt.raw then
- e, a, b, c, d, e = os.pullEventRaw()
- else
- e, a, b, c, d, e = os.pullEvent()
- end
- if e == "char" then
- if cobalt.textinput then cobalt.textinput( a ) end
- elseif e == "key" then
- cobalt._keypressed( a, keys.getName( a ) )
- elseif e == "key_up" then
- cobalt._keyreleased( a, keys.getName( a ) )
- elseif e == "mouse_click" then
- if cobalt.mousepressed then cobalt.mousepressed( b, c, a ) end --b, c, a to keep love.mousepressed syntax as( x, y, button ), not ( button, x, y )
- elseif e == "mouse_up" then
- if cobalt.mousereleased then cobalt.mousereleased( b, c, a ) end
- elseif e == "rednet_message" then
- if cobalt.rednetreceive then cobalt.rednetreceive( a, b, c ) end
- elseif e == "monitor_touch" then
- if cobalt.monitortouch then cobalt.monitortouch( x, y ) else cobalt.mousereleased( x, y ) end
- elseif e == "mouse_drag" then
- if cobalt.mousedrag then cobalt.mousedrag( x, y ) end
- elseif e == "timer" then
- if a == cobalt.updatetimer then
- if cobalt.update then cobalt.update( cobalt.updatespeed ) end
- cobalt.updatetimer = os.startTimer( cobalt.updatespeed )
- cobalt._draw()
- end
- end
- if runOnce then cobalt._mainloop = false; return end
- end
- end
- function cobalt.initOnce()
- cobalt.initLoop( true )
- end
- return cobalt
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement