Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- _G["HyTunes"] = {}
- HyTunes["speaker"] = peripheral.find("speaker")
- if HyTunes.speaker == null then
- print("Could not find a speaker!")
- return
- end
- HyTunes["songs"] = {}
- HyTunes["Volume"] = 1
- HyTunes.songs[1] = {
- ["title"] = "Padoru",
- ["track"] = "minecraft:music_disc.11",
- ["artist"] = "Senzawa"
- }
- HyTunes.songs[2] = {
- ["title"] = "Feliz Navidad",
- ["track"] = "minecraft:music_disc.far",
- ["artist"] = "Jose Faliciano"
- }
- HyTunes.songs[3] = {
- ["title"] = "Last Christmas",
- ["track"] = "minecraft:music_disc.mall",
- ["artist"] = "Wham!"
- }
- HyTunes.songs[4] = {
- ["title"] = "Carol of the Bells",
- ["track"] = "minecraft:music_disc.wait",
- ["artist"] = "Some choir Archie found"
- }
- HyTunes.songs[5] = {
- ["title"] = "Beginning to Look a Lot like Christmas",
- ["track"] = "minecraft:music_disc.chirp",
- ["artist"] = "Michael Bubble"
- }
- HyTunes.songs[6] = {
- ["title"] = "Rubber Tree",
- ["track"] = "minecraft:music_disc.13",
- ["artist"] = "Duncan Lalna"
- }
- HyTunes.songs[7] = {
- ["title"] = "Jingle Bells",
- ["track"] = "minecraft:music_disc.stal",
- ["artist"] = "Kidz Music Official"
- }
- HyTunes.songs[8] = {
- ["title"] = "Christmas Time",
- ["track"] = "minecraft:music_disc.pigstep",
- ["artist"] = "The Darkness"
- }
- HyTunes.songs[9] = {
- ["title"] = "Christmas Tree",
- ["track"] = "minecraft:music_disc.cat",
- ["artist"] = "Crouch-End Festival Chorus"
- }
- HyTunes.songs[10] = {
- ["title"] = "We wish you a merry Christmas",
- ["track"] = "minecraft:music_disc.blocks",
- ["artist"] = "Some Orchestra Archie found"
- }
- HyTunes.songs[11] = {
- ["title"] = "Fairytale of New York",
- ["track"] = "minecraft:music_disc.strad",
- ["artist"] = "Pogues"
- }
- HyTunes.songs[12] = {
- ["title"] = "The Christmas Song",
- ["track"] = "minecraft:music_disc.ward",
- ["artist"] = "Nat King Cole"
- }
- HyTunes["currentSong"] = HyTunes.songs[1]
- HyTunes["termSize"] = { term.getSize() }
- function renderList()
- term.setBackgroundColor(colors.lightGray)
- term.clear()
- paintutils.drawLine(1,1,HyTunes.termSize[1],1,colors.magenta)
- term.setCursorPos(1,1)
- term.setTextColor(colors.black)
- write("HyTunes 0.5")
- for i=1,HyTunes.termSize[2]-1 do
- local color = i % 2 == 1 and colors.cyan or colors.lightBlue
- paintutils.drawLine(1,i+1,HyTunes.termSize[1],i+1,color)
- end
- term.setCursorPos(1,2)
- color = colors.cyan
- for i = 1,#HyTunes.songs do
- name = HyTunes.songs[i].title
- if #name > HyTunes.termSize[1] then
- print(name:sub(1,HyTunes.termSize[1] - 3).."...")
- else
- print(name)
- end
- color = color == colors.lightBlue and colors.cyan or colors.lightBlue
- term.setBackgroundColor(color)
- end
- term.setCursorPos(HyTunes.termSize[1]-2,1)
- for i = 1,3 do
- if HyTunes.Volume == i then
- term.setBackgroundColor(colors.pink)
- else
- term.setBackgroundColor(colors.magenta)
- end
- write(i)
- end
- HyTunes.currentHandler = handleList
- end
- function breakIntoLines(text)
- if #text > HyTunes.termSize[1] then
- words = {}
- for word in text:gmatch("%w+") do table.insert(words,word) end
- lines = {}
- line = ""
- for _,word in pairs(words) do
- if #line + #word > HyTunes.termSize[1] then
- table.insert(lines, line)
- line = word
- else
- if #line > 0 then line = line.." "..word else line = word end
- end
- end
- if #line > 0 then
- table.insert(lines, line)
- end
- return lines
- else
- return { text }
- end
- end
- function renderMusic()
- color = colors.cyan
- term.setBackgroundColor(colors.cyan)
- term.clear()
- lines = breakIntoLines(HyTunes.currentSong.title)
- titleWord = "Currently Playing"
- lineNum = ((HyTunes.termSize[2] / 2) - (#lines / 2)) - 3
- term.setCursorPos((HyTunes.termSize[1] / 2) - (#titleWord / 2), lineNum - 1)
- write(titleWord)
- for _,line in pairs(lines) do
- term.setCursorPos((HyTunes.termSize[1] / 2) - (#line / 2), lineNum)
- write(line)
- lineNum = lineNum + 1
- end
- lineNum = lineNum + 1
- artistWord = "Artist"
- lines = breakIntoLines(HyTunes.currentSong.artist)
- for _,line in pairs(lines) do
- term.setCursorPos((HyTunes.termSize[1] / 2) - (#line / 2), lineNum)
- write(line)
- lineNum = lineNum + 1
- end
- paintutils.drawLine(1,HyTunes.termSize[2],HyTunes.termSize[1],HyTunes.termSize[2],colors.lightBlue)
- term.setCursorPos(1,HyTunes.termSize[2])
- write("Back")
- HyTunes.currentHandler = handleMusic
- end
- function handleMusic()
- local event, button, x, y = os.pullEvent("mouse_click")
- if x < 5 and y == HyTunes.termSize[2] then
- HyTunes.currentPage = renderList
- end
- end
- function handleList()
- local event, button, x, y = os.pullEvent("mouse_click")
- if y > 1 then
- if HyTunes.songs[y-1] then
- HyTunes.currentSong = HyTunes.songs[y-1]
- HyTunes.speaker.playSound(HyTunes.currentSong.track, HyTunes.Volume)
- HyTunes.currentPage = renderMusic
- end
- else
- if x >= HyTunes.termSize[1] - 2 then
- HyTunes.Volume = 3 - (HyTunes.termSize[1] - x)
- term.setCursorPos(HyTunes.termSize[1]-2,1)
- for i = 1,3 do
- if HyTunes.Volume == i then
- term.setBackgroundColor(colors.pink)
- else
- term.setBackgroundColor(colors.magenta)
- end
- write(i)
- end
- end
- end
- end
- HyTunes["currentPage"] = renderList
- function doInteractions()
- processedPage = HyTunes.currentPage
- processedPage()
- processedHandler = HyTunes.currentHandler
- while true do
- processedHandler()
- if processedHandler ~= HyTunes.currentHandler then
- processedHandler = HyTunes.currentHandler
- end
- if processedPage ~= HyTunes.currentPage then
- processedPage = HyTunes.currentPage
- processedPage()
- processedHandler = HyTunes.currentHandler
- end
- end
- end
- doInteractions()
Advertisement
Add Comment
Please, Sign In to add comment