From 82526665364389d92e0f2c33eba04678275863bb Mon Sep 17 00:00:00 2001 From: David Vazgenovich Shakaryan Date: Tue, 27 Jan 2026 01:12:16 -0800 Subject: on-demand calculation and update of option info Using metatables to calculate info strings on render, we can avoid precomputing it for all options when generating the menu, making certain menus open much faster. This also allows us to update dynamic info, e.g. the currently programme, while the menu is open. --- catalogue.lua | 87 +++++++++++++++++++---------------------------------------- 1 file changed, 28 insertions(+), 59 deletions(-) (limited to 'catalogue.lua') diff --git a/catalogue.lua b/catalogue.lua index cf9d897..7f83e82 100644 --- a/catalogue.lua +++ b/catalogue.lua @@ -14,13 +14,6 @@ function catalogue.new() id = 'root', name = '/', }) - t:add({ - type = 'group', - id = 'favourites', - parent_id = 'root', - name = 'Favourites', - lazy = true, -- prevent infinite recursion on search - }) return t end @@ -50,7 +43,7 @@ end function mt:add(entry) self.data[entry.id] = entry - if entry.type == 'group' then + if entry.type == 'group' and not entry.children_f then entry.children = {} end @@ -76,57 +69,6 @@ function mt:add(entry) return entry end -function mt:load_xc_section(section) - self:add({ - section = section.id, - type = 'group', - group_type = 'category', - id = section.id .. ':category:0', - parent_id = 'root', - name = section.name, - }) - - -- currently, this will not correctly handle subcategories which come - -- before their parent category - for _, v in ipairs(section.categories) do - self:add({ - section = section.id, - type = 'group', - group_type = 'category', - id = section.id .. ':category:' .. v.category_id, - parent_id = section.id .. ':category:' .. v.parent_id, - name = util.strip(v.category_name), - }) - end - - for _, v in ipairs(section.elements) do - local vv = { - section = section.id, - parent_id = section.id .. ':category:' .. - v.category_id, - name = util.strip(v.name), - } - - if section.type == 'series' then - vv.type = 'group' - vv.group_type = 'series' - vv.id = section.id .. ':series:' .. v.series_id - vv.series_id = v.series_id - vv.img_url = util.strip_ne(v.cover) - vv.lazy = true -- avoid API calls on search - else - vv.type = 'stream' - vv.id = section.id .. ':stream:' .. v.stream_id - vv.stream_type = v.stream_type - vv.stream_id = v.stream_id - vv.img_url = util.strip_ne(v.stream_icon) - vv.epg_channel_id = util.strip_ne(v.epg_channel_id) - end - - self:add(vv) - end -end - function mt:path_to_root(entry) local path = {} @@ -153,4 +95,31 @@ function mt:path_from_root(entry) return path end +function mt:group_count(group) + if group.count then + return group.count + end + + if group.count_f then + return group.count_f(group) + end + + local count = 0 + -- only children, not children_f, is considered here. dynamically + -- loaded groups will have a count of 0 unless count or count_f is + -- specified. + for _, v in ipairs(group.children or {}) do + if v.type == 'group' then + count = count + (v.count or mt:group_count(v) or 0) + else + count = count + 1 + end + end + return count +end + +function mt:group_children(group) + return group.children_f and group.children_f(group) or group.children +end + return catalogue -- cgit v1.2.3-70-g09d2