Rhythmblock/rhythmblock.lua

73 lines
1.8 KiB
Lua
Raw Normal View History

2021-05-06 14:22:19 +00:00
accentColor = colors.gray
buttonColor = colors.lightGray
backgroundColor = colors.black
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()
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
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
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
status = "Not a music disc"
2021-05-06 14:22:19 +00:00
else
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()
playing = 0
status = defaultStatus
2021-05-06 14:22:19 +00:00
else
status = "No disc is playing"
end
end
function renderPlayButton()
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
2021-05-06 17:48:36 +00:00
playDisc()