2021-05-06 14:22:19 +00:00
|
|
|
accentColor = colors.gray
|
|
|
|
buttonColor = colors.lightGray
|
|
|
|
backgroundColor = colors.black
|
|
|
|
|
2021-05-06 17:46:25 +00:00
|
|
|
function round(n)
|
|
|
|
return n % 1 >= 0.5 and math.ceil(n) or math.floor(n)
|
|
|
|
end
|
|
|
|
|
2021-05-06 14:22:19 +00:00
|
|
|
width, height = term.getSize()
|
2021-05-06 17:46:25 +00:00
|
|
|
centerWidth = round(width / 2)
|
|
|
|
centerHeight = round(width / 2)
|
2021-05-06 14:22:19 +00:00
|
|
|
peripherals = peripheral.getNames()
|
|
|
|
playing = false
|
|
|
|
if #peripherals < 0 then
|
|
|
|
print "No drive"
|
|
|
|
else
|
|
|
|
driveCount = 0
|
|
|
|
for n = 1, #peripherals do
|
|
|
|
local driveCheck = peripherals[n]
|
|
|
|
if peripheral.getType(driveCheck) == "drive" then
|
|
|
|
drive = driveCheck
|
|
|
|
driveCount = driveCount + 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if driveCount > 1 then
|
2021-05-06 17:34:43 +00:00
|
|
|
print("Too many disk drives. Specify where the disk drive is by running Rhythmblock with the argument")
|
2021-05-06 14:22:19 +00:00
|
|
|
os.exit()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-05-06 17:34:43 +00:00
|
|
|
defaultStatus = "Rhythmblock 0.0.1a"
|
|
|
|
invalidFormatStatus = "Not a music disc"
|
|
|
|
noDiscStatus = "No disc"
|
|
|
|
notPlayingStatus ="No disc playing"
|
|
|
|
noDiscInDriveStatus = "No disc in drive"
|
|
|
|
status = defaultStatus
|
2021-05-06 14:22:19 +00:00
|
|
|
|
|
|
|
function playDisc()
|
|
|
|
|
|
|
|
if disk.isPresent(drive) and disk.hasAudio(drive) then
|
|
|
|
disk.playAudio(drive)
|
|
|
|
status = disk.getAudioTitle(drive)
|
|
|
|
playing = true
|
|
|
|
elseif disk.isPresent(drive) then
|
2021-05-06 17:34:43 +00:00
|
|
|
status = "Not a music disc"
|
2021-05-06 14:22:19 +00:00
|
|
|
else
|
2021-05-06 17:34:43 +00:00
|
|
|
print("No disc")
|
2021-05-06 14:22:19 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function ejectDisc()
|
|
|
|
disk.eject()
|
|
|
|
end
|
|
|
|
|
|
|
|
function stopDisc()
|
|
|
|
if playing == true then
|
|
|
|
disk.stopAudio()
|
2021-05-06 17:34:43 +00:00
|
|
|
playing = 0
|
|
|
|
status = defaultStatus
|
2021-05-06 14:22:19 +00:00
|
|
|
else
|
|
|
|
status = "No disc is playing"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function renderPlayButton()
|
2021-05-06 17:34:43 +00:00
|
|
|
paintutils.drawFilledBox(centerWidth - 3, centerHeight - 4, centerWidth + 2, centerHeight + 2, accentColor)
|
|
|
|
paintutils.drawLine(centerWidth - 2, centerHeight - 3, centerWidth - 2, centerHeight + 1, buttonColor)
|
|
|
|
paintutils.drawLine(centerWidth - 1, centerHeight - 2, centerWidth - 1, centerHeight, buttonColor)
|
|
|
|
paintutils.drawPixel(centerWidth + 1, centerHeight)
|
|
|
|
end
|
|
|
|
|
|
|
|
renderPlayButton()
|