Skip to content

Commit 82deed2

Browse files
authored
ContentDB: Order installed content first (#10864)
1 parent 44a9510 commit 82deed2

File tree

1 file changed

+34
-2
lines changed

1 file changed

+34
-2
lines changed

builtin/mainmenu/dlg_contentstore.lua

+34-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ if not minetest.get_http_api then
2323
return
2424
end
2525

26-
local store = { packages = {}, packages_full = {} }
26+
-- Unordered preserves the original order of the ContentDB API,
27+
-- before the package list is ordered based on installed state.
28+
local store = { packages = {}, packages_full = {}, packages_full_unordered = {} }
2729

2830
local http = minetest.get_http_api()
2931

@@ -572,6 +574,7 @@ function store.load()
572574
end
573575
end
574576

577+
store.packages_full_unordered = store.packages_full
575578
store.packages = store.packages_full
576579
store.loaded = true
577580
end
@@ -619,6 +622,33 @@ function store.update_paths()
619622
end
620623
end
621624

625+
function store.sort_packages()
626+
local ret = {}
627+
628+
-- Add installed content
629+
for i=1, #store.packages_full_unordered do
630+
local package = store.packages_full_unordered[i]
631+
if package.path then
632+
ret[#ret + 1] = package
633+
end
634+
end
635+
636+
-- Sort installed content by title
637+
table.sort(ret, function(a, b)
638+
return a.title < b.title
639+
end)
640+
641+
-- Add uninstalled content
642+
for i=1, #store.packages_full_unordered do
643+
local package = store.packages_full_unordered[i]
644+
if not package.path then
645+
ret[#ret + 1] = package
646+
end
647+
end
648+
649+
store.packages_full = ret
650+
end
651+
622652
function store.filter_packages(query)
623653
if query == "" and filter_type == 1 then
624654
store.packages = store.packages_full
@@ -652,7 +682,6 @@ function store.filter_packages(query)
652682
store.packages[#store.packages + 1] = package
653683
end
654684
end
655-
656685
end
657686

658687
function store.get_formspec(dlgdata)
@@ -960,6 +989,9 @@ function create_store_dlg(type)
960989
store.load()
961990
end
962991

992+
store.update_paths()
993+
store.sort_packages()
994+
963995
search_string = ""
964996
cur_page = 1
965997

0 commit comments

Comments
 (0)