5bitesofcookies

Glass V0.2.1

Jul 16th, 2013
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 11.48 KB | None | 0 0
  1. --[[
  2. If you're wanting to make an application for
  3. CCGlass, please read the guide on the forums.
  4. Every time a developer doesn't read the guide,
  5. an innocent computer dies
  6.  
  7. Update information:
  8. ===
  9. v0.2.1: Fixes the glitch where the terminal
  10. would always need to be on the left side, no
  11. matter what.
  12. Adds pixeClear(), which clears the pixels on
  13. the pixelAPI.
  14. Redid the versioning system to a more popular
  15. way of versioning applications.
  16. ===
  17. v0.2.0: Adds the Pixel API, aswell as the
  18. "Garbage Collectors" that set variables
  19. that are no longer needed at the ends of funct-
  20. ions to nil.
  21. ===
  22. v0.1.0
  23. Initial Release
  24.  
  25.  
  26.  
  27.  
  28. CREDITS:
  29. (MC IGN: Hithere__)Icanbreathecode - Making
  30. glass
  31. TheOriginalBIT for kindly making the RGB Color
  32. converter, and being awesome
  33. GravityScore for making LuaIDE, which has saved
  34. me a lot of time.
  35. The community, for helping me with figuring out
  36. a lot of stuff about Terminal Glasses.
  37. Dan200, for making computercraft
  38. Mikeemoo for making OpenPeripherals
  39. --DEVMODE CONFIGURATION
  40. --If you're just looking at the code, don't touch this
  41. --Application makers, this is pointless for you too
  42. --]]
  43. devmode = true
  44. newuserdev = false
  45. --first we set ye color values
  46. glcolors = {}
  47.             glcolors.red = 0xff3333
  48.             glcolors.blue = 0x7dd2e4
  49.             glcolors.yellow = 0xffff4d
  50.             glcolors.green = 0x4dff4d
  51.             glcolors.gray = 0xe0e0e0
  52.             glcolors.textGray = 0x676767
  53.             glcolors.text = 0x5a5a5
  54.             glcolors.otherBlue = 0x2e679f
  55.             --colors not stolen from Plastic
  56.             --:p
  57.             glcolors.black = 0x000000
  58.             glcolors.purple = 0xff00ff
  59.             glcolors.blueGreen = 0x00ffff
  60.             glcolors.orange = 0xff6600
  61.             glcolors.darkBlue = 0x000066
  62.             glcolors.brown = 0x663300
  63.             glcolors.otherGreen = 0x00ff00
  64.             glcolors.lightOrange = 0xffcc00
  65. --second, we ensure the user isn't wasting an advanced cpu
  66. if term.isColor() == true and devmode == false then
  67.   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)")
  68.   answer = read()
  69.   if answer == "n" then
  70.     error("User opted out")
  71.   end
  72.   --garbage collector:
  73.   answer = nil
  74. end
  75. function getSide()
  76.   print("Which side is the Terminal Glasses Bridge on?(top bottom left right back, caps count) ")
  77.   side = read()
  78.   sw = fs.open("glassside", "w")
  79.   sw.writeLine(side)
  80.   sw.close()
  81.   print("What is your desired username?")
  82.   username = read()
  83.   sw = fs.open("username", "w")
  84.   sw.writeLine(username)
  85.   sw.close()
  86.   print("Now, if you havn't already, take the terminal glasses you're going to use and right-click the terminal bridge.")
  87. end
  88. function loadPixelAPI()
  89.   print("Loading PixelAPI.")
  90.   pixelsOne = {}
  91.   pixelsTwo = {}
  92.   pixelsThree = {}
  93.   pixelsFour = {}
  94.   pixelsFive = {}
  95.   pixelsSix = {}
  96.   pixelsSeven = {}
  97.   pixelsEight = {}
  98.   pixelsNine = {}
  99.   pixelsTen = {}
  100.   oneX, twoX, threeX, fourX, fiveX, sixX, sevenX, eightX, nineX, tenX = 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10
  101.   for i = 1,30 do
  102.     pixelsOne[i] = glass.addBox(oneX, 5, 5, 5, glcolors.red, 0)
  103.     pixelsOne[i].setZIndex(4)
  104.     oneX = oneX + 5
  105.   end
  106.   for i = 1,30 do
  107.     pixelsTwo[i] = glass.addBox(twoX, 10, 5, 5, glcolors.red, 0)
  108.     pixelsTwo[i].setZIndex(4)
  109.     twoX = twoX + 5
  110.   end
  111.   for i = 1,30 do
  112.     pixelsThree[i] = glass.addBox(threeX, 15, 5, 5, glcolors.red, 0)
  113.     pixelsThree[i].setZIndex(4)
  114.     threeX = threeX + 5
  115.   end
  116.   for i = 1,30 do
  117.     pixelsFour[i] = glass.addBox(fourX, 20, 5, 5, glcolors.red, 0)
  118.     pixelsFour[i].setZIndex(4)
  119.     fourX = fourX + 5
  120.   end
  121.   for i = 1,30 do
  122.     pixelsFive[i] = glass.addBox(fiveX, 25, 5, 5, glcolors.red, 0)
  123.     pixelsFive[i].setZIndex(4)
  124.     fiveX = fiveX + 5
  125.   end
  126.   for i = 1,30 do
  127.     pixelsSix[i] = glass.addBox(sixX, 30, 5, 5, glcolors.red, 0)
  128.     pixelsSix[i].setZIndex(4)
  129.     sixX = sixX + 5
  130.   end
  131.   for i = 1,30 do
  132.     pixelsSeven[i] = glass.addBox(sevenX, 35, 5, 5, glcolors.red, 0)
  133.     pixelsSeven[i].setZIndex(4)
  134.     sevenX = sevenX + 5
  135.   end
  136.   for i = 1,30 do
  137.     pixelsEight[i] = glass.addBox(eightX, 40, 5, 5, glcolors.red, 0)
  138.     pixelsEight[i].setZIndex(4)
  139.     eightX = eightX + 5
  140.   end
  141.   for i = 1,30 do
  142.     pixelsNine[i] = glass.addBox(nineX, 45, 5, 5, glcolors.red, 0)
  143.     pixelsNine[i].setZIndex(4)
  144.     nineX = nineX + 5
  145.   end
  146.   for i = 1,30 do
  147.     pixelsTen[i] = glass.addBox(tenX, 50, 5, 5, glcolors.red, 0)
  148.     pixelsTen[i].setZIndex(4)
  149.     tenX = tenX + 5
  150.   end
  151.   --garbage collector:
  152.   i, oneX, twoX, threeX, fourX, fiveX, sixX, sevenX, eightX, nineX, tenX = nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil
  153. end
  154. function drawPixel(y, x, color, trans)
  155.   --example usage: 2, 4, colors.red, 1
  156.   --this would make a red pixel appear at 2, 4.
  157.   if y ==1 then
  158.     pixelsOne[x].setColor(color)
  159.     pixelsOne[x].setOpacity(trans)
  160.   elseif y ==2 then
  161.     pixelsTwo[x].setColor(color)
  162.     pixelsTwo[x].setOpacity(trans)
  163.   elseif y ==3 then
  164.     pixelsThree[x].setColor(color)
  165.     pixelsThree[x].setOpacity(trans)
  166.   elseif y ==4 then
  167.     pixelsFour[x].setColor(color)
  168.     pixelsFour[x].setOpacity(trans)
  169.   elseif y ==5 then
  170.     pixelsFive[x].setColor(color)
  171.     pixelsFive[x].setOpacity(trans)
  172.   elseif y ==6 then
  173.     pixelsSix[x].setColor(color)
  174.     pixelsSix[x].setOpacity(trans)
  175.   elseif y ==7 then
  176.     pixelsSeven[x].setColor(color)
  177.     pixelsSeven[x].setOpacity(trans)
  178.   elseif y ==8 then
  179.     pixelsEight[x].setColor(color)
  180.     pixelsEight[x].setOpacity(trans)
  181.   elseif y ==9 then
  182.     pixelsNine[x].setColor(color)
  183.     pixelsNine[x].setOpacity(trans)
  184.   elseif y ==10 then
  185.     pixelsTen[x].setColor(color)
  186.     pixelsTen[x].setOpacity(trans)
  187.   end
  188.   --Garbage Collector:
  189.   x, y, color, trans = nil, nil, nil, nil
  190. end
  191. function pixelClear()
  192.   for i = 1,30 do
  193.       drawPixel(i,1,glcolors.red,0)
  194.   end
  195.   for i = 1,30 do
  196.       drawPixel(i,2,glcolors.red,0)
  197.   end
  198.   for i = 1,30 do
  199.       drawPixel(i,3,glcolors.red,0)
  200.   end
  201.   for i = 1,30 do
  202.       drawPixel(i,4,glcolors.red,0)
  203.   end
  204.   for i = 1,30 do
  205.       drawPixel(i,5,glcolors.red,0)
  206.   end
  207.   for i = 1,30 do
  208.       drawPixel(i,6,glcolors.red,0)
  209.   end
  210.   for i = 1,30 do
  211.       drawPixel(i,7,glcolors.red,0)
  212.   end
  213.   for i = 1,30 do
  214.       drawPixel(i,8,glcolors.red,0)
  215.   end
  216.   for i = 1,30 do
  217.       drawPixel(i,9,glcolors.red,0)
  218.   end
  219.   for i = 1,30 do
  220.       drawPixel(i,10,glcolors.red,0)
  221.   end
  222. end
  223. function checkPixelsLoaded()
  224.   if loadedPixels == false then
  225.      loadPixelAPI()
  226.      loadedPixels = true
  227.      --loadedPixels does not need to be trashed.
  228.   end
  229. end
  230. function load()
  231.   dir = "CCGlass/"
  232.   glassVersion = "0.2.1"
  233.   --note that this still runs on first time
  234.   on = true
  235.   gs = fs.open("glassside", "r")
  236.   side = gs.readLine()
  237.   gs.close()
  238.   glass = peripheral.wrap(side)
  239.   gs = fs.open("username", "r")
  240.   username = gs.readLine()
  241.   gs.close()
  242. end
  243. --Ye first thing where we draw stuff
  244. --(besides the PixelAPI)
  245. function firstDraw()
  246.   oneText= glass.addText(10, 27.9, " ", glcolors.green)
  247.   twoText= glass.addText(10, 27.9, " ", glcolors.green)
  248.   threeText= glass.addText(10, 27.9, " ", glcolors.green)
  249.   fourText= glass.addText(10, 27.9, " ", glcolors.green)
  250.   fiveText= glass.addText(10, 27.9, " ", glcolors.green)
  251.   midText= glass.addText(29, 27.9, " ", glcolors.green)
  252.   highText= glass.addText(29, 27.9, " ", glcolors.red)
  253.   lowText= glass.addText(29, 27.9, " ", glcolors.otherBlue)
  254.   leftBox = glass.addBox(5, 0, 5, 60, glcolors.blue, 0.75)
  255.   bigBox = glass.addBox(10, 5, 150, 50, glcolors.gray, 0.75)
  256.   --note that the width really is 150
  257.   --add 10 to x cords, 5 to y cords
  258.   for bigWidth = 1, 20 do
  259.     bigBox.setWidth(bigWidth * 7.5)
  260.     sleep(0.01)
  261.   end
  262.   leftBox = glass.addBox(160, 0, 5, 60, glcolors.blue, 0.75)
  263.   --Gargage Collector:
  264.   bigWidth = nil
  265. end
  266. --The way glass prints stuffs to the screen
  267. function midPrint(text)
  268.   midText.setText(text)
  269.   midText.setScale(2)
  270.   midText.setZIndex(5)
  271.   w = bigBox.getWidth()
  272.   tw = midText.getWidth()
  273.   tw = tw*2
  274.   posx = math.floor(w-tw)/2, 2
  275.   posx = posx +10
  276.   midText.setX(posx)
  277.   posy = 20
  278.   midText.setY(posy)
  279. --Garbage collector:
  280. w = nil
  281. tw = nil
  282. posx = nil
  283. posy = nil
  284. end
  285. function highPrint(text)
  286.   highText.setZIndex(5)
  287.     local w = bigBox.getWidth() --=150
  288.     highText.setText(text)
  289.     tw = highText.getWidth()
  290.   hposx = math.floor(w-tw)/2, 2
  291.   hposx = hposx+10
  292.   highText.setX(hposx)
  293.   posy = 10
  294.   highText.setY(posy)
  295.   --Gargage Collector
  296.   w = nil
  297.   hposx = nil
  298.   posy = nil
  299. end
  300. function lowPrint(text)
  301.     local w = bigBox.getWidth()
  302.   lowText.setText(text)
  303.   lowText.setZIndex(5)
  304.   tw = lowText.getWidth()
  305.   posx = math.floor(w-tw)/2, 2
  306.   posx = posx +10
  307.   lowText.setX(posx)
  308.   lowText.setY(40)
  309.   --Gargage Collector
  310.   w = nil
  311.   tw = nil
  312.   posx = nil
  313. end
  314. --now we define print functions for books and such
  315. function tinyPrint(text, line, color)
  316.   local w = bigBox.getWidth()
  317.   if line == 1 then
  318.     oneText.setY(5)
  319.     oneText.setColor(color)
  320.     oneText.setZIndex(5)
  321.     oneText.setText(text)
  322.     elseif line == 2 then
  323.     twoText.setY(15)
  324.     twoText.setColor(color)
  325.     twoText.setZIndex(5)
  326.     twoText.setText(text)
  327.     elseif line == 3 then
  328.     threeText.setY(25)
  329.     threeText.setColor(color)
  330.     threeText.setZIndex(5)
  331.     threeText.setText(text)
  332.     elseif line == 4 then
  333.     fourText.setY(35)
  334.     fourText.setColor(color)
  335.     fourText.setZIndex(5)
  336.     fourText.setText(text)
  337.     elseif line == 5 then
  338.     fiveText.setY(45)
  339.     fiveText.setColor(color)
  340.     fiveText.setZIndex(5)
  341.     fiveText.setText(text)
  342.   end
  343.   --garbage collector
  344.   w = nil
  345. end
  346. function tinyClear()
  347. tinyPrint(" ", 1, glcolors.red)
  348. tinyPrint(" ", 2, glcolors.red)
  349. tinyPrint(" ", 3, glcolors.red)
  350. tinyPrint(" ", 4, glcolors.red)
  351. tinyPrint(" ", 5, glcolors.red)
  352. end
  353. function bigClear()
  354.   highPrint(" ")
  355.   midPrint(" ")
  356.   lowPrint(" ")
  357. end
  358. --now we launch apps based on what the user inputs
  359. function homeScreenLaunch()
  360.   tinyClear()
  361.   evt, cmd = os.pullEvent("chat_command")
  362.   if cmd == "apps" then
  363.     launchApps()
  364.   elseif cmd == "shutdown" then
  365.     on = false
  366.   elseif cmd == "help" then
  367.     shell.run('CCGlass/ccghelp')
  368.   elseif cmd == "easteregg" then
  369.     username = "You have found the easter egg that breaks glass. Congratulations on your find!"
  370.     else
  371.     reprintHome()
  372.   end
  373.   reprintHome()
  374.   --Garbage Collector
  375.   evt = nil
  376.   cmd = nil
  377. end
  378. --now we launch 3rd party and default apps
  379. function launchApps()
  380.   tinyClear()
  381.   highPrint("Launcher v0.001")
  382.   midPrint(" ")
  383.   lowPrint("Usage: $$appname")
  384.   evt, cmd = os.pullEvent("chat_command")
  385.   ok, error = pcall(shell.run("CCGlass/"..cmd.." "))
  386.   we = fs.open("glassErrors", "w")
  387.   we.writeLine(error)
  388.   we.close()
  389.   reprintHome()
  390.   --Garbage Collector
  391.   evt = nil
  392.   cmd = nil
  393.   --we leave ok & error
  394. end
  395. --now we can reprint the homescreen
  396. function reprintHome()
  397.   tinyClear()
  398.   highPrint("Welcome, "..username.."!")
  399.   midPrint("V"..glassVersion.."")
  400.   lowPrint("Do $$help for help.")
  401. end
  402. --firsttime?
  403. if fs.exists("glassside") == false or newuserdev == true then
  404.   getSide()
  405. end
  406. --Will add later. :3
  407. function bookprint()
  408. end
  409. --this function was kindly created by TheOriginalBIT
  410. --who is also awesome.
  411. function rgbColor( _r, _g, _b )
  412.   return bit.bor( bit.blshift( bit.bor( bit.blshift( _r, 8 ), _g ), 8 ), _b )
  413. end
  414. --[[begin execution]]
  415. load()
  416. firstDraw()
  417. reprintHome()
  418. while on == true do
  419.   homeScreenLaunch()
  420. end
  421. glass.clear()
Advertisement
Add Comment
Please, Sign In to add comment