Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- redstonePlay
- modification of
- easyPlay
- By Barnet
- --]] -- --
- local function getSongs(songPath)
- local songs = {songPath}
- local r = {}
- for i, song in ipairs(songs) do
- if fs.isDir(song) then
- moreSongs = fs.list(song)
- for j, s in ipairs(moreSongs) do
- table.insert(songs, song .. "/" .. s)
- end
- table.insert(r, i)
- end
- end
- for i = table.maxn(r), 1, -1 do table.remove(songs, r[i]) end
- return songs
- end
- local function getName(song)
- local i = string.find(song, "/[^/]*$")
- if i ~= nil then
- local songName = string.sub(song, i + 1, string.len(song))
- songName = songName:gsub("^%l", string.upper)
- i = string.find(songName, "%.")
- if i ~= nil then songName = string.sub(songName, 1, i - 1) end
- return songName
- else
- return song
- end
- end
- local function start(songPath, option)
- local loop = option ~= nil and string.find(option, "l") ~= nil
- local color = option ~= nil and string.find(option, "c") ~= nil
- if songPath == "" then error("No song path") end
- if string.sub(songPath, 1, 1) == '.' then
- songPath = shell.dir() .. string.sub(songPath, 2)
- end
- local songs = getSongs(songPath)
- local n = table.maxn(songs)
- repeat
- monitor = peripheral.find("monitor")
- if monitor == nil then error("No monitor detected!") end
- monitorName = peripheral.getName(monitor)
- local speakers = ""
- local speakerCount = 0
- for i, perName in ipairs(peripheral.getNames()) do
- if string.find(perName, "speaker") then
- speakers = speakers .. perName .. " "
- speakerCount = speakerCount + 1
- end
- end
- if speakerCount == 0 then error("No speakers detected!") end
- for i, song in ipairs(songs) do
- shell.run("EasyPlay/Core/playnbs.lua " .. tostring(color) .. " " ..
- getName(song) .. " " .. song .. " " .. monitorName ..
- " " .. speakers)
- end
- until not loop
- end
- local function GetArg(a)
- if a ~= nil then
- return a
- else
- return ""
- end
- end
- local arg1 = GetArg(arg[1])
- local arg2 = GetArg(arg[2])
- local arg3 = GetArg(arg[3])
- local path = ""
- local option = ""
- if arg1 == "start" then
- path = arg2
- option = arg3
- else
- path = arg1
- option = arg2
- end
- while true
- do
- local e = os.pullEvent("redstone")
- start(path, option)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement