diff options
| -rw-r--r-- | main.lua | 31 |
1 files changed, 16 insertions, 15 deletions
@@ -178,25 +178,26 @@ local function push_menu(t) end local function sort_options(options) - table.sort(options, function(a, b) - local a_name = a.name - local b_name = b.name - - if favourites[a.id] then - a_name = '\0\0' .. a_name + local scores = {} + for _, v in ipairs(options) do + local score = 0 + if favourites[v.id] then + score = score + 2 end - if a.type == 'group' and a.group_type ~= 'series' then - a_name = '\0' .. a_name + if v.type == 'group' and v.group_type ~= 'series' then + score = score + 1 end + scores[v] = score + end - if favourites[b.id] then - b_name = '\0\0' .. b_name - end - if b.type == 'group' and b.group_type ~= 'series' then - b_name = '\0' .. b_name + table.sort(options, function(a, b) + local sa = scores[a] + local sb = scores[b] + if sa ~= sb then + return sa > sb + else + return a.name < b.name end - - return a_name < b_name end) end |
