Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- If you're wanting to make an application for
- CCGlass, please read the guide on the forums.
- Every time a developer doesn't read the guide,
- an innocent computer dies
- Update information:
- v0.0002: Adds the Pixel API, aswell as the
- "Garbage Collectors" that set variables
- that are no longer needed at the ends of funct-
- ions to nil.
- ===
- v0.0001
- Initial Release
- CREDITS:
- (MC IGN: Hithere__)Icanbreathecode - Making
- glass
- TheOriginalBIT for kindly making the RGB Color
- converter, and being awesome
- GravityScore for making LuaIDE, which has saved
- me a lot of time.
- The community, for helping me with figuring out
- a lot of stuff about Terminal Glasses.
- Dan200, for making computercraft
- Mikeeemoo for making OpenPeripherals
- --DEVMODE CONFIGURATION
- --If you're just looking at the code, don't touch this
- --Application makers, this is pointless for you too
- --]]
- devmode = false
- newuserdev = false
- --first we set ye color values
- glcolors = {}
- glcolors.red = 0xff3333
- glcolors.blue = 0x7dd2e4
- glcolors.yellow = 0xffff4d
- glcolors.green = 0x4dff4d
- glcolors.gray = 0xe0e0e0
- glcolors.textGray = 0x676767
- glcolors.text = 0x5a5a5
- glcolors.otherBlue = 0x2e679f
- --colors not stolen from Plastic
- --:p
- glcolors.black = 0x000000
- glcolors.purple = 0xff00ff
- glcolors.blueGreen = 0x00ffff
- glcolors.orange = 0xff6600
- glcolors.darkBlue = 0x000066
- glcolors.brown = 0x663300
- glcolors.otherGreen = 0x00ff00
- glcolors.lightOrange = 0xffcc00
- --second, we ensure the user isn't wasting an advanced cpu
- if term.isColor() == true and devmode == false then
- print("Error: You are on an advanced computer. This program will not allow other programs to be ran. Do you wish to continue anyway?(y/n, caps count)")
- answer = read()
- if answer == "n" then
- error("User opted out")
- end
- --garbage collector:
- answer = nil
- end
- function getSide()
- print("Which side is the Terminal Glasses Bridge on?(top bottom left right back, caps count) ")
- side = read()
- sw = fs.open("glassside", "w")
- sw.writeLine(side)
- sw.close()
- print("What is your desired username?")
- username = read()
- sw = fs.open("username", "w")
- sw.writeLine(username)
- sw.close()
- print("Now, if you havn't already, take the terminal glasses you're going to use and right-click the terminal bridge.")
- end
- function loadPixelAPI()
- print("Loading PixelAPI.")
- pixelsOne = {}
- pixelsTwo = {}
- pixelsThree = {}
- pixelsFour = {}
- pixelsFive = {}
- pixelsSix = {}
- pixelsSeven = {}
- pixelsEight = {}
- pixelsNine = {}
- pixelsTen = {}
- oneX, twoX, threeX, fourX, fiveX, sixX, sevenX, eightX, nineX, tenX = 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10
- for i = 1,30 do
- pixelsOne[i] = glass.addBox(oneX, 5, 5, 5, glcolors.red, 0)
- pixelsOne[i].setZIndex(4)
- oneX = oneX + 5
- end
- for i = 1,30 do
- pixelsTwo[i] = glass.addBox(twoX, 10, 5, 5, glcolors.red, 0)
- pixelsTwo[i].setZIndex(4)
- twoX = twoX + 5
- end
- for i = 1,30 do
- pixelsThree[i] = glass.addBox(threeX, 15, 5, 5, glcolors.red, 0)
- pixelsThree[i].setZIndex(4)
- threeX = threeX + 5
- end
- for i = 1,30 do
- pixelsFour[i] = glass.addBox(fourX, 20, 5, 5, glcolors.red, 0)
- pixelsFour[i].setZIndex(4)
- fourX = fourX + 5
- end
- for i = 1,30 do
- pixelsFive[i] = glass.addBox(fiveX, 25, 5, 5, glcolors.red, 0)
- pixelsFive[i].setZIndex(4)
- fiveX = fiveX + 5
- end
- for i = 1,30 do
- pixelsSix[i] = glass.addBox(sixX, 30, 5, 5, glcolors.red, 0)
- pixelsSix[i].setZIndex(4)
- sixX = sixX + 5
- end
- for i = 1,30 do
- pixelsSeven[i] = glass.addBox(sevenX, 35, 5, 5, glcolors.red, 0)
- pixelsSeven[i].setZIndex(4)
- sevenX = sevenX + 5
- end
- for i = 1,30 do
- pixelsEight[i] = glass.addBox(eightX, 40, 5, 5, glcolors.red, 0)
- pixelsEight[i].setZIndex(4)
- eightX = eightX + 5
- end
- for i = 1,30 do
- pixelsNine[i] = glass.addBox(nineX, 45, 5, 5, glcolors.red, 0)
- pixelsNine[i].setZIndex(4)
- nineX = nineX + 5
- end
- for i = 1,30 do
- pixelsTen[i] = glass.addBox(tenX, 50, 5, 5, glcolors.red, 0)
- pixelsTen[i].setZIndex(4)
- tenX = tenX + 5
- end
- --garbage collector:
- i, oneX, twoX, threeX, fourX, fiveX, sixX, sevenX, eightX, nineX, tenX = nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil
- end
- function drawPixel(y, x, color, trans)
- --example usage: 2, 4, colors.red, 1
- --this would make a red pixel appear at 2, 4.
- if y ==1 then
- pixelsOne[x].setColor(color)
- pixelsOne[x].setOpacity(trans)
- elseif y ==2 then
- pixelsTwo[x].setColor(color)
- pixelsTwo[x].setOpacity(trans)
- elseif y ==3 then
- pixelsThree[x].setColor(color)
- pixelsThree[x].setOpacity(trans)
- elseif y ==4 then
- pixelsFour[x].setColor(color)
- pixelsFour[x].setOpacity(trans)
- elseif y ==5 then
- pixelsFive[x].setColor(color)
- pixelsFive[x].setOpacity(trans)
- elseif y ==6 then
- pixelsSix[x].setColor(color)
- pixelsSix[x].setOpacity(trans)
- elseif y ==7 then
- pixelsSeven[x].setColor(color)
- pixelsSeven[x].setOpacity(trans)
- elseif y ==8 then
- pixelsEight[x].setColor(color)
- pixelsEight[x].setOpacity(trans)
- elseif y ==9 then
- pixelsNine[x].setColor(color)
- pixelsNine[x].setOpacity(trans)
- elseif y ==10 then
- pixelsTen[x].setColor(color)
- pixelsTen[x].setOpacity(trans)
- end
- --Garbage Collector:
- x, y, color, trans = nil, nil, nil, nil
- end
- function checkPixelsLoaded()
- if loadedPixels == false then
- loadPixelAPI()
- loadedPixels = true
- --loadedPixels does not need to be trashed.
- end
- end
- function load()
- dir = "CCGlass/"
- glassVersion = "0.0002"
- --note that this still runs on first time
- on = true
- gs = fs.open("glassside", "r")
- side = gs.readLine()
- gs.close()
- glass = peripheral.wrap("left")
- gs = fs.open("username", "r")
- username = gs.readLine()
- gs.close()
- end
- --Ye first thing where we draw stuff
- --(besides the PixelAPI)
- function firstDraw()
- oneText= glass.addText(10, 27.9, " ", glcolors.green)
- twoText= glass.addText(10, 27.9, " ", glcolors.green)
- threeText= glass.addText(10, 27.9, " ", glcolors.green)
- fourText= glass.addText(10, 27.9, " ", glcolors.green)
- fiveText= glass.addText(10, 27.9, " ", glcolors.green)
- midText= glass.addText(29, 27.9, " ", glcolors.green)
- highText= glass.addText(29, 27.9, " ", glcolors.red)
- lowText= glass.addText(29, 27.9, " ", glcolors.otherBlue)
- leftBox = glass.addBox(5, 0, 5, 60, glcolors.blue, 0.75)
- bigBox = glass.addBox(10, 5, 150, 50, glcolors.gray, 0.75)
- --note that the width really is 150
- --add 10 to x cords, 5 to y cords
- for bigWidth = 1, 20 do
- bigBox.setWidth(bigWidth * 7.5)
- sleep(0.01)
- end
- leftBox = glass.addBox(160, 0, 5, 60, glcolors.blue, 0.75)
- --Gargage Collector:
- bigWidth = nil
- end
- --The way glass prints stuffs to the screen
- function midPrint(text)
- midText.setText(text)
- midText.setScale(2)
- midText.setZIndex(5)
- w = bigBox.getWidth()
- tw = midText.getWidth()
- tw = tw*2
- posx = math.floor(w-tw)/2, 2
- posx = posx +10
- midText.setX(posx)
- posy = 20
- midText.setY(posy)
- --Garbage collector:
- w = nil
- tw = nil
- posx = nil
- posy = nil
- end
- function highPrint(text)
- highText.setZIndex(5)
- local w = bigBox.getWidth() --=150
- highText.setText(text)
- tw = highText.getWidth()
- hposx = math.floor(w-tw)/2, 2
- hposx = hposx+10
- highText.setX(hposx)
- posy = 10
- highText.setY(posy)
- --Gargage Collector
- w = nil
- hposx = nil
- posy = nil
- end
- function lowPrint(text)
- local w = bigBox.getWidth()
- lowText.setText(text)
- lowText.setZIndex(5)
- tw = lowText.getWidth()
- posx = math.floor(w-tw)/2, 2
- posx = posx +10
- lowText.setX(posx)
- lowText.setY(40)
- --Gargage Collector
- w = nil
- tw = nil
- posx = nil
- end
- --now we define print functions for books and such
- function tinyPrint(text, line, color)
- local w = bigBox.getWidth()
- if line == 1 then
- oneText.setY(5)
- oneText.setColor(color)
- oneText.setZIndex(5)
- oneText.setText(text)
- elseif line == 2 then
- twoText.setY(15)
- twoText.setColor(color)
- twoText.setZIndex(5)
- twoText.setText(text)
- elseif line == 3 then
- threeText.setY(25)
- threeText.setColor(color)
- threeText.setZIndex(5)
- threeText.setText(text)
- elseif line == 4 then
- fourText.setY(35)
- fourText.setColor(color)
- fourText.setZIndex(5)
- fourText.setText(text)
- elseif line == 5 then
- fiveText.setY(45)
- fiveText.setColor(color)
- fiveText.setZIndex(5)
- fiveText.setText(text)
- end
- --garbage collector
- w = nil
- end
- function tinyClear()
- tinyPrint(" ", 1, glcolors.red)
- tinyPrint(" ", 2, glcolors.red)
- tinyPrint(" ", 3, glcolors.red)
- tinyPrint(" ", 4, glcolors.red)
- tinyPrint(" ", 5, glcolors.red)
- end
- function bigClear()
- highPrint(" ")
- midPrint(" ")
- lowPrint(" ")
- end
- --now we launch apps based on what the user inputs
- function homeScreenLaunch()
- tinyClear()
- evt, cmd = os.pullEvent("chat_command")
- if cmd == "apps" then
- launchApps()
- elseif cmd == "shutdown" then
- on = false
- elseif cmd == "help" then
- shell.run('CCGlass/ccghelp')
- elseif cmd == "easteregg" then
- username = "You have found the easter egg that breaks glass. Congratulations on your find!"
- else
- reprintHome()
- end
- reprintHome()
- --Garbage Collector
- evt = nil
- cmd = nil
- end
- --now we launch 3rd party and default apps
- function launchApps()
- tinyClear()
- highPrint("Launcher v0.001")
- midPrint(" ")
- lowPrint("Usage: $$appname")
- evt, cmd = os.pullEvent("chat_command")
- ok, error = pcall(shell.run("CCGlass/"..cmd.." "))
- we = fs.open("glassErrors", "w")
- we.writeLine(error)
- we.close()
- reprintHome()
- --Garbage Collector
- evt = nil
- cmd = nil
- --we leave ok & error
- end
- --now we can reprint the homescreen
- function reprintHome()
- tinyClear()
- highPrint("Welcome, "..username.."!")
- midPrint("V"..glassVersion.."")
- lowPrint("Do $$help for help.")
- end
- --firsttime?
- if fs.exists("glassside") == false or newuserdev == true then
- getSide()
- end
- --Will add later. :3
- function bookprint()
- end
- --this function was kindly created by TheOriginalBIT
- --who is also awesome.
- function rgbColor( _r, _g, _b )
- return bit.bor( bit.blshift( bit.bor( bit.blshift( _r, 8 ), _g ), 8 ), _b )
- end
- --[[begin execution]]
- load()
- firstDraw()
- reprintHome()
- while on == true do
- homeScreenLaunch()
- end
- glass.clear()
Advertisement
Add Comment
Please, Sign In to add comment