1
0
Fork 0
mirror of https://fem.mint.lgbt/m/Rhythmblock.git synced 2024-08-14 20:27:11 +00:00

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

View file

@ -1,32 +1,32 @@
-- Change these lines to change the GUI colors.
local accentColor = colors.gray
local buttonColor = colors.lightGray
local textColor = colors.lightGray
local altTextColor = colors.gray
local backgroundColor = colors.black
accentColor = colors.gray
buttonColor = colors.lightGray
textColor = colors.lightGray
altTextColor = colors.gray
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
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
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
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
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
local drive = driveCheck
local driveCount = driveCount + 1
drive = driveCheck
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.
]]
local defaultStatus = "Rhythmblock"
local invalidFormatStatus = "Not a music disc"
local noDiscStatus = "No disc"
local noAudioStatus = "No audio is playing"
local ejectText = "Eject"
defaultStatus = "Rhythmblock"
invalidFormatStatus = "Not a music disc"
noDiscStatus = "No disc"
noAudioStatus = "No audio is playing"
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)
local playing = true
local status = disk.getAudioTitle(drive)
playing = true
status = disk.getAudioTitle(drive)
buttonRender(true)
elseif disk.isPresent(drive) then
local status = invalidFormatStatus
status = invalidFormatStatus
buttonRender(false)
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)
end
end
@ -72,19 +72,19 @@ end
function ejectDisc() -- Ejects the disc! How cool is that?
term.clear()
buttonRender(false)
if playing then
if playing == true 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.
local status = noDiscStatus
status = noDiscStatus
end
end
function stopDisc() -- Stops the music
playing = false
local status = defaultStatus
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 then
if play == true then
renderStopButton()
else
renderPlayButton()
@ -139,7 +139,7 @@ end
term.clear()
term.setBackgroundColor(backgroundColor) -- Setting the background color
buttonRender(false)
local status = defaultStatus -- Setting the value to the default
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 then
if playing == true 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 then
if playing == true then
stopDisc()
else
playDisc()