5bitesofcookies

CCGlass V0.0002

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