Shnupbups

ComputerCraft CCScreensaver 1.1

Mar 9th, 2013
367
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 11.27 KB | None | 0 0
  1. args = {...}
  2. term.clear()
  3. term.setCursorPos(1,1)
  4. local version = "CCScreensaver Beta 1.1"
  5. local changelog = {
  6. "Added a config (shnupProgFiles/screensaver/config.cfg)",
  7. "Added 6 screensaver types",
  8. "Added a new error screen",
  9. "Edited the credits ("..shell.getRunningProgram().." -credits)",
  10. "Added -resetConfig, -changelog and -r parameters",
  11. "Fixed bugs 1, 2 and 3",
  12. "For more details, see the forum post here:",
  13. "http://www.computercraft.info/forums2/index.php?/topic/10438-ccscreensaver-beta-10-11-release-date-announced",
  14. }
  15. if not fs.exists("shnupProgFiles") then
  16.   if not http then
  17.    print("Sorry, http must be enabled to download the files. Enable in CC's config.")
  18.    return
  19.  end
  20.  print("Since this is your first time using the program, it will download the necessary files. This may take a short while.")
  21.  fs.makeDir("shnupProgFiles")
  22. end
  23. if not fs.exists("shnupProgFiles/apis") then
  24.  fs.makeDir("shnupProgFiles/apis")
  25. end
  26. if not fs.exists("shnupProgFiles/apis/dl") then
  27.  write("Downloading: shnupProgFiles/apis/dl...")
  28.  local dl = http.request("http://pastebin.com/raw?i=mSP4wJV4")
  29.  while true do
  30.   local event,url,text = os.pullEvent()
  31.   if event == "http_success" then
  32.    f = fs.open("shnupProgFiles/apis/dl","w")
  33.    f.write(text.readAll())
  34.    f.close()
  35.    print(" Done!")
  36.    break
  37.   elseif event == "http_failure" then
  38.    error("Failed to download file: dl API")
  39.   end
  40.  end
  41. end
  42. os.loadAPI("shnupProgFiles/apis/dl")
  43. if not fs.exists("shnupProgFiles/screensaver") then
  44.  fs.makeDir("shnupProgFiles/screensaver")
  45. end
  46. if not fs.exists("shnupProgFiles/screensaver/apis") then
  47.  fs.makeDir("shnupProgFiles/screensaver/apis")
  48. end
  49. if not fs.exists("shnupProgFiles/screensaver/.secret") then
  50.  fs.makeDir("shnupProgFiles/screensaver/.secret")
  51. end
  52. if not fs.exists("shnupProgFiles/screensaver/pictures") then
  53.  fs.makeDir("shnupProgFiles/screensaver/pictures")
  54. end
  55. if not fs.exists("shnupProgFiles/screensaver/apis/CConfig") then
  56.  dl.httpDownload("http://pastebin.com/raw?i=iMpzmDWt","shnupProgFiles/screensaver/apis/CConfig")
  57. end
  58. os.loadAPI("shnupProgFiles/screensaver/apis/CConfig")
  59. if not fs.exists("shnupProgFiles/apis/byte") then
  60.  dl.httpDownload("http://pastebin.com/raw?i=ynaCiE75","shnupProgFiles/apis/byte")
  61. end
  62. os.loadAPI("shnupProgFiles/apis/byte")
  63. if not fs.exists("shnupProgFiles/screensaver/.secret/pbjt") then
  64.  dl.httpDownload("http://pastebin.com/raw?i=F1X1VmFJ","shnupProgFiles/screensaver/.secret/pbjt","REDACTED")
  65. end
  66. if not fs.exists("shnupProgFiles/screensaver/pictures/flower") then
  67.  dl.httpDownload("http://pastebin.com/raw?i=9CSDMhuB","shnupProgFiles/screensaver/pictures/flower")
  68. end
  69. if not fs.exists("shnupProgFiles/screensaver/pictures/hello") then
  70.  dl.httpDownload("http://pastebin.com/raw?i=Hu2iJQs8","shnupProgFiles/screensaver/pictures/hello")
  71. end
  72. local config = CConfig.new("shnupProgFiles/screensaver/config.cfg")
  73. config:load()
  74. scrnsvrID = config:getNumber("screensaver",0)
  75. config:addCommentForKey("screensaver","What screensaver to use?")
  76. config:addRestrictionForKey("screensaver","0 = words, 1 = indie letters, 2 = random letters, 3 = pixels, 4 = lines, 5 = slideshow 6 = scrapbook")
  77. wait = config:getNumber("waitBetweenPrints",0.005)
  78. config:addCommentForKey("waitBetweenPrints","How many seconds to wait before printing the next word/pixel/whatever")
  79. isRandCol = config:getBoolean("randomColour","true")
  80. config:addCommentForKey("randomColour","Is colour randomly picked each time it prints?")
  81. col = config:getColour("colourToUse",colours.white)
  82. config:addCommentForKey("colourToUse","If colour is not random, what colour should it use?")
  83. picDir = config:getString("slideshowDir","shnupProgFiles/screensaver/pictures")
  84. config:addCommentForKey("slideshowDir","If the slideshow or scrapbook screensaver is selected, where is the folder with the pictures?")
  85. config:save()
  86. term.clear()
  87. term.setCursorPos(1,1)
  88. if args[1] then
  89.  local arg1 = string.lower(args[1])
  90.  if arg1 == "-resetconfig" then
  91.   config:reset()
  92.   config:save()
  93.   print("Config reset successfully")
  94.   return
  95.  elseif arg1 == "-credits" then
  96.   term.setCursorPos(1,1)
  97.   print("Coded by: Shnupbups100")
  98.   print("Code originally by: Kingdaro")
  99.   print("FORUMS post wIth idea: Cranium")
  100.   print("LOVElY mOd by: Dan200 and Cloudy")
  101.   print("Under the hood AND CConfig etc.: TheOriginalBIT")
  102.   print("(yes, there's a hidden message in there)")
  103.   return
  104.  elseif arg1 == "-changelog" then
  105.   term.setCursorPos(1,1)
  106.   for i = 1,#changelog do
  107.    print(changelog[i])
  108.   end
  109.   return
  110.  elseif arg1 == "-u" then
  111.   upper = true
  112.  elseif arg1 == "-l" then
  113.   lower = true
  114.  elseif arg1 == "-r" then
  115.   rand = true
  116.  end
  117. end
  118. if not args[1] and (scrnsvrID == 0 or scrnsvrID == 1) or args[1] and ((scrnsvrID == 2 and upper == false and lower == false and rand == false) or scrnsvrID == 3 or scrnsvrID == 4 or scrnsvrID == 5) then
  119.  local w,h = term.getSize()
  120.  print(string.rep("-",w))
  121.  term.setCursorPos(w*.5-string.len(version)*.5+1,1)
  122.  print(version)
  123.  print("Usage: ")
  124.  print("While in word or indie letters mode: "..shell.getRunningProgram().." <text> [text] [text] etc.")
  125.  print("While in random letters, lines, slideshow, pixels or scrapbook mode: "..shell.getRunningProgram())
  126.  write("Random Fact Thing: ")
  127.  local facts = {
  128.   "Try using -u, -l or -r instead of the first '<text>' in word/indie letters mode!",
  129.   "Try the program secret/alongtimeago!",
  130.   "Try putting a (regular) monitor and a wither skeleton skull in a crafting bench!",
  131.   "Try erroring this program again like this for more fact things! Collect them all! [/marketingCampain]",
  132.   "These fact things are an easter egg of this program! Shhh! Try to find the one in screensaver -credits!",
  133.   "Pumpkins make good headgear, no annoying angry endermen!",
  134.   "This program has quite a few secrets... this being one of them.",
  135.   "I'm getting bored of typing these",
  136.   "Thnx TheOriginalBIT for stuffs!",
  137.   "To quickly reset the config, use "..shell.getRunningProgram().." -resetconfig",
  138.   "This is the longest fact out of all the facts in the facts table I have written that contains facts because it is very very very long.",
  139.   "There is a hidden folder in shnupProgFiles/screensaver...",
  140.   "The config is found at shnupProgFiles/screensaver/config.cfg",
  141.   "There are 14 random fact things in total.",
  142.   "This fact thing will never show up. Minecraft has a splash screen like this in its .jar.",
  143.  }
  144.  print(facts[math.random(1,#facts-1)])
  145.  print(string.rep("-",w))
  146.  return
  147. end
  148. numb1 = 1
  149. numb2 = 0
  150. lower = false
  151. upper = false
  152. while args[numb1] ~= nil do
  153.  if args[numb1] == "-u" and lower ~= true and rand ~= true then
  154.   upper = true
  155.  elseif args[numb1] == "-l" and upper ~= true and rand ~= true then
  156.   lower = true
  157.  elseif args[numb1] == "-r" and lower ~= true and upper ~= true then
  158.   rand = true
  159.  else
  160.   numb2 = numb2 + string.len(args[numb1]) - 1
  161.  end
  162.  numb1 = numb1 + 1
  163. end
  164. numb3 = 1
  165. used = false
  166. l = {""}
  167. local function screensaver()
  168.  local w,h = term.getSize()
  169.  if scrnsvrID ~= 1 then
  170.   local picx = math.random(w)
  171.   local picy = math.random(h)
  172.   term.setCursorPos(math.random(w-numb2),math.random(h))
  173.  else
  174.   term.setCursorPos(math.random(w),math.random(h))
  175.  end
  176.  if isRandCol == true and (scrnsvrID == 0 or scrnsvrID == 1 or scrnsvrID == 2) then
  177.   term.setTextColour(2^math.random(14))
  178.  elseif isRandCol == false and (scrnsvrID == 0 or scrnsvrID == 1 or scrnsvrID == 2) then
  179.   term.setTextColour(col)
  180.  elseif isRandCol == true and (scrnsvrID == 3 or scrnsvrID == 4) then
  181.   term.setBackgroundColour(2^math.random(14))
  182.  elseif isRandCol == false and (scrnsvrID == 3 or scrnsvrID == 4) then
  183.   term.setBackgroundColour(col)
  184.  end
  185.  if scrnsvrID == 0 then
  186.   while args[numb3] ~= nil do
  187.    if args[numb3] ~= "-u" and args[numb3] ~= "-l" and args[numb3] ~= "-r" then
  188.     if upper == true then
  189.      args[numb3] = string.upper(args[numb3])
  190.     elseif lower == true then
  191.      args[numb3] = string.lower(args[numb3])
  192.     elseif rand == true then
  193.      local randChance = math.random(2)
  194.      if randChance == 1 then
  195.       args[numb3] = string.upper(args[numb3])
  196.      else
  197.       args[numb3] = string.lower(args[numb3])
  198.      end
  199.     end
  200.     numb4 = numb3 + 1
  201.     term.write(args[numb3])
  202.    end
  203.    if args[numb4] and args[numb4] ~= "-u" and args[numb4] ~= "-l" then
  204.     term.write(" ")
  205.    end
  206.    numb3 = numb3 + 1
  207.   end
  208.   numb3 = 1
  209.  elseif scrnsvrID == 1 then
  210.   while args[numb3] ~= nil do
  211.    if args[numb3] == "-u" then
  212.     numb3 = numb3 + 1
  213.     if upper == true then
  214.      args[numb3] = string.upper(args[numb3])
  215.     end
  216.    elseif args[numb3] == "-l" then
  217.     numb3 = numb3 + 1
  218.     if lower == true then
  219.      args[numb3] = string.lower(args[numb3])
  220.     end
  221.    elseif args[numb3] == "-r" then
  222.     numb3 = numb3 + 1
  223.     if rand == true then
  224.      local randChance = math.random(100)
  225.      if randChance < 50 then
  226.       args[numb3] = string.upper(args[numb3])
  227.      elseif randChance >= 50 then
  228.       args[numb3] = string.lower(args[numb3])
  229.      end
  230.     end
  231.    else
  232.     for i = 1,string.len(args[numb3]) do
  233.       table.insert(l,#l+1,string.char(string.byte(args[numb3],i)))
  234.     end
  235.     numb3 = numb3 + 1
  236.    end
  237.   end
  238.   local letter = math.random(#l)
  239.   local lett = l[letter]
  240.   if upper == true then
  241.    local lett = string.upper(lett)
  242.   elseif lower == true then
  243.    local lett = string.lower(lett)
  244.   elseif rand == true then
  245.    local randChance = math.random(100)
  246.    if randChance < 50 then
  247.     local lett = string.upper(lett)
  248.    elseif randChance >= 50 then
  249.     local lett = string.lower(lett)
  250.    end
  251.   end
  252.   write(lett)
  253.  elseif scrnsvrID == 2 then
  254.   local letter = byte.decode(math.random(32,126))
  255.   if letter ~= false then
  256.    if upper == true then
  257.     letter = string.upper(letter)
  258.    elseif lower == true then
  259.     letter = string.lower(letter)
  260.    elseif rand == true then
  261.     local randChance = math.random(100)
  262.     if randChance < 50 then
  263.      letter = string.upper(letter)
  264.     elseif randChance >= 50 then
  265.      letter = string.lower(letter)
  266.     end
  267.    end
  268.    write(letter)
  269.   end
  270.  elseif scrnsvrID == 3 then
  271.   term.write(" ")
  272.  elseif scrnsvrID == 4 then
  273.   for i = 1,h do
  274.    local x,y = term.getCursorPos()
  275.    write(" ")
  276.    local y = y + 1
  277.    term.setCursorPos(x,y)
  278.   end
  279.  elseif scrnsvrID == 5 then
  280.   if fs.exists(picDir) and fs.isDir(picDir) then
  281.    local pics = fs.list(picDir)
  282.    local pic = math.random(#pics)
  283.    local image = paintutils.loadImage(picDir.."/"..pics[pic])
  284.    paintutils.drawImage(image,1,1)
  285.    term.setBackgroundColour(colours.black)
  286.   else
  287.    error("Folder not found: "..picdir)
  288.   end
  289.  elseif scrnsvrID == 6 then
  290.   if fs.exists(picDir) and fs.isDir(picDir) then
  291.    local pics = fs.list(picDir)
  292.    local pic = math.random(#pics)
  293.    local image = paintutils.loadImage(picDir.."/"..pics[pic])
  294.    paintutils.drawImage(image,math.random(w),math.random(h))
  295.    term.setBackgroundColour(colours.black)
  296.   else
  297.    error("Folder not found: "..picDir)
  298.   end
  299.  end
  300. end
  301. while true do
  302.  screensaver()
  303.  os.startTimer(wait)
  304.  event,p1,p2,p3 = os.pullEvent()
  305.  if scrnsvrID == 5 then
  306.   term.clear()
  307.  end
  308.  if event ~= "timer" then
  309.   term.setTextColour(colours.white)
  310.   term.setBackgroundColour(colours.black)
  311.   term.clear()
  312.   term.setCursorPos(1,1)
  313.   os.unloadAPI("shnupProgFiles/apis/dl")
  314.   os.unloadAPI("shnupProgFiles/apis/byte")
  315.   os.unloadAPI("shnupProgFiles/screensaver/apis/CConfig")
  316.   break
  317.  end
  318. end
Advertisement
Add Comment
Please, Sign In to add comment