Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- (C) 2023 Freekeh99, All Rights Reserved.
- -- Text functions
- local function centerText(text, y)
- local x = (term.getSize() - string.len(text)) / 2
- term.setCursorPos(x, y)
- term.write(text)
- end
- local function optionsText(key, text, y)
- local x = 3
- term.setCursorPos(x, y)
- term.write("[" .. key .. "] " .. text)
- end
- -- Draw the main menu.
- -- It displays the program name and waits for the user to press Enter.
- local function drawMenu()
- term.clear()
- term.setCursorPos(1, 1)
- centerText("Welcome to TunePlay", 1)
- centerText("Press Enter to view options", 3)
- centerText("Version 1.0", 6)
- end
- -- Draw the options menu on Enter press.
- local function drawOptionsMenu()
- term.clear()
- term.setCursorPos(1, 1)
- centerText("TunePlay Options", 1)
- optionsText("1", "Choose a song", 3)
- optionsText("2", "Start playback", 4)
- optionsText("3", "Stop playback", 5)
- optionsText("4", "Back to main menu", 6)
- optionsText("5", "Exit", 7)
- end
- -- Array of all the songs available.
- songs = {
- "music.creative",
- "music.credits",
- "music.dragon",
- "music.end",
- "music.game",
- "music.menu",
- "music.nether.basalt_deltas",
- "music.nether.crimson_forest",
- "music.nether.nether_wastes",
- "music.nether.soul_sand_valley",
- "music.nether.warped_forest",
- "music.overworld.deep_dark",
- "music.overworld.dripstone_caves",
- "music.overworld.frozen_peaks",
- "music.overworld.grove",
- "music.overworld.jagged_peaks",
- "music.overworld.lush_caves",
- "music.overworld.meadow",
- "music.overworld.old_growth_taiga",
- "music.overworld.snowy_slopes",
- "music.overworld.stony_peaks",
- "music.overworld.swamp",
- "music.under_water",
- "music_disc.11",
- "music_disc.13",
- "music_disc.5",
- "music_disc.blocks",
- "music_disc.cat",
- "music_disc.chirp",
- "music_disc.far",
- "music_disc.mall",
- "music_disc.mellohi",
- "music_disc.otherside",
- "music_disc.pigstep",
- "music_disc.stal",
- "music_disc.strad",
- "music_disc.wait",
- "music_disc.ward"
- }
- song_titles = {
- "Shuffle creative music",
- "C418 - Alpha",
- "C418 - Dragon Fight",
- "C418 - The End",
- "Shuffle survival music",
- "Shuffle menu music",
- "Shuffle Nether Basalt Deltas music",
- "Shuffle Nether Crimson Forest music",
- "Shuffle Nether Nether Wastes music",
- "Shuffle Nether Soul Sand Valley music",
- "Shuffle Nether Warped Forest music",
- "Shuffle underwater music",
- "Shuffle Deep Dark music",
- "Shuffle Dripstone Caves music",
- "Shuffle Frozen Peaks music",
- "Shuffle Grove music",
- "Shuffle Jagged Peaks music",
- "Shuffle Lush Caves music",
- "Shuffle Meadow music",
- "Shuffle Old Growth Taiga music",
- "Shuffle Snowy Slopes music",
- "Shuffle Stony Peaks music",
- "Shuffle Swamp music",
- "C418 - 11",
- "C418 - 13",
- "Samuel Aberg - 5",
- "C418 - Blocks",
- "C418 - Cat",
- "C418 - Chirp",
- "C418 - Far",
- "C418 - Mall",
- "C418 - Mellohi",
- "Lena Raine - Otherside",
- "Lena Raine - Pigstep",
- "C418 - Stal",
- "C418 - Strad",
- "C418 - Wait",
- "C418 - Ward"
- }
- -- Draw music list, paginated
- local function drawMusicList(page)
- term.clear()
- term.setCursorPos(1, 1)
- centerText("Choose a song", 1)
- local i = 1
- local y = 3
- local max = 10
- local start = (page - 1) * max + 1
- local stop = page * max
- for i = start, stop do
- if i > #songs then
- break
- end
- optionsText(i, song_titles[i], y)
- y = y + 1
- end
- if page > 1 then
- optionsText("p", "Previous page", y)
- end
- if stop < #songs then
- optionsText("n", "Next page", y + 1)
- end
- optionsText("b", "Back to options", y + 2)
- end
- -- Play a song
- local function playSong(song)
- term.clear()
- term.setCursorPos(1, 1)
- centerText("Now playing", 1)
- centerText(song_titles[song], 3)
- term.setCursorPos(1, 5)
- term.write("Press Enter to stop playback")
- local handle = peripheral.find("speaker")
- handle.playDisk(songs[song])
- while true do
- local event, key = os.pullEvent("key")
- if key == keys.enter then
- handle.stop()
- break
- end
- end
- end
- -- Main loop
- local function main()
- drawMenu()
- while true do
- local event, key = os.pullEvent("key")
- if key == keys.enter then
- drawOptionsMenu()
- while true do
- local event, key = os.pullEvent("key")
- if key == keys["1"] then
- local page = 1
- while true do
- drawMusicList(page)
- local event, key = os.pullEvent("key")
- if key == keys["p"] then
- if page > 1 then
- page = page - 1
- end
- elseif key == keys["n"] then
- if page < math.ceil(#songs / 10) then
- page = page + 1
- end
- elseif key == keys["b"] then
- break
- else
- if key >= 1 and key <= #songs then
- playSong(key)
- end
- end
- end
- elseif key == keys["2"] then
- local handle = peripheral.find("speaker")
- handle.playDisk("music.creative")
- elseif key == keys["3"] then
- local handle = peripheral.find("speaker")
- handle.stop()
- elseif key == keys["4"] then
- drawMenu()
- break
- elseif key == keys["5"] then
- return
- end
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement