Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- (C) 2023 Freekeh99, All Rights Reserved.
- -- Memory
- local nowplaying = nil
- local nostalgiamode = false
- -- Text functions
- local function centerText(text, y)
- local x = (term.getSize() - string.len(text)) / 2
- term.setCursorPos(x, y)
- term.write(text)
- -- Reset cursor position
- term.setCursorPos(1, 1)
- end
- local function optionsText(key, text, y)
- local x = 3
- term.setCursorPos(x, y)
- term.write("[" .. key .. "] " .. text)
- end
- -- Number key convertion to number
- local function numberKey(key)
- if key == keys.one then
- return 1
- elseif key == keys.two then
- return 2
- elseif key == keys.three then
- return 3
- elseif key == keys.four then
- return 4
- elseif key == keys.five then
- return 5
- elseif key == keys.six then
- return 6
- elseif key == keys.seven then
- return 7
- elseif key == keys.eight then
- return 8
- elseif key == keys.nine then
- return 9
- elseif key == keys.zero then
- return 0
- end
- return nil
- 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 v1.0", 1)
- centerText("Press Enter to view options", 3)
- if nowplaying ~= nil then
- centerText("Now playing:", 5)
- centerText(song_titles[nowplaying], 6)
- end
- end
- -- Draw the options menu on Enter press.
- local function drawOptionsMenu()
- term.clear()
- term.setCursorPos(1, 1)
- centerText("TunePlay Options", 1)
- if nowplaying ~= nil then
- optionsText("P", "Choose another song", 3)
- else
- optionsText("P", "Choose a song", 3)
- end
- if nostalgiamode then
- optionsText("N", "Disable nostalgia mode", 4)
- else
- optionsText("N", "Enable nostalgia mode", 4)
- end
- optionsText("B", "Back to main menu", 5)
- optionsText("Q", "Exit", 6)
- 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 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",
- "Shuffle underwater 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
- local j = 0
- for i = start, stop do
- if i > #songs then
- break
- end
- optionsText(j, song_titles[i], y)
- y = y + 1
- j = j + 1
- end
- y = y + 1
- if page > 1 then
- optionsText("P", "Previous page", y)
- y = y + 1
- end
- if stop < #songs then
- optionsText("N", "Next page", y)
- end
- optionsText("B", "Back to main menu", y + 1)
- end
- -- Play a song
- local function playSong(song)
- local speakers = {peripheral.find "speaker"}
- for _, speaker in ipairs(speakers) do
- if nostalgiamode then
- speaker.playSound(songs[song], 1.1, 0.84)
- else
- speaker.playSound(songs[song], 1.0, 1.0)
- end
- end
- nowplaying = song
- 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.p 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
- drawMenu()
- break
- else
- -- Check if the key is a number
- local num = numberKey(key)
- if num ~= nil then
- local song = (page - 1) * 10 + num + 1
- playSong(song)
- -- Back to main menu
- drawMenu()
- break
- end
- end
- end
- break
- elseif key == keys.b then
- drawMenu()
- break
- elseif key == keys.n then
- nostalgiamode = not nostalgiamode
- drawOptionsMenu()
- elseif key == keys.q then
- -- Clear the screen and exit
- term.clear()
- return
- end
- end
- end
- end
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement