Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Delightful Enhanced sound test code by rixithechao
- -- v1.0.2
- -- June 4, 2025
- -- This code comes with zero guarantee that it works perfectly. If it has any issues, feel free to fix it up or modify it to suit your needs
- -- If you use this library, please either include me in your episode credits (in a "Libraries Used" or "Additional Code By" section or whatever equivalent you have) or add the line "Delightful Enhanced sound test code used with permission from its programmer"
- --[[ USAGE INSTRUCTIONS:
- First, load this library and configure it with the following lines of code at the top of your level's luna.lua file:
- local soundTest = require("delightfulSoundTest")
- soundTest.section = #
- soundTest.font = valid textplus font
- soundTest.eventNames = {
- toggle = "vanilla event name to toggle the music player",
- previous = "same but for moving to the next track",
- next = "for moving to the previous track",
- showPrevious = "for showing the previous track block",
- hidePrevious = "for hiding the previous track block",
- showNext = "for showing the next track block",
- hideNext = "for hiding the next track block",
- }
- By default, it uses section 0, textplus font 3, and the following event names.
- "SoundTest Toggle"
- "SoundTest Previous"
- "SoundTest Next"
- "SoundTest ShowPrevious"
- "SoundTest HidePrevious"
- "SoundTest ShowNext"
- "SoundTest HideNext"
- Once you have the library configured, you'll need to load your music. You can manually list them like so:
- soundTest.tracks = {
- "a path as you'd specify it in a section's custom music field in the editor",
- "another path in the same format",
- "and so on",
- }
- Or you can call the load function, which will fill out the track list automatically from the specified folder (or "music" if you don't give an argument.) Note that this loads them in alphabetical order based on their filenames, so you may want to specify track numbers in the filenames if you want them included in a specific order (i.e. '01-title.ogg', `02-intro.spc`, etc.)
- soundTest.load() -- loads from 'episodeName/music/'
- soundTest.load("allTheMusic") -- loads from 'episodeName/allTheMusic/'
- Of course, the track list is really just an orderered lua table, so if you want you can load most of the tracks from one folder automatically and then append a few from elsewhere in the project.
- soundTest.load()
- soundTest.tracks[#soundTest.tracks+1] = "another path somewhere else in the project"
- Altogether, your code will look something like this:
- local soundTest = require("delightfulSoundTest")
- soundTest.section = 19
- soundTest.eventNames = {
- toggle = "Music Player Toggle",
- previous = "Music Player Prev",
- next = "Music Player Next",
- showPrevious = "Music Player Show Prev",
- hidePrevious = "Music Player Hide Prev",
- showNext = "Music Player Show Next",
- hideNext = "Music Player Hide Next",
- }
- soundTest.load()
- ]]
- local textplus = require("textplus")
- local soundTest = {
- section = 0,
- font = textplus.loadFont("textplus/font/3.ini"),
- eventNames = {
- toggle = "SoundTest Toggle",
- previous = "SoundTest Previous",
- next = "SoundTest Next",
- showPrevious = "SoundTest ShowPrevious",
- hidePrevious = "SoundTest HidePrevious",
- showNext = "SoundTest ShowNext",
- hideNext = "SoundTest HideNext",
- },
- tracks = {},
- noMusicText = "NO MUSIC LOADED",
- current = 1,
- playing = false,
- playTime = 0
- }
- function onInitAPI()
- registerEvent(soundTest, "onEvent")
- registerEvent(soundTest, "onDraw")
- end
- function soundTest.load(path)
- soundTest.tracks = Misc.listLocalFiles(Misc.resolveDirectory(path or "music"))
- end
- function soundTest.onEvent(eventName)
- -- Sound test stuff
- if eventName == soundTest.eventNames.toggle then
- soundTest.playing = not soundTest.playing
- if soundTest.playing then
- Audio.MusicChange(soundTest.section, soundTest.musicFolderPath .. soundTest.tracks[soundTest.current])
- else
- Audio.MusicChange(soundTest.section, 0)
- end
- end
- if eventName == soundTest.eventNames.previous then
- soundTest.current = math.max(1, soundTest.current-1)
- if soundTest.current == #soundTest.tracks-1 then
- triggerEvent(soundTest.eventNames.showNext)
- end
- if soundTest.current == 1 then
- triggerEvent(soundTest.eventNames.hidePrevious)
- end
- if soundTest.playing then
- Audio.MusicChange(soundTest.section, soundTest.musicFolderPath .. soundTest.tracks[soundTest.current])
- end
- end
- if eventName == soundTest.eventNames.next then
- soundTest.current = math.min(#soundTest.tracks, soundTest.current+1)
- if soundTest.current == 2 then
- triggerEvent(soundTest.eventNames.showPrevious)
- end
- if soundTest.current == #soundTest.tracks then
- triggerEvent(soundTest.eventNames.hideNext)
- end
- if soundTest.playing then
- Audio.MusicChange(soundTest.section, soundTest.musicFolderPath .. soundTest.tracks[soundTest.current])
- end
- end
- end
- function soundTest.onDraw()
- if player.section == soundTest.section then
- local musicNameText = soundTest.noMusicText
- if #soundTest.tracks > 0 then
- musicNameText = "<align center>" .. tostring(soundTest.current) .. "/" .. tostring(#soundTest.tracks) .. "<br><br>" .. soundTest.tracks[soundTest.current] .. "</align>"
- end
- textplus.print{
- text=musicNameText,
- font=soundTest.font,
- xscale=2,yscale=2,
- x=-119600,y=-120496,
- maxWidth=600,
- priority=5,
- pivot=vector(0.5,0),
- sceneCoords=true,
- color=Color.white
- }
- if soundTest.playing then
- soundTest.playTime = Audio.MusicClock()
- else
- soundTest.playTime = 0
- end
- textplus.print{
- text="<align center>" .. os.date("%M:%S", soundTest.playTime) .. ":" .. string.format("%02d",math.floor(100*soundTest.playTime)%100) .. "</align>",
- font=soundTest.font,
- xscale=2,yscale=2,
- x=-119600,y=-120404,
- maxWidth=600,
- priority=5,
- pivot=vector(0.5,0),
- sceneCoords=true,
- color=Color.white
- }
- end
- end
- return soundTest
Advertisement
Add Comment
Please, Sign In to add comment