Advertisement
Redxone

CC: GameOfLife - Installer

Feb 21st, 2016
332
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.00 KB | None | 0 0
  1. --]] Game of life PRO installer by Lewisk3 [[--
  2. scp = term.setCursorPos
  3. stc = term.setTextColor
  4. sbc = term.setBackgroundColor
  5. local w,h = term.getSize()
  6. local dxoff = 0
  7. local dyoff = 0
  8. local function drawTopBar()
  9.     scp(6,1)
  10.     sbc(colors.gray)
  11.     term.clearLine()
  12.     write("(c)Lewisk's Game of life Pro, Installer.")
  13. end
  14. local function fade(d,speed)
  15.     local fadecolors = {'black','gray','lightGray','white'}
  16.     if(d == true)then
  17.         -- fade in
  18.         for i = 1, #fadecolors do
  19.             sbc(colors[fadecolors[i]])
  20.             term.clear()
  21.             sleep(speed)
  22.         end
  23.     else
  24.         -- fade out
  25.         for i = #fadecolors, 1, -1 do
  26.             sbc(colors[fadecolors[i]])
  27.             term.clear()
  28.             sleep(speed)
  29.         end
  30.     end
  31. end
  32. fade(true,0.1)
  33. fade(false,0.2)
  34. local function drawMenu(offin,bcolor,txt)
  35.     if(offin)then
  36.         paintutils.drawFilledBox(dxoff,2,dxoff+30,19,colors.black)
  37.         dxoff = -10
  38.         for i = 0, 10 do
  39.             term.current().setVisible(true)
  40.             paintutils.drawFilledBox(dxoff,2,dxoff+30,19,colors.lightGray)
  41.             paintutils.drawFilledBox(dxoff,2,dxoff+30,4,bcolor)
  42.             term.current().setVisible(false)
  43.             sleep(0.1)
  44.             paintutils.drawFilledBox(dxoff,2,dxoff+30,19,colors.black)
  45.             dxoff = dxoff + 1
  46.         end
  47.             term.current().setVisible(true)
  48.             paintutils.drawFilledBox(dxoff,2,dxoff+30,19,colors.lightGray)
  49.             paintutils.drawFilledBox(1,2,dxoff+30,4,bcolor)
  50.             sbc(bcolor)
  51.             scp( ( (dxoff+30)/2 ) - #txt/2 ,3)
  52.             write(txt)
  53.             sbc(colors.lightGray)
  54.     else
  55.         paintutils.drawFilledBox(dxoff,2,dxoff+30,19,colors.black)
  56.         dxoff = 10
  57.         for i = 0, 10 do
  58.             term.current().setVisible(true)
  59.             paintutils.drawFilledBox(1,2,dxoff+dxoff*3,19,colors.lightGray)
  60.             paintutils.drawFilledBox(1,2,dxoff+dxoff*3,4,bcolor)
  61.             term.current().setVisible(false)
  62.             sleep(0.1)
  63.             paintutils.drawFilledBox(1,2,dxoff+dxoff*3,19,colors.black)
  64.             dxoff = dxoff - 1
  65.         end
  66.             term.current().setVisible(true)
  67.             paintutils.drawFilledBox(dxoff,2,dxoff+dxoff*3,19,colors.black)
  68.     end
  69. end
  70. local function openMenu(moptions,dx,dy,startselected)
  71.     local sop = startselected
  72.     local active = true
  73.     local function draw()
  74.             for i = 1, #moptions do
  75.                 scp(dx,dy+(i-1))
  76.                 if(sop == i)then
  77.                     write('[ ' .. moptions[i] .. ' ]')
  78.                 else
  79.                     write('  ' .. moptions[i] .. '  ')
  80.                 end
  81.             end
  82.     end
  83.     local function update()
  84.         draw()
  85.         while active do
  86.             ev = {os.pullEvent()}
  87.             if(ev[1] == 'key')then
  88.                 if(ev[2] == keys.up and sop > 1)then sop = sop - 1 end
  89.                 if(ev[2] == keys.down and sop < #moptions)then sop = sop + 1 end
  90.                 draw()
  91.                 if(ev[2] == keys.enter)then active = false return sop end
  92.             end
  93.         end
  94.     end
  95.     return update()
  96. end
  97. local function start()
  98.     drawTopBar()
  99.     drawMenu(true,colors.green,"Install Options.")
  100.     sbc(colors.lightGray)
  101.     scp(1,5)
  102.     write("Use arrows to select.")
  103.     scp(1,6)
  104.     write("Press enter to confirm.")
  105.     local result = openMenu({'Install Full',"Install Grid",'Exit Install'},4,8,1)
  106.     if(result == 3)then sbc(colors.black) stc(colors.white) scp(1,1) term.clear() return false end
  107.     if(result == 1)then
  108.         drawMenu(false,colors.green)
  109.         drawMenu(true,colors.blue,"Install To?")
  110.         scp(5,5)
  111.         write("Location: ")
  112.         scp(5,6)
  113.         sbc(colors.gray)
  114.         write(string.rep(" ",15))
  115.         scp(5,6)
  116.         local loc = read()
  117.         scp(5,9)
  118.         sbc(colors.lightGray)
  119.         write("Install to: " .. loc .. " ?")
  120.         result = openMenu({'Yeah','Nope'},10,10,1)
  121.         if(result == 1)then
  122.             if(not http)then
  123.                 scp(1,11)
  124.                 write("HTTP is disabled!, please enable.")
  125.                 scp(1,12)
  126.                 write("Press any key.")
  127.                 os.pullEvent("key")
  128.                 drawMenu(false,colors.blue)
  129.                 start()    
  130.             else
  131.                 scp(1,11)
  132.                 write("Fetching file(s)..")
  133.                 local gridcont = http.get("http://pastebin.com/raw/QEXpahe1")
  134.                 local gamecont = http.get("http://pastebin.com/raw/R3HfhA4x")
  135.                 if(gridcont == nil or gamecont == nil)then
  136.                     scp(1,11)
  137.                     write("Failed to download file.")
  138.                     scp(1,12)
  139.                     write("Press any key.")
  140.                     os.pullEvent("key")
  141.                     drawMenu(false,colors.blue)
  142.                     start()
  143.                 else
  144.                     gridcont=gridcont.readAll()
  145.                     gamecont=gamecont.readAll()
  146.                     if(not fs.isDir(shell.resolve(loc)))then
  147.                         fs.makeDir(shell.resolve(loc))
  148.                     end
  149.                     f = fs.open(shell.resolve(loc) .. "/grid", "w")
  150.                     f.write(gridcont)
  151.                     f.close()
  152.                     scp(1,12)
  153.                     write("Grid installed to: " .. shell.resolve(loc))
  154.                     f = fs.open(shell.resolve(loc) .. "/gameoflife", "w")
  155.                     f.write(gamecont)
  156.                     f.close()
  157.                     scp(1,13)
  158.                     write("Game installed to: " .. shell.resolve(loc))
  159.                     scp(1,14)
  160.                     write("Press any key.")
  161.                     os.pullEvent("key")
  162.                     drawMenu(false,colors.blue)
  163.                     start()
  164.                 end
  165.             end
  166.         elseif(result == 2)then
  167.             drawMenu(false,colors.blue)
  168.             start()
  169.         end
  170.     elseif(result == 2)then
  171.         drawMenu(false,colors.green)
  172.         drawMenu(true,colors.blue,"Install Grid To?")
  173.         scp(5,5)
  174.         write("Location: ")
  175.         scp(5,6)
  176.         sbc(colors.gray)
  177.         write(string.rep(" ",15))
  178.         scp(5,6)
  179.         local loc = read()
  180.         scp(5,9)
  181.         sbc(colors.lightGray)
  182.         write("Install Grid to: " .. loc .. " ?")
  183.         result = openMenu({'Yeah','Nope'},10,10,1) 
  184.         if(result == 1)then
  185.             if(not http)then
  186.                 scp(1,11)
  187.                 write("HTTP is disabled!, please enable.")
  188.                 scp(1,12)
  189.                 write("Press any key.")
  190.                 os.pullEvent("key")
  191.                 drawMenu(false,colors.blue)
  192.                 start()    
  193.             else
  194.                 scp(1,11)
  195.                 write("Fetching file..")
  196.                 local cont = http.get("http://pastebin.com/raw/QEXpahe1")
  197.                 if(cont == nil)then
  198.                     scp(1,11)
  199.                     write("Failed to download file.")
  200.                     scp(1,12)
  201.                     write("Press any key.")
  202.                     os.pullEvent("key")
  203.                     drawMenu(false,colors.blue)
  204.                     start()
  205.                 else
  206.                     cont=cont.readAll()
  207.                     if(not fs.isDir(shell.resolve(loc)))then
  208.                         fs.makeDir(shell.resolve(loc))
  209.                     end
  210.                     f = fs.open(shell.resolve(loc) .. "/grid", "w")
  211.                     f.write(cont)
  212.                     f.close()
  213.                     write("Grid install to: " .. shell.resolve(loc))
  214.                     scp(1,12)
  215.                     write("Press any key.")
  216.                     os.pullEvent("key")
  217.                     drawMenu(false,colors.blue)
  218.                     start()
  219.                 end
  220.             end
  221.         elseif(result == 2)then
  222.             drawMenu(false,colors.blue)
  223.             start()
  224.         end
  225.     end
  226. end
  227. start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement