Andy73

Zombease Installer

Dec 19th, 2016
1,399
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.94 KB | None | 0 0
  1.  
  2. -- [SublimeLinter luacheck-globals:term,colours,textutils,keys,blittle,shell,sleep,fs,window]
  3.  
  4. -- The Zombease installer, by viluon (Andrew Kvapil) http://viluon.me
  5.  
  6. --[[
  7. Arguments:
  8. dont    Don't actually run the install coroutine
  9. update  Set the message to the update version
  10. no-msg  Don't display a result message
  11. --]]
  12.  
  13. if not term.isColour or not term.isColour() then
  14.     print( "It appears that your computer does not support colours."
  15.         .. "Zombies love colours, especially green, the colour of a rotting body, or blue, the colour of your brain."
  16.         .. "Please get yourself an advanced computer before inviting zombies for a feast." )
  17. end
  18.  
  19. local args = { ... }
  20.  
  21. local old_term = term.current()
  22. local w, h = old_term.getSize()
  23. local main_win = window.create( old_term, 1, 1, w, h, false )
  24. local nil_win = window.create( old_term, 1, 1, w, h, false )
  25.  
  26. term.redirect( nil_win )
  27.  
  28. local running = true
  29.  
  30. local greens = {
  31.     colours.green, colours.green, colours.green, colours.lime, colours.lightGrey
  32. }
  33.  
  34. local arguments = {}
  35. for _, v in ipairs( args ) do
  36.     arguments[ v ] = true
  37. end
  38.  
  39. local heading = arguments.update and "Zombease is updating" or "Zombease will infect your computer"
  40. local time = arguments.update and "please wait" or "in a few moments"
  41.  
  42. --- Install Zombease
  43. -- @return nil
  44. local function install()
  45.     if not arguments.dont then
  46.         shell.run( "pastebin", "run", "W5ZkVYSi", "viluon", "Zombease" )
  47.     end
  48.  
  49.     sleep( 0 )
  50. end
  51.  
  52. --- Write something in fancy zombie-like colours.
  53. -- @param target description
  54. -- @param text description
  55. -- @return nil
  56. local function fancy_write( target, text )
  57.     for i = 1, #text do
  58.         target.setTextColour( greens[ math.random( 1, #greens ) ] )
  59.         target.write( text:sub( i, i ) )
  60.     end
  61. end
  62.  
  63. --- Draw the GUI
  64. -- @return nil
  65. local function redraw( dont, colour )
  66.     colour = colour or colours.white
  67.  
  68.     repeat
  69.         main_win.setVisible( false )
  70.  
  71.         main_win.setBackgroundColour( colours.black )
  72.         main_win.setTextColour( colour )
  73.         main_win.clear()
  74.  
  75.         main_win.setCursorPos( w / 2 - #heading / 2, h / 2 )
  76.  
  77.         if dont then
  78.             main_win.write( heading )
  79.         else
  80.             fancy_write( main_win, heading )
  81.         end
  82.  
  83.         main_win.setCursorPos( w / 2 - #time / 2, h / 2 + 1 )
  84.  
  85.         if dont then
  86.             main_win.write( time )
  87.         else
  88.             fancy_write( main_win, time )
  89.         end
  90.  
  91.         main_win.setVisible( true )
  92.  
  93.         sleep( 0.1 )
  94.     until dont
  95. end
  96.  
  97. local coroutines = {
  98.     coroutine.create( install );
  99.     coroutine.create( redraw  );
  100. }
  101.  
  102. redraw( true, colours.black )
  103. redraw( true, colours.grey )
  104. redraw( true, colours.lightGrey )
  105.  
  106. -- First yield
  107. for i, coro in ipairs( coroutines ) do
  108.     local ok, err = coroutine.resume( coro )
  109.  
  110.     if not ok then
  111.         term.redirect( old_term )
  112.         term.setTextColour( colours.lightGrey )
  113.         term.clear()
  114.         term.setCursorPos( 1, 1 )
  115.  
  116.         print( "Damn it! Zombies from the invasion tactics team " .. i
  117.             .. " killed each other over some brain leftovers, before the invasion could start. "
  118.             .. "The last one alive said it's because you" )
  119.         error( err, 0 )
  120.     end
  121. end
  122.  
  123. local ok, err, source
  124.  
  125. while running do
  126.     local ev = { os.pullEvent() }
  127.  
  128.     for key, coro in ipairs( coroutines ) do
  129.         ok, err = coroutine.resume( coro, unpack( ev ) )
  130.  
  131.         source = key
  132.  
  133.         if coroutine.status( coro ) == "dead" then
  134.             running = false
  135.             break
  136.         end
  137.  
  138.         if not ok then
  139.             running = false
  140.             break
  141.         end
  142.     end
  143. end
  144.  
  145. redraw( true, colours.lightGrey )
  146. redraw( true, colours.grey )
  147. redraw( true, colours.black )
  148.  
  149. term.redirect( old_term )
  150.  
  151. if arguments[ "no-msg" ] and ok then
  152.     return
  153. end
  154.  
  155. term.setBackgroundColour( colours.black )
  156. term.clear()
  157.  
  158. term.setCursorPos( 1, 1 )
  159.  
  160. if ok then
  161.     term.setTextColour( colours.white )
  162.     print( "Success! Run menu.lua to launch the game." )
  163.     term.setCursorPos( 1, 2 )
  164.  
  165.     return
  166. else
  167.     term.setTextColour( colours.lightGrey )
  168.     print( "Crap! Zombies from the brain-eating team #" .. source .. " rot on their way. Their last words were" )
  169.     error( err, 0 )
  170. end
Add Comment
Please, Sign In to add comment