Compare commits

...

2 commits

View file

@ -1,32 +1,32 @@
-- Change these lines to change the GUI colors.
accentColor = colors.gray
buttonColor = colors.lightGray
textColor = colors.lightGray
altTextColor = colors.gray
backgroundColor = colors.black
local accentColor = colors.gray
local buttonColor = colors.lightGray
local textColor = colors.lightGray
local altTextColor = colors.gray
local backgroundColor = colors.black
-- Code starts from here
function round(n) -- We need a function to round the center of the terminal
return n % 1 >= 0.5 and math.ceil(n) or math.floor(n)
end
width, height = term.getSize() -- Gets the terminal size to determine the center
centerWidth = round(width / 2) -- Defines the horizontal center
centerHeight = round(height / 2) -- Defines the vertical center
local width, height = term.getSize() -- Gets the terminal size to determine the center
local centerWidth = round(width / 2) -- Defines the horizontal center
local centerHeight = round(height / 2) -- Defines the vertical center
if arg[1] == nil then
peripherals = peripheral.getNames() -- Gets peripherals to check if any disk drives are avavailable
local peripherals = peripheral.getNames() -- Gets peripherals to check if any disk drives are avavailable
if #peripherals == 0 then
term.setTextColor(colors.red)
print "No drive"
print("No drive")
return false -- Exits if there's no disk drive
else
driveCount = 0
for n = 1, #peripherals do
local driveCheck = peripherals[n]
if peripheral.getType(driveCheck) == "drive" then
drive = driveCheck
driveCount = driveCount + 1
local drive = driveCheck
local driveCount = driveCount + 1
end
end
if driveCount > 1 then
@ -35,7 +35,7 @@ if arg[1] == nil then
return false
elseif driveCount == 0 then
term.setTextColor(colors.red)
print "No drive"
print("No drive")
return false -- Exits if there's no disk drive
end
end
@ -46,25 +46,25 @@ end
--[[ Instead of calling every status by string, we call the variables storing the strings. This may ease translation if we plan to do it in the future.
]]
defaultStatus = "Rhythmblock"
invalidFormatStatus = "Not a music disc"
noDiscStatus = "No disc"
noAudioStatus = "No audio is playing"
ejectText = "Eject"
local defaultStatus = "Rhythmblock"
local invalidFormatStatus = "Not a music disc"
local noDiscStatus = "No disc"
local noAudioStatus = "No audio is playing"
local ejectText = "Eject"
function playDisc()
term.clear()
if disk.isPresent(drive) and disk.hasAudio(drive) then -- Determines if there's a disc or not and if it's a music disc
disk.playAudio(drive)
buttonRender(true)
playing = true
status = disk.getAudioTitle(drive)
local playing = true
local status = disk.getAudioTitle(drive)
buttonRender(true)
elseif disk.isPresent(drive) then
status = invalidFormatStatus
local status = invalidFormatStatus
buttonRender(false)
else -- If none of these checks are passed then it just means there's no disc in the drive.
status = noDiscStatus
local status = noDiscStatus
buttonRender(false)
end
end
@ -72,19 +72,19 @@ end
function ejectDisc() -- Ejects the disc! How cool is that?
term.clear()
buttonRender(false)
if playing == true then
if playing then
stopDisc()
disk.eject()
elseif disk.isPresent(drive) then -- If there's a disc, it'll be ejected.
disk.eject(drive)
else -- If not it'll report there's no disc.
status = noDiscStatus
local status = noDiscStatus
end
end
function stopDisc() -- Stops the music
playing = false
status = defaultStatus
local status = defaultStatus
disk.stopAudio(drive)
term.clear()
buttonRender(false)
@ -118,7 +118,7 @@ function renderCloseButton() -- Renders the Close button
end
function buttonRender(play) -- Render some buttons depending if the computer is advanced or not
if play == true then
if play then
renderStopButton()
else
renderPlayButton()
@ -139,7 +139,7 @@ end
term.clear()
term.setBackgroundColor(backgroundColor) -- Setting the background color
buttonRender(false)
status = defaultStatus -- Setting the value to the default
local status = defaultStatus -- Setting the value to the default
while true do
statusRender(status) -- Renders the status
@ -148,7 +148,7 @@ while true do
if event == "mouse_up" then -- If the event triggered is the mouse clicking it'll do what's next
if eventData[2] == 1 and eventData[3] >= centerWidth - 4 and eventData[4] >= centerHeight - 4 and eventData[3] <= centerWidth + 4 and eventData[4] <= centerHeight + 2 then -- If the user clicks on the play/stop button it'll begin playing the disc
if playing == true then
if playing then
stopDisc()
else
playDisc()
@ -163,7 +163,7 @@ while true do
elseif event == "key_up" then -- Same order but now with keys
local name = keys.getName(eventData[2]) or "unknown key"
if name == "space" then
if playing == true then
if playing then
stopDisc()
else
playDisc()