WOAH THAT'S A LOT OF PROGRESS
This commit is contained in:
parent
34cbbdae9f
commit
b8f1445f11
136
rhythmblock.lua
136
rhythmblock.lua
|
@ -1,20 +1,20 @@
|
||||||
|
-- Change these lines to change the GUI colors.
|
||||||
accentColor = colors.gray
|
accentColor = colors.gray
|
||||||
buttonColor = colors.lightGray
|
buttonColor = colors.lightGray
|
||||||
textColor = colors.lightGray
|
textColor = colors.lightGray
|
||||||
altTextColor = colors.gray
|
altTextColor = colors.gray
|
||||||
backgroundColor = colors.black
|
backgroundColor = colors.black
|
||||||
|
|
||||||
function round(n)
|
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
|
||||||
width, height = term.getSize()
|
centerWidth = round(width / 2) -- Defines the horizontal center
|
||||||
centerWidth = round(width / 2)
|
centerHeight = round(height / 2) -- Defines the vertical center
|
||||||
centerHeight = round(height / 2)
|
peripherals = peripheral.getNames() -- Gets peripherals to check if any disk drives are avavailable
|
||||||
peripherals = peripheral.getNames()
|
|
||||||
playing = false
|
|
||||||
if #peripherals < 0 then
|
if #peripherals < 0 then
|
||||||
print "No drive"
|
print "No drive"
|
||||||
|
os.exit() -- Exits if there's no disk drive
|
||||||
else
|
else
|
||||||
driveCount = 0
|
driveCount = 0
|
||||||
for n = 1, #peripherals do
|
for n = 1, #peripherals do
|
||||||
|
@ -25,49 +25,125 @@ else
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if driveCount > 1 then
|
if driveCount > 1 then
|
||||||
print("Too many disk drives. Specify where the disk drive is by running Rhythmblock with the argument")
|
print("Too many disk drives. Specify where the disk drive is by running rhythmbox [drive position]") -- For safety reasons
|
||||||
os.exit()
|
os.exit()
|
||||||
end
|
end
|
||||||
end
|
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 0.0.1a"
|
defaultStatus = "Rhythmblock 0.0.1a"
|
||||||
invalidFormatStatus = "Not a music disc"
|
invalidFormatStatus = "Not a music disc"
|
||||||
noDiscStatus = "No disc"
|
noDiscStatus = "No disc"
|
||||||
notPlayingStatus ="No disc playing"
|
ejectText = "Eject"
|
||||||
noDiscInDriveStatus = "No disc in drive"
|
|
||||||
status = defaultStatus
|
|
||||||
|
|
||||||
function playDisc()
|
function playDisc()
|
||||||
if disk.isPresent(drive) and disk.hasAudio(drive) then
|
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)
|
||||||
status = disk.getAudioTitle(drive)
|
renderStopButton()
|
||||||
playing = true
|
playing = true
|
||||||
elseif disk.isPresent(drive) then
|
status = disk.getAudioTitle(drive)
|
||||||
status = "Not a music disc"
|
elseif disk.isPresent(drive) then -- If there's a floppy disk for example, Rhythmbox won't play it.
|
||||||
else
|
status = invalidFormatStatus
|
||||||
print("No disc")
|
else -- If none of these checks are passed then it just means there's no disc in the drive.
|
||||||
|
status = noDiscStatus
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function ejectDisc()
|
function ejectDisc() -- Ejects the disc! How cool is that?
|
||||||
disk.eject()
|
|
||||||
end
|
|
||||||
|
|
||||||
function stopDisc()
|
|
||||||
if playing == true then
|
if playing == true then
|
||||||
disk.stopAudio()
|
stopDisc()
|
||||||
playing = 0
|
disk.eject()
|
||||||
status = defaultStatus
|
elseif disk.isPresent(drive) then -- If there's a disc, it'll be ejected.
|
||||||
else
|
disk.eject()
|
||||||
status = "No disc is playing"
|
else -- If not it'll report there's no disc.
|
||||||
end
|
status = noDiscStatus
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function renderPlayButton()
|
function stopDisc() -- Stops the music
|
||||||
|
disk.stopAudio()
|
||||||
|
renderPlayButton()
|
||||||
|
playing = false
|
||||||
|
status = defaultStatus
|
||||||
|
end
|
||||||
|
|
||||||
|
function renderPlayButton() -- Renders the Play button
|
||||||
paintutils.drawFilledBox(centerWidth - 4, centerHeight - 4, centerWidth + 4, centerHeight + 2, accentColor)
|
paintutils.drawFilledBox(centerWidth - 4, centerHeight - 4, centerWidth + 4, centerHeight + 2, accentColor)
|
||||||
paintutils.drawFilledBox(centerWidth - 2, centerHeight - 3, centerWidth - 1, centerHeight + 1, buttonColor)
|
paintutils.drawFilledBox(centerWidth - 2, centerHeight - 3, centerWidth - 1, centerHeight + 1, buttonColor)
|
||||||
paintutils.drawFilledBox(centerWidth, centerHeight - 2, centerWidth + 1, centerHeight, buttonColor)
|
paintutils.drawFilledBox(centerWidth, centerHeight - 2, centerWidth + 1, centerHeight, buttonColor)
|
||||||
paintutils.drawPixel(centerWidth + 2, centerHeight - 1, buttonColor)
|
paintutils.drawPixel(centerWidth + 2, centerHeight - 1, buttonColor)
|
||||||
end
|
end
|
||||||
|
|
||||||
playDisc()
|
|
||||||
|
function renderStopButton() -- Renders the Stop button
|
||||||
|
paintutils.drawFilledBox(centerWidth - 4, centerHeight - 4, centerWidth + 4, centerHeight + 2, accentColor)
|
||||||
|
paintutils.drawFilledBox(centerWidth - 2, centerHeight - 3, centerWidth + 1, centerHeight + 1, buttonColor)
|
||||||
|
end
|
||||||
|
|
||||||
|
function renderEjectButton() -- Renders the Eject button
|
||||||
|
paintutils.drawLine(centerWidth - 2, centerHeight + 4, centerWidth + 2, centerHeight + 4, buttonColor)
|
||||||
|
term.setTextColor(buttonColor)
|
||||||
|
term.setCursorPos(centerWidth - 2, centerHeight + 4)
|
||||||
|
term.write(ejectText)
|
||||||
|
statusPos()
|
||||||
|
end
|
||||||
|
|
||||||
|
function statusPos() -- Resets the status position
|
||||||
|
term.setCursorPos(1, 1)
|
||||||
|
term.setTextColor(textColor)
|
||||||
|
end
|
||||||
|
|
||||||
|
function clickListen()
|
||||||
|
local event, button, x, y = os.pullEvent("mouse_up")
|
||||||
|
if button == 1 and x >= centerWidth - 4 and y >= centerHeight - 4 and x <= centerWidth + 4 and y <= centerHeight + 2 then
|
||||||
|
if playing == true then
|
||||||
|
stopDisc()
|
||||||
|
else
|
||||||
|
playDisc()
|
||||||
|
end
|
||||||
|
elseif button == 1 and x >= centerWidth - 2 and y >= centerHeight + 4 and x <= centerWidth + 2 and y <= centerHeight + 4 then
|
||||||
|
ejectDisc()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function touchEvent()
|
||||||
|
local event, side, x, y = os.pullEvent("monitor_touch")
|
||||||
|
if x >= centerWidth - 4 and y >= centerHeight - 4 and x <= centerWidth + 4 and y <= centerHeight + 2 then
|
||||||
|
if playing == true then
|
||||||
|
stopDisc()
|
||||||
|
else
|
||||||
|
playDisc()
|
||||||
|
end
|
||||||
|
elseif x >= centerWidth - 2 and y >= centerHeight + 4 and x <= centerWidth + 2 and y <= centerHeight + 4 then
|
||||||
|
ejectDisc()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function keyEvent()
|
||||||
|
local event, key = os.pullEvent("key_up")
|
||||||
|
local name = keys.getName(key) or "unknown key"
|
||||||
|
|
||||||
|
if name == "space" then
|
||||||
|
if playing == true then
|
||||||
|
stopDisc()
|
||||||
|
else
|
||||||
|
playDisc()
|
||||||
|
end
|
||||||
|
elseif name == "q" then
|
||||||
|
os.exit()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
term.setBackgroundColor(backgroundColor) -- Setting the background color
|
||||||
|
renderPlayButton() -- Rendering the play button
|
||||||
|
renderEjectButton() -- Rendering the eject button
|
||||||
|
status = defaultStatus --Setting the
|
||||||
|
term.clear()
|
||||||
|
while true do
|
||||||
|
term.write(status)
|
||||||
|
spawn(clickListen)
|
||||||
|
spawn(touchListen)
|
||||||
|
spawn(keyListen)
|
||||||
|
end
|
||||||
|
|
Loading…
Reference in a new issue