Compare commits

...

2 commits

View file

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