@@ -23,7 +23,9 @@ if not minetest.get_http_api then
23
23
return
24
24
end
25
25
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 = {} }
27
29
28
30
local http = minetest .get_http_api ()
29
31
@@ -572,6 +574,7 @@ function store.load()
572
574
end
573
575
end
574
576
577
+ store .packages_full_unordered = store .packages_full
575
578
store .packages = store .packages_full
576
579
store .loaded = true
577
580
end
@@ -619,6 +622,33 @@ function store.update_paths()
619
622
end
620
623
end
621
624
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
+
622
652
function store .filter_packages (query )
623
653
if query == " " and filter_type == 1 then
624
654
store .packages = store .packages_full
@@ -652,7 +682,6 @@ function store.filter_packages(query)
652
682
store .packages [# store .packages + 1 ] = package
653
683
end
654
684
end
655
-
656
685
end
657
686
658
687
function store .get_formspec (dlgdata )
@@ -960,6 +989,9 @@ function create_store_dlg(type)
960
989
store .load ()
961
990
end
962
991
992
+ store .update_paths ()
993
+ store .sort_packages ()
994
+
963
995
search_string = " "
964
996
cur_page = 1
965
997
0 commit comments