-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.lua
77 lines (67 loc) · 1.45 KB
/
main.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
local LoveGme = require "lovegme"
local gme
local pause = false
local currentPath = "no file"
local report = "drag a supported file here to play it\nuse left and right keys to go through tracks\nuse p to pause"
function love.load(args)
gme = LoveGme()
local path = args[1]
if path then openFile(love.filesystem.newFile(path)) end
updateTitle()
end
function love.update()
gme:update()
end
function love.draw()
love.graphics.print(report, 10,10)
end
function love.keypressed(key)
if key == "left" then
local next_track = gme.current_track - 1
if next_track < 0 then
next_track = gme.track_count - 1 -- last track
end
gme:setTrack(next_track)
gme:play()
elseif key == "right" then
local next_track = gme.current_track + 1
if next_track >= gme.track_count then
next_track = 0 -- first track
end
gme:setTrack(next_track)
gme:play()
elseif key == 'p' then
pause = not pause
if pause then
gme:pause()
else
gme:play()
end
end
updateTitle()
end
function love.filedropped(file)
openFile(file)
end
function updateTitle()
love.window.setTitle("LoveGme Player: "
..(currentPath:match("^.+/(.+)$") or "no file")
.." "..(gme.current_track+1)
.."/"..gme.track_count
)
end
function openFile(file)
if file then
gme:loadFile(file)
gme:play()
currentPath = file:getFilename()
updateTitle()
genReport()
end
end
function genReport()
report = ""
for k, v in pairs(gme.info) do
report = report ..k..": "..v.."\n"
end
end