Advertisement
Arc13

music

May 8th, 2016
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.00 KB | None | 0 0
  1. diskDrive = peripheral.find("drive")
  2.  
  3. if not os.loadAPI("time") then
  4.     shell.run("pastebin get 6nArsPfK time")
  5.     os.loadAPI("time")
  6. end
  7.  
  8. term.setBackgroundColor(colors.lightGray)
  9. term.clear()
  10. x, y = term.getSize()
  11. paintutils.drawLine(1, 1, x, 1, colors.gray)
  12. term.setCursorPos(1, 1)
  13. term.write("music by arc13")
  14.  
  15. if not diskDrive then
  16.     term.setBackgroundColor(colors.black)
  17.     term.clear()
  18.     term.setCursorPos(1, 1)
  19.     error("No disk drive found")
  20. end
  21.  
  22. paintutils.drawPixel(x, 1, colors.red)
  23. term.setCursorPos(x, 1)
  24. term.write("X")
  25.  
  26. term.setBackgroundColor(colors.lightGray)
  27.  
  28. function toast(text, default)
  29.     if text then
  30.         paintutils.drawLine(1, y, x, y, colors.blue)
  31.         term.setCursorPos(1, y)
  32.         term.clearLine()
  33.         if default then
  34.             term.write(text)
  35.         else
  36.             term.write("["..time.getWorldHours()..":"..time.getWorldMinutes().."] "..text)
  37.         end
  38.         term.setBackgroundColor(colors.lightGray)
  39.     end
  40. end
  41.  
  42. function buttonHandler()
  43.     while true do
  44.         event, button, cX, cY = os.pullEvent("mouse_click")
  45.         if cX <= 7 and cY >= y - 5 and cY <= y - 2 and diskDrive.hasAudio() then
  46.             diskDrive.playAudio()
  47.         elseif cX >= x - 6 and cY >= y - 5 and cY <= y - 2 and diskDrive.hasAudio() then
  48.             diskDrive.stopAudio()
  49.         elseif cX == x and cY == 1 then
  50.             term.setBackgroundColor(colors.black)
  51.             term.clear()
  52.             term.setCursorPos(1, 1)
  53.             return true
  54.         end
  55.     end
  56. end
  57.  
  58. function toggleButtons(state)
  59.     if state then
  60.         paintutils.drawFilledBox(1, y - 6, 7, y - 2, colors.green)
  61.         term.setCursorPos(3, y - 4)
  62.         term.write("|>")
  63.         paintutils.drawFilledBox(x - 6, y - 6, x, y - 2, colors.red)
  64.         term.setCursorPos(x - 3, y - 4)
  65.         term.write("||")
  66.     else
  67.         paintutils.drawFilledBox(1, y - 6, 7, y - 2, colors.gray)
  68.         term.setCursorPos(3, y - 4)
  69.         term.write("|>")
  70.         paintutils.drawFilledBox(x - 6, y - 6, x, y - 2, colors.gray)
  71.         term.setCursorPos(x - 3, y - 4)
  72.         term.write("||")
  73.     end
  74.     term.setBackgroundColor(colors.lightGray)
  75. end
  76.  
  77. function diskHandler()
  78.     while true do
  79.         event = os.pullEvent()
  80.         if event == "disk" then
  81.             toast("Disk inserted !")
  82.             if diskDrive.hasAudio() then
  83.                 toggleButtons(true)
  84.                 term.setCursorPos(1, 3)
  85.                 term.clearLine()
  86.                 term.write(diskDrive.getAudioTitle())
  87.             else
  88.                 toggleButtons(false)
  89.                 term.setCursorPos(1, 3)
  90.                 term.clearLine()
  91.                 term.write("Not an audio disk !")
  92.             end
  93.         elseif event == "disk_eject" then
  94.             toast("Disk ejected !")
  95.             toggleButtons(false)
  96.             term.setCursorPos(1, 3)
  97.             term.clearLine()
  98.             term.write("No disk inserted !")
  99.         end
  100.     end
  101. end
  102.  
  103. if diskDrive.isDiskPresent() then
  104.     if diskDrive.hasAudio() then
  105.         toggleButtons(true)
  106.         term.setCursorPos(1, 3)
  107.         term.clearLine()
  108.         term.write(diskDrive.getAudioTitle())
  109.     else
  110.         toggleButtons(false)
  111.         term.setCursorPos(1, 3)
  112.         term.clearLine()
  113.         term.write("Not an audio disk !")
  114.     end
  115. else
  116.     toggleButtons(false)
  117.     term.setCursorPos(1, 3)
  118.     term.clearLine()
  119.     term.write("No disk inserted !")
  120. end
  121.  
  122. toast("No notifications !", true)
  123.  
  124. parallel.waitForAny(diskHandler, buttonHandler)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement