]> git.lizzy.rs Git - minetest.git/commitdiff
ContentDB: Add support for package aliases / renaming (#11484)
authorrubenwardy <rw@rubenwardy.com>
Mon, 2 Aug 2021 19:05:10 +0000 (20:05 +0100)
committerGitHub <noreply@github.com>
Mon, 2 Aug 2021 19:05:10 +0000 (20:05 +0100)
builtin/mainmenu/dlg_contentstore.lua

index 7096c91877e01f22ce3a7091d4a4eaf23930d543..a3c72aee4e0da28a7f2bc9c9547d7fa8016005a9 100644 (file)
@@ -575,6 +575,7 @@ function store.load()
        end
 
        store.packages_full = core.parse_json(response.data) or {}
+       store.aliases = {}
 
        for _, package in pairs(store.packages_full) do
                local name_len = #package.name
@@ -583,6 +584,16 @@ function store.load()
                else
                        package.id = package.author:lower() .. "/" .. package.name
                end
+
+               if package.aliases then
+                       for _, alias in ipairs(package.aliases) do
+                               -- We currently don't support name changing
+                               local suffix = "/" .. package.name
+                               if alias:sub(-#suffix) == suffix then
+                                       store.aliases[alias:lower()] = package.id
+                               end
+                       end
+               end
        end
 
        store.packages_full_unordered = store.packages_full
@@ -595,7 +606,8 @@ function store.update_paths()
        pkgmgr.refresh_globals()
        for _, mod in pairs(pkgmgr.global_mods:get_list()) do
                if mod.author and mod.release > 0 then
-                       mod_hash[mod.author:lower() .. "/" .. mod.name] = mod
+                       local id = mod.author:lower() .. "/" .. mod.name
+                       mod_hash[store.aliases[id] or id] = mod
                end
        end
 
@@ -603,14 +615,16 @@ function store.update_paths()
        pkgmgr.update_gamelist()
        for _, game in pairs(pkgmgr.games) do
                if game.author ~= "" and game.release > 0 then
-                       game_hash[game.author:lower() .. "/" .. game.id] = game
+                       local id = game.author:lower() .. "/" .. game.id
+                       game_hash[store.aliases[id] or id] = game
                end
        end
 
        local txp_hash = {}
        for _, txp in pairs(pkgmgr.get_texture_packs()) do
                if txp.author and txp.release > 0 then
-                       txp_hash[txp.author:lower() .. "/" .. txp.name] = txp
+                       local id = txp.author:lower() .. "/" .. txp.name
+                       txp_hash[store.aliases[id] or id] = txp
                end
        end