Revert "formatting changes and switching to local variables"

This reverts commit 5b453593ac.
This commit is contained in:
mint 2021-05-07 14:56:15 -04:00
parent b3804e1052
commit c0df7011e5
1 changed files with 29 additions and 29 deletions

View File

@ -1,32 +1,32 @@
-- Change these lines to change the GUI colors. -- Change these lines to change the GUI colors.
local accentColor = colors.gray accentColor = colors.gray
local buttonColor = colors.lightGray buttonColor = colors.lightGray
local textColor = colors.lightGray textColor = colors.lightGray
local altTextColor = colors.gray altTextColor = colors.gray
local backgroundColor = colors.black 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
local width, height = term.getSize() -- Gets the terminal size to determine the center width, height = term.getSize() -- Gets the terminal size to determine the center
local centerWidth = round(width / 2) -- Defines the horizontal center centerWidth = round(width / 2) -- Defines the horizontal center
local centerHeight = round(height / 2) -- Defines the vertical center centerHeight = round(height / 2) -- Defines the vertical center
if arg[1] == nil then if arg[1] == nil then
local peripherals = peripheral.getNames() -- Gets peripherals to check if any disk drives are avavailable 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
local drive = driveCheck drive = driveCheck
local driveCount = driveCount + 1 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.
]] ]]
local defaultStatus = "Rhythmblock" defaultStatus = "Rhythmblock"
local invalidFormatStatus = "Not a music disc" invalidFormatStatus = "Not a music disc"
local noDiscStatus = "No disc" noDiscStatus = "No disc"
local noAudioStatus = "No audio is playing" noAudioStatus = "No audio is playing"
local ejectText = "Eject" 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)
local playing = true playing = true
local status = disk.getAudioTitle(drive) status = disk.getAudioTitle(drive)
buttonRender(true) buttonRender(true)
elseif disk.isPresent(drive) then elseif disk.isPresent(drive) then
local status = invalidFormatStatus 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.
local status = noDiscStatus 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 then if playing == true 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.
local status = noDiscStatus status = noDiscStatus
end end
end end
function stopDisc() -- Stops the music function stopDisc() -- Stops the music
playing = false playing = false
local status = defaultStatus 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 then if play == true 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)
local status = defaultStatus -- Setting the value to the default 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 then if playing == true 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 then if playing == true then
stopDisc() stopDisc()
else else
playDisc() playDisc()