Changed ScreenSelectMusic and Song to look for preview.ogg and use it for a sample if it exists instead of the music file. Sample length still comes from simfile. Changed foreach_ordered to work on tables with string and number keys.
This commit is contained in:
@@ -6,14 +6,26 @@ Note that this is a namespace, not a class per se.
|
||||
|
||||
-- TODO: move this into a more general section
|
||||
-- func takes a key and a value
|
||||
function foreach_by_sorted_keys(tbl, keys, func)
|
||||
table.sort(keys)
|
||||
for _, key in ipairs(keys) do func(key, tbl[key]) end
|
||||
end
|
||||
|
||||
function foreach_ordered( tbl, func )
|
||||
local keys = { }
|
||||
for k,_ in pairs(tbl) do keys[#keys+1] = k end
|
||||
|
||||
table.sort( keys )
|
||||
|
||||
local string_keys= {}
|
||||
local number_keys= {}
|
||||
-- First person to to use this on a table that uses something else as keys
|
||||
-- gets to extend this function to cover more types. And a beating. -Kyz
|
||||
for k,_ in pairs(tbl) do
|
||||
if type(k) == "string" then
|
||||
table.insert(string_keys, k)
|
||||
elseif type(k) == "number" then
|
||||
table.insert(number_keys, k)
|
||||
end
|
||||
end
|
||||
-- iterate in sorted order
|
||||
for _,key in ipairs(keys) do func( key, tbl[key]) end
|
||||
foreach_by_sorted_keys(tbl, number_keys, func)
|
||||
foreach_by_sorted_keys(tbl, string_keys, func)
|
||||
end
|
||||
|
||||
-- redeclared here for my sanity's sake
|
||||
|
||||
Reference in New Issue
Block a user