Advertisement
ozozx235

juke.lua

Sep 17th, 2023 (edited)
530
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.08 KB | None | 0 0
  1. local tArgs = {...}
  2. local speak = peripheral.find("speaker")
  3. local lib = io.open("musiclib.txt")
  4. local sizeX, sizeY = term.getSize()
  5. local lines = lib:lines()
  6. function noUS (s)
  7.     return s:gsub("%_", " ")
  8. end
  9. function visual (det, offs)
  10.     term.clear()
  11.     term.setCursorPos((sizeX/2)-3,(sizeY/2)-1)
  12.     print("playing")
  13.     term.setCursorPos(((sizeX/2)-(string.len(det[1])/2))+1,(sizeY/2))
  14.     local swatch = {"1","2","3","4","5","6","9","a","b","c","d","e"}
  15.     local front = ""
  16.     local back = ""
  17.     for it = 1,string.len(det[1]) do
  18.         front = front .. "" .. swatch[(it-offs)%12+1]
  19.         back = back .. "f"
  20.     end
  21.     term.blit((noUS(det[1])),front,back)
  22.     term.setTextColor(colors.red)
  23.     term.setCursorPos(((sizeX/2)-(string.len(det[2])/2)-1),(sizeY/2)+1)
  24.     print("by " .. (noUS(det[2])))
  25.     term.setTextColor(colors.white)
  26. end
  27. if(#tArgs == 1) then
  28.     song = tArgs[1]
  29.     for line in lines do
  30.         deets = {}
  31.         i=0
  32.         for sub in line:gmatch("%S+") do
  33.             deets[i] = sub
  34.             i=i+1
  35.         end
  36.         if(deets[0] == song) then
  37.             speak.playSound(deets[3])
  38.             ofs = 0
  39.             visual(deets, ofs)
  40.             sleep(1)
  41.             while true do
  42.                 timerID = os.startTimer(0.25)
  43.                 local evdat = {os.pullEvent()}
  44.                 local ev = evdat[1]
  45.                 if ev == "key_up" then
  46.                     speak.stop()
  47.                     term.clear()
  48.                     term.setCursorPos(1,1)
  49.                     term.write("song ended")
  50.                     return
  51.                 elseif ev == "timer" and evdat[2] == timerID then
  52.                     ofs = ofs+1
  53.                     visual(deets,ofs)
  54.                 end
  55.             end
  56.         end
  57.     end
  58.     print("song not found")
  59. end
  60. if(#tArgs == 0) then
  61.     term.clear()
  62.     term.setCursorPos(1,1)
  63.     term.setTextColor(colors.green)
  64.     term.write("Music Selection")
  65.     term.setTextColor(colors.white)
  66.     for line in lines do
  67.         _, pos = term.getCursorPos()
  68.         if (pos > sizeY-2) then
  69.             os.pullEvent("key_up")
  70.         end
  71.         print()
  72.         deets = {}
  73.         i=0
  74.         for sub in line:gmatch("%S+") do
  75.             deets[i] = sub
  76.             i=i+1
  77.         end
  78.         term.setTextColor(colors.yellow)
  79.         term.write((deets[0]) .. " ")
  80.         term.setTextColor(colors.orange)
  81.         term.write((noUS(deets[1])))
  82.         term.setTextColor(colors.blue)
  83.         term.write(" -" .. (noUS(deets[2])))
  84.     end
  85.     os.pullEvent("key_up")
  86.     print()
  87. end
Tags: CCScripts
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement