+ infinite scroll to songwheel

This commit is contained in:
FajsiEx 2021-07-30 20:18:03 +02:00
parent fdff69f762
commit a2520877dd
1 changed files with 21 additions and 2 deletions

View File

@ -74,6 +74,23 @@ function draw_number(x, y, alpha, num, digits, images, is_dim, scale, kern)
end end
end end
function getCorrectedIndex(from, offset)
total = #songwheel.songs;
index = from + offset;
if index < 1 then
index = total + (from+offset) -- this only happens if the offset is negative
end;
if index > total then
indexesUntilEnd = total - from;
index = offset - indexesUntilEnd -- this only happens if the offset is positive
end;
return index;
end;
function getJacketImage(song) function getJacketImage(song)
if not jacketCache[song.id] then if not jacketCache[song.id] then
jacketCache[song.id] = gfx.CreateImage(song.difficulties[1].jacketPath, 0) jacketCache[song.id] = gfx.CreateImage(song.difficulties[1].jacketPath, 0)
@ -129,7 +146,8 @@ function drawSongList()
local i=1; local i=1;
while (i <= numOfSongsAround) do while (i <= numOfSongsAround) do
drawSong(songwheel.songs[selectedIndex-i], desh/2-172/2-172*i) local songIndex = getCorrectedIndex(selectedIndex, -i)
drawSong(songwheel.songs[songIndex], desh/2-172/2-172*i)
i=i+1; i=i+1;
end; end;
@ -138,7 +156,8 @@ function drawSongList()
i=1; i=1;
while (i <= numOfSongsAround) do while (i <= numOfSongsAround) do
drawSong(songwheel.songs[selectedIndex+i], desh/2-172/2+172*i) local songIndex = getCorrectedIndex(selectedIndex, i)
drawSong(songwheel.songs[songIndex], desh/2-172/2+172*i)
i=i+1; i=i+1;
end; end;
end end