TheRockettek

SongGui

Apr 16th, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.06 KB | None | 0 0
  1. local songList = "LajAJwja"
  2. local condense = "W3jHDPSX"
  3. local songPlayer = "695qWt0q"
  4. print("Downloading dependency...")
  5. shell.run("rm cond")
  6. shell.run("rm player")
  7. shell.run("rm .songlist")
  8. shell.run("pastebin get " .. condense .. " cond")
  9. shell.run("pastebin get " .. songPlayer .. " player")
  10. print("Updating list...")
  11. shell.run("rm .songlist")
  12. shell.run("pastebin get " .. songList .. " .songlist")
  13. print("Starting up...")
  14. size = {term.getSize()}
  15. nb = peripheral.find("Music") or peripheral.find("minecraft:noteblock") or peripheral.find("speaker")
  16. if not nb then
  17. if peripheral.find("neuralInterface") then
  18. if peripheral.find("neuralInterface").playNote then
  19. nb = peripheral.find("neuralInterface")
  20. end
  21. end
  22. end
  23. local function centerText(text,yOffset)
  24. yOffset = yOffset or 0
  25. local x,y = term.getSize() local x2,y2 = term.getCursorPos()
  26. term.setCursorPos(math.round((x / 2) - (text:len() / 2)), y2+yOffset)
  27. write(text)
  28. end
  29. if ( not nb ) or ( not nb.playNote ) then
  30. term.setBackgroundColour(colours.lightGrey)
  31. term.setTextColour(colours.grey)
  32. centerText("Couldn't locate noteblock")
  33. centerText("Playing may not work!",1)
  34. sleep(4)
  35. end
  36.  
  37.  
  38. clr = {}
  39. for i,k in pairs(colours) do
  40. if type(k) == "number" and i ~= "black" then
  41. table.insert(clr,k)
  42. end
  43. end
  44.  
  45. term.clear()
  46. songs = {}
  47. f = fs.open(".songlist","r")
  48. while true do
  49. line = f.readLine()
  50. if not line then break else table.insert(songs,line) end
  51. end
  52.  
  53. size = {term.getSize()}
  54. term.setCursorPos(1,size[2]/2)
  55. term.setTextColour(colours.white)
  56. term.write(">")
  57.  
  58. function writeT(b)
  59. term.clear()
  60. term.setCursorPos(1,size[2]/2)
  61. term.write(">")
  62. str = 2-math.ceil((size[2]/2))
  63. line = 1
  64. term.setTextColour(colours.cyan)
  65. for i=str,str+size[2],1 do
  66. term.setCursorPos(3,line)
  67. term.write((songs[i+b] or "") .. string.rep(" ",30))
  68. line=line+1
  69. end
  70. term.setCursorPos(2,1)
  71. term.clearLine()
  72. term.setTextColour(clr[math.random(1,#clr)])
  73. term.write("Song Shop - " .. #songs .. " total songs!")
  74. end
  75.  
  76. offset = 1
  77. writeT(offset)
  78. while true do
  79. a,b,c,d = os.pullEvent()
  80. if a == "key" then
  81. if b == 200 then --up
  82. offset = offset - 1
  83. elseif b == 208 then --down
  84. offset = offset + 1
  85. elseif b == 201 then --pgup
  86. offset = 0
  87. elseif b == 209 then --bgdwn
  88. offset = #songs-1
  89. elseif b == 28 then -- enter
  90. term.clear()
  91. term.setCursorPos(1,1)
  92. songname = songs[offset]
  93. if songname == ".song Player" then
  94. shell.run("pastebin get 695qWt0q songPlayer")
  95. else
  96. print("Downloading " .. songname)
  97. shell.run("wget http://hackery.site/computercraft/lua-songs/" .. songname:gsub(" ","%%20") .. ".lua temp")
  98. shell.run("cond temp .temp")
  99. shell.run("rm temp")
  100. shell.run("player .temp \"" .. songname .. "\"")
  101. shell.run("rm .temp")
  102. term.clear()
  103. term.setCursorPos(1,1)
  104. end
  105. end
  106. if offset < 1 then offset = 1 end
  107. if offset > #songs then offset = #songs end
  108. writeT(offset)
  109. end
  110. end
Add Comment
Please, Sign In to add comment