aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPilzAdam <pilzadam@minetest.net>2013-08-16 01:34:52 +0200
committerPilzAdam <pilzadam@minetest.net>2013-08-16 02:09:45 +0200
commitb94f18298d61bd0a55c042a3becd2f63b2e9c6b0 (patch)
tree417ef28e40262cd4d232ffc7fe05ca64a5f24fda
parentd52185c43e7fa96174bb9e0d6d7a38f894b3a356 (diff)
downloadminetest-b94f18298d61bd0a55c042a3becd2f63b2e9c6b0.tar.gz
minetest-b94f18298d61bd0a55c042a3becd2f63b2e9c6b0.tar.bz2
minetest-b94f18298d61bd0a55c042a3becd2f63b2e9c6b0.zip
Sort modlist alphabetically
/* Minetest Copyright (C) 2013 sapier This progr-rw-r--r--builtin/filterlist.lua33
-rw-r--r--builtin/modmgr.lua4
2 files changed, 37 insertions, 0 deletions
diff --git a/builtin/filterlist.lua b/builtin/filterlist.lua
index 906c339df..fd337ae92 100644
--- a/builtin/filterlist.lua
+++ b/builtin/filterlist.lua
@@ -246,3 +246,36 @@ function sort_worlds_alphabetic(this)
return a.name:lower() < b.name:lower()
end)
end
+
+--------------------------------------------------------------------------------
+function sort_mod_list(this)
+
+ table.sort(this.m_processed_list, function(a, b)
+ -- Show game mods at bottom
+ if a.typ ~= b.typ then
+ return b.typ == "game_mod"
+ end
+ -- If in same or no modpack, sort by name
+ if a.modpack == b.modpack then
+ if a.name:lower() == b.name:lower() then
+ return a.name < b.name
+ end
+ return a.name:lower() < b.name:lower()
+ -- Else compare name to modpack name
+ else
+ -- Always show modpack pseudo-mod on top of modpack mod list
+ if a.name == b.modpack then
+ return true
+ elseif b.name == a.modpack then
+ return false
+ end
+
+ local name_a = a.modpack or a.name
+ local name_b = b.modpack or b.name
+ if name_a:lower() == name_b:lower() then
+ return name_a < name_b
+ end
+ return name_a:lower() < name_b:lower()
+ end
+ end)
+end
diff --git a/builtin/modmgr.lua b/builtin/modmgr.lua
index 58ffb1530..2f1343738 100644
--- a/builtin/modmgr.lua
+++ b/builtin/modmgr.lua
@@ -972,6 +972,8 @@ function modmgr.init_worldconfig()
hide_game=modmgr.hide_gamemods,
hide_modpackcontents= modmgr.hide_modpackcontents
})
+ filterlist.add_sort_mechanism(modmgr.modlist, "alphabetic", sort_mod_list)
+ filterlist.set_sortmode(modmgr.modlist, "alphabetic")
return true
end
@@ -1068,6 +1070,8 @@ function modmgr.refresh_globals()
nil, --filter
{}
)
+ filterlist.add_sort_mechanism(modmgr.global_mods, "alphabetic", sort_mod_list)
+ filterlist.set_sortmode(modmgr.global_mods, "alphabetic")
end
--------------------------------------------------------------------------------