Rhythmblock/rhythmblock.lua

74 lines
1.8 KiB
Lua
Raw Normal View History

2021-05-06 14:22:19 +00:00
accentColor = colors.gray
buttonColor = colors.lightGray
textColor = colors.lightGray
altTextColor = colors.gray
2021-05-06 14:22:19 +00:00
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)
2021-05-07 04:48:14 +00:00
centerHeight = round(height / 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()
2021-05-07 04:48:14 +00:00
if disk.isPresent(drive) and disk.hasAudio(drive) then
2021-05-06 14:22:19 +00:00
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 - 4, centerHeight - 4, centerWidth + 4, centerHeight + 2, accentColor)
2021-05-07 04:48:14 +00:00
paintutils.drawFilledBox(centerWidth - 2, centerHeight - 3, centerWidth - 1, centerHeight + 1, buttonColor)
paintutils.drawFilledBox(centerWidth, centerHeight - 2, centerWidth + 1, centerHeight, buttonColor)
paintutils.drawPixel(centerWidth + 2, centerHeight - 1, buttonColor)
end
2021-05-06 17:48:36 +00:00
playDisc()