Skip to content

Commit

Permalink
version 2.0 (delta)
Browse files Browse the repository at this point in the history
[added] dos.fnt (really marble madness font from idleberg/playdate-arcade-fonts)
[added] skipping of files cursor
[added] dark mode / light mode toggle
[added] time / battery percentage in now playing menu
[added] version in corner
[added] doesn't auto-lock
[added] key repeat
[changed] rounded corners of file selection list
[changed] format of onPlayingScreen to screenMode, which is now int instead of bool
[changed] constants used to draw colors are now set based on if dark/light mode is active
[removed] some pesky little bugs
  • Loading branch information
Aiden committed Aug 29, 2022
1 parent 568ef53 commit 18280bc
Show file tree
Hide file tree
Showing 4 changed files with 240 additions and 35 deletions.
Binary file modified src/SystemAssets/card-pressed.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
105 changes: 105 additions & 0 deletions src/fnt/dos.fnt
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
--metrics={"baseline":7,"xHeight":0,"capHeight":0,"pairs":{},"left":[],"right":[]}
datalen=2188
data=iVBORw0KGgoAAAANSUhEUgAAAFAAAABQCAYAAACOEfKtAAAGMElEQVR4Xu2c23YbOwxD2///6J46K+PDoQliU6PYTlf6ZFs3CgRBKA/9/ev/f3/C59/hc/x4zMnjce0xP86pxm/zun2OsZW1cW+13s1x8X+M5yBv3wlI1ebutwNYsr+KTeRVxnybX50Xf7s0rgDLm+YsKobGgDuGKeZV8TgGqoRQsJ8CoGNPBs6VZ8cwAkjFoAxYlWTK/hy/TCJloANwwtBcVkSjMjiTEqSxUwk6xT/RQKcnFevcGsKSSyUWkHfsowCe9lGdhnTZAzDCINelI8M6wOI81CUBgJX8uBK+n901AyXCP78HBFYAvDHE+USXwSMEx/TOC7q1+QzXzTsmyqqYAtiZ7U7YnY5VWnl1v67xVFXUdf8tAGbmxe8OoJVxqotVI9wBEDqfMjCzIdsfCpDyas77uf1XGkGUmbx/rjTZKAmAqoNWJVZlnnjNnQA6fSbWSXnVh85PAMzZjYBkK6O81IRBxJuS/a5qIDLrFEBXI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OxLksu286LH1B1N32hjHwKtl+pbrnTVAQhomOR+nBPqdwBnFOAGQlG7XbEaBvRDRKk55d1rCFLzY7aJEOIsRNeyF2N2tEK68ZwHoQIn6SWNSHm9lfWVzXMwf4/SwqwwkwbxDiY9jeCcAHcjjy4Hmllns/lz2ME4B7JoD1guHUDM+rYCVmLoEXW4iqjmsBHoBx/dbOmHgV0fvGkn3kogVorSdSEAXQ7k++sBJU9kNZiwR9YxyyXZlTgBUUiVt2BRAGkQFMF2bgYjrHEMcCUgMLhGnu7ms0i5FSuiY053ZsS+Dl8EgF38ZgORgWtZqLwVAxcD73+M2WhXaKEsG7sieawKEgSoJFegrDCQxECzuccZyIiwjcyYgZInoNIx2YSdL7g7LANISfNd5pAJc7OM9XLZe1URcN3VAPG18AqDTD0J9Vz7Khz0NkOlBUwC7/X8AnKJfWAhXehMG5r2OtWSPC1eZLd3FQCq+5PLVXm8JnmPLLBX6/+CfNKJvq4HOYxEwfzSQoNTMIWXsSpjscTHMvcv/A75kDHPOOX0PAAAAAElFTkSuQmCC
width=8
height=8

tracking=1

0 8
1 8
2 8
3 8
4 8
5 8
6 8
7 8
8 8
9 8
space 8
� 8
A 8
B 8
C 8
D 8
E 8
F 8
G 8
H 8
I 8
J 8
K 8
L 8
M 8
N 8
O 8
P 8
Q 8
R 8
S 8
T 8
U 8
V 8
W 8
X 8
Y 8
Z 8
a 8
b 8
c 8
d 8
e 8
f 8
g 8
h 8
i 8
j 8
k 8
l 8
m 8
n 8
o 8
p 8
q 8
r 8
s 8
t 8
u 8
v 8
w 8
x 8
y 8
z 8
! 5
" 5
# 6
$ 7
% 7
& 7
' 2
( 5
) 7
* 4
+ 4
, 3
- 4
. 3
/ 5
: 3
; 3
< 4
= 5
> 5
? 6
@ 7
[ 5
\ 5
] 6
^ 4
_ 5
` 4
{ 5
| 4
} 7
~ 5

166 changes: 133 additions & 33 deletions src/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,35 @@ files = playdate.file.listFiles(dir, false)
local playingGraphic = gfx.image.new("img/playing")
local pausedGraphic = gfx.image.new("img/paused")

-- dosFnt = playdate.graphics.font.new("fnt/dos")
-- playdate.graphics.setFont(dosFnt)
dosFnt = playdate.graphics.font.new("fnt/dos")

local currentAudio = playdate.sound.fileplayer.new()
local currentFilePath = ""
local currentFileName = ""
audioFiles = {}
mode = 0 -- 0 is none, 1 is shuffle, 2 is loop folder, 3 is loop song
local modeString = "none"
onPlayingScreen = false
local lastOffset = 0
local currentPos = 1
audioLen = 0
local modeString = "none"
local darkMode = true
audioFiles = {}
mode = 0 -- 0 is none, 1 is shuffle, 2 is loop folder, 3 is loop song
screenMode = 0 -- 0 is files, 1 is playing, 2 is settings
audioLen = 0
keyTimer = nil

bgColor = gfx.kColorBlack
color = gfx.kColorWhite
dMColor1 = gfx.kDrawModeFillWhite
dMColor2 = gfx.kDrawModeCopy

print("Hey there, friend!")
print("----------------------------------------------------")
print("Hey there, friend! Have fun debugging / hacking my app! :D")
print("----------------------------------------------------")

gfx.setColor(gfx.kColorWhite)
gfx.setColor(color)
gfx.clear(bgColor)
gfx.setImageDrawMode(dMColor1)
gfx.drawText("no files!",0,0)
gfx.setImageDrawMode(dMColor2)

local menu = playdate.getSystemMenu()

Expand All @@ -50,9 +61,30 @@ function handleMode(str) -- add queue mode
end

local playingMenuItem, error = menu:addMenuItem("now playing", function()
onPlayingScreen = not onPlayingScreen
if screenMode == 0 then
screenMode = 1
else
screenMode = 0
end
end)
local modeMenuItem, error = menu:addOptionsMenuItem("mode", {"none","shuffle","loop folder","loop one"}, "none", handleMode)
local colorModeMenuItem, error = menu:addCheckmarkMenuItem("dark", darkMode, function ()
if darkMode == true then
bgColor = gfx.kColorWhite
color = gfx.kColorBlack
dMColor1 = gfx.kDrawModeCopy
dMColor2 = gfx.kDrawModeFillWhite
gfx.setColor(color)
darkMode = false
else
bgColor = gfx.kColorBlack
color = gfx.kColorWhite
dMColor1 = gfx.kDrawModeFillWhite
dMColor2 = gfx.kDrawModeCopy
gfx.setColor(color)
darkMode = true
end
end)

fileList = playdate.ui.gridview.new(0, 10)
fileList.backgroundImage = playdate.graphics.nineSlice.new('img/scrollimg', 20, 23, 92, 20)
Expand All @@ -65,15 +97,16 @@ function fileList:drawCell(section, row, column, selected, x, y, width, height)
if files[row] ~= nil then
if selected then
gfx.fillRoundRect(x, y, width, 20, 4)
gfx.setImageDrawMode(gfx.kDrawModeCopy)
gfx.setImageDrawMode(dMColor2)
else
gfx.setImageDrawMode(gfx.kDrawModeFillWhite)
gfx.setImageDrawMode(dMColor1)
end

gfx.drawText(files[row], x+4, y+2, width, height, nil, "...")
end
end


if files[1] == nil then
table.insert(files,"no files!")
playdate.stop()
Expand All @@ -82,19 +115,23 @@ end

function playdate.update()
playdate.timer.updateTimers()
gfx.clear(gfx.kColorBlack)
gfx.clear(bgColor)

gfx.setImageDrawMode(gfx.kDrawModeNXOR)
if currentAudio:isPlaying() == true then
playingGraphic:draw(0,220)
else
pausedGraphic:draw(0,220)
end
gfx.setImageDrawMode(gfx.kDrawModeFillWhite)
gfx.setImageDrawMode(dMColor1)

-- playdate.drawFPS(0,0)

if screenMode == 0 then
dosFnt:drawTextAligned("musik "..playdate.metadata.version.." delta", 400, 232, kTextAlignment.right, nil)

if onPlayingScreen == false then
playingMenuItem:setTitle("now playing")
gfx.drawRect(20,13,360,209)
gfx.drawRoundRect(20,13,360,209,4)

curRow = fileList:getSelectedRow()
files = playdate.file.listFiles(dir, false)
Expand All @@ -104,10 +141,22 @@ function playdate.update()
fileList:drawInRect(0, 0, 400, 230)
end

if playdate.buttonJustPressed(playdate.kButtonDown) then
fileList:selectNextRow(true)
elseif playdate.buttonJustPressed(playdate.kButtonUp) then
fileList:selectPreviousRow(true)
if playdate.buttonJustPressed(playdate.kButtonRight) then
local selRow = fileList:getSelectedRow()
if selRow <= #files-4 then
fileList:setSelectedRow(selRow+4)
else
fileList:setSelectedRow(#files)
end
fileList:scrollToRow(fileList:getSelectedRow())
elseif playdate.buttonJustPressed(playdate.kButtonLeft) then
local selRow = fileList:getSelectedRow()
if selRow > 5 then
fileList:setSelectedRow(selRow-4)
else
fileList:setSelectedRow(1)
end
fileList:scrollToRow(fileList:getSelectedRow())
elseif playdate.buttonJustPressed(playdate.kButtonA) then
if playdate.file.isdir(dir..files[curRow]) == true then
audioFiles = {}
Expand All @@ -125,14 +174,7 @@ function playdate.update()
fileList:setNumberOfRows(#files)
else
if dir..files[curRow] == currentFilePath then
-- if currentAudio:isPlaying() == true then
-- lastOffset = currentAudio:getOffset()
-- currentAudio:pause()
-- else
-- currentAudio:setOffset(lastOffset)
-- currentAudio:play()
-- end
onPlayingScreen = true
screenMode = 1
else
if string.find(files[curRow],"%.mp3") ~= nil or string.find(files[curRow],"%.pda") ~= nil then
for i=1,#files do
Expand All @@ -146,14 +188,16 @@ function playdate.update()

if currentAudio:isPlaying() == true then
currentAudio:stop()
playdate.setAutoLockDisabled(false)
end

currentAudio:load(dir..files[curRow])
audioLen = currentAudio:getLength()
currentAudio:play()
playdate.setAutoLockDisabled(true)

currentFileName = files[curRow]
onPlayingScreen = true
screenMode = 1
end
end
end
Expand All @@ -168,18 +212,39 @@ function playdate.update()
fileList:setSelectedRow(1)
end
end
else
elseif screenMode == 1 then
playingMenuItem:setTitle("files")
gfx.setImageDrawMode(gfx.kDrawModeFillWhite)
gfx.setImageDrawMode(dMColor1)
audioLen = currentAudio:getLength()
if audioLen ~= nil then
gfx.drawTextInRect(currentFileName,0,0,400,240,nil,nil,kTextAlignment.center,nil)
gfx.drawTextInRect((formatSeconds(currentAudio:getOffset()).." / "..formatSeconds(audioLen)),0,220,400,20,nil,nil,kTextAlignment.center,nil)
else
gfx.drawTextInRect("nothing playing",0,220,400,20,nil,nil,kTextAlignment.center,nil)
end
local time = playdate.getTime()
if #tostring(time["hour"]) == 1 then
time["hour"] = "0"..time["hour"]
end

if #tostring(time["minute"]) == 1 then
time["minute"] = "0"..time["minute"]
end

local batteryPercent = playdate.getBatteryPercentage()

if string.find(batteryPercent,"100.") then
batteryPercent = "100"
else
batteryPercent = string.sub(string.gsub(batteryPercent,"%.",""),1,2)
end

local size = gfx.getTextSize(batteryPercent.."%",dosFnt)

dosFnt:drawTextAligned(time["hour"]..":"..time["minute"],0,0,400,20,kTextAlignment.left,nil)
dosFnt:drawTextAligned(batteryPercent.."%",400-size,0,400,20,kTextAlignment.right,nil)
gfx.drawTextInRect(modeString,0,220,400,20,nil,nil,kTextAlignment.right,nil)
gfx.setImageDrawMode(gfx.kDrawModeCopy)
gfx.setImageDrawMode(dMColor2)

if playdate.buttonJustPressed(playdate.kButtonLeft) then
if currentAudio:getOffset()-5 ~= audioLen then
Expand All @@ -204,13 +269,15 @@ function playdate.update()
if currentAudio:isPlaying() == true then
lastOffset = currentAudio:getOffset()
currentAudio:pause()
playdate.setAutoLockDisabled(false)
else
currentAudio:setOffset(lastOffset)
currentAudio:play()
playdate.setAutoLockDisabled(true)
end
end
elseif playdate.buttonJustPressed(playdate.kButtonB) then
onPlayingScreen = false
screenMode = 0
end
end
end
Expand Down Expand Up @@ -260,6 +327,7 @@ function handleSongEnd()
currentAudio:play()
else
currentFilePath = ""
playdate.setAutoLockDisabled(false)
end
end

Expand All @@ -276,4 +344,36 @@ function formatSeconds(seconds)
end
end



function playdate.downButtonDown()
local function timerCallback()
if fileList:getSelectedRow() ~= #files then
fileList:selectNextRow(true)
end
end
if screenMode == 0 then
keyTimer = playdate.timer.keyRepeatTimerWithDelay(300,50,timerCallback)
end
end

function playdate.downButtonUp()
keyTimer:remove()
end

function playdate.upButtonDown()
local function timerCallback()
if fileList:getSelectedRow() ~= 1 then
fileList:selectPreviousRow(true)
end
end
if screenMode == 0 then
keyTimer = playdate.timer.keyRepeatTimerWithDelay(300,50,timerCallback)
end
end

function playdate.upButtonUp()
keyTimer:remove()
end

currentAudio:setFinishCallback(handleSongEnd)
Loading

0 comments on commit 18280bc

Please sign in to comment.