]> git.lizzy.rs Git - dragonfireclient.git/commitdiff
Deprecate game.conf name, use title instead (#12030)
authorrubenwardy <rw@rubenwardy.com>
Sat, 21 May 2022 15:23:30 +0000 (16:23 +0100)
committerGitHub <noreply@github.com>
Sat, 21 May 2022 15:23:30 +0000 (16:23 +0100)
12 files changed:
builtin/mainmenu/dlg_contentstore.lua
builtin/mainmenu/pkgmgr.lua
builtin/mainmenu/tab_local.lua
doc/lua_api.txt
doc/menu_lua_api.txt
games/devtest/game.conf
src/content/content.cpp
src/content/content.h
src/content/subgames.cpp
src/content/subgames.h
src/script/lua_api/l_mainmenu.cpp
src/server.cpp

index 276a7b0962aa07f9692760dec9f25136509ad80f..16ab1c3a7720c0299feae9045aa6c6af3de3b1f8 100644 (file)
@@ -151,11 +151,9 @@ local function start_install(package, reason)
 
                                if conf_path then
                                        local conf = Settings(conf_path)
-                                       if name_is_title then
-                                               conf:set("name",   package.title)
-                                       else
-                                               conf:set("title",  package.title)
-                                               conf:set("name",   package.name)
+                                       conf:set("title", package.title)
+                                       if not name_is_title then
+                                               conf:set("name", package.name)
                                        end
                                        if not conf:get("description") then
                                                conf:set("description", package.short_description)
@@ -360,7 +358,7 @@ function install_dialog.get_formspec()
                        selected_game_idx = i
                end
 
-               games[i] = core.formspec_escape(games[i].name)
+               games[i] = core.formspec_escape(games[i].title)
        end
 
        local selected_game = pkgmgr.games[selected_game_idx]
@@ -410,7 +408,7 @@ function install_dialog.get_formspec()
                "container[0.375,0.70]",
 
                "label[0,0.25;", fgettext("Base Game:"), "]",
-               "dropdown[2,0;4.25,0.5;gameid;", table.concat(games, ","), ";", selected_game_idx, "]",
+               "dropdown[2,0;4.25,0.5;selected_game;", table.concat(games, ","), ";", selected_game_idx, "]",
 
                "label[0,0.8;", fgettext("Dependencies:"), "]",
 
@@ -461,9 +459,9 @@ function install_dialog.handle_submit(this, fields)
                return true
        end
 
-       if fields.gameid then
+       if fields.selected_game then
                for _, game in pairs(pkgmgr.games) do
-                       if game.name == fields.gameid then
+                       if game.title == fields.selected_game then
                                core.settings:set("menu_last_game", game.id)
                                break
                        end
index 334fcf5f828fe70e325abdf0229a849be6bca9be..b2f3243c4800cef98d4b226f404a08c1c44fc31f 100644 (file)
@@ -646,6 +646,8 @@ function pkgmgr.install_dir(type, path, basename, targetpath)
                else
                        targetpath = core.get_gamepath() .. DIR_DELIM .. basename
                end
+       else
+               error("basefolder didn't return a recognised type, this shouldn't happen")
        end
 
        -- Copy it
@@ -692,7 +694,7 @@ function pkgmgr.preparemodlist(data)
                retval[#retval + 1] = {
                        type = "game",
                        is_game_content = true,
-                       name = fgettext("$1 mods", gamespec.name),
+                       name = fgettext("$1 mods", gamespec.title),
                        path = gamespec.path
                }
        end
@@ -873,10 +875,10 @@ end
 function pkgmgr.gamelist()
        local retval = ""
        if #pkgmgr.games > 0 then
-               retval = retval .. core.formspec_escape(pkgmgr.games[1].name)
+               retval = retval .. core.formspec_escape(pkgmgr.games[1].title)
 
                for i=2,#pkgmgr.games,1 do
-                       retval = retval .. "," .. core.formspec_escape(pkgmgr.games[i].name)
+                       retval = retval .. "," .. core.formspec_escape(pkgmgr.games[i].title)
                end
        end
        return retval
index e77c6f04de368ea1e967099144003f04e4e244e8..049d16507ef4338764303a477793e0561d28e7f1 100644 (file)
@@ -88,7 +88,7 @@ if enable_gamebar then
 
                        local image = nil
                        local text = nil
-                       local tooltip = core.formspec_escape(game.name)
+                       local tooltip = core.formspec_escape(game.title)
 
                        if (game.menuicon_path or "") ~= "" then
                                image = core.formspec_escape(game.menuicon_path)
index abfaf08aa3d22abcacc5b88f1ac00f252158fa95..6046a5902a0eb33ae10a2bddc21e1e5aa61fa056 100644 (file)
@@ -62,7 +62,8 @@ Where `<gameid>` is unique to each game.
 The game directory can contain the following files:
 
 * `game.conf`, with the following keys:
-    * `name`: Required, a human readable title to address the game, e.g. `name = Minetest`.
+    * `title`: Required, a human-readable title to address the game, e.g. `title = Minetest Game`.
+    * `name`: (Deprecated) same as title.
     * `description`: Short description to be shown in the content tab
     * `allowed_mapgens = <comma-separated mapgens>`
       e.g. `allowed_mapgens = v5,v6,flat`
index c2931af310f6a45aec6d43de75577aaf7a214432..68e7b4b9de018edb3bdff85149b3cd74211320ed 100644 (file)
@@ -246,13 +246,14 @@ Package - content which is downloadable from the content db, may or may not be i
 * core.get_texturepath() (possible in async calls)
     * returns path to default textures
 * core.get_game(index)
+    * `name` in return value is deprecated, use `title` instead.
     * returns:
 
         {
             id               = <id>,
             path             = <full path to game>,
             gamemods_path    = <path>,
-            name             = <name of game>,
+            title            = <title of game>,
             menuicon_path    = <full path to menuicon>,
             author           = "author",
             DEPRECATED:
@@ -264,8 +265,9 @@ Package - content which is downloadable from the content db, may or may not be i
     * returns
 
         {
-            name             = "name of content",
+            name             = "technical_id",
             type             = "mod" or "modpack" or "game" or "txp",
+            title            = "Human readable title",
             description      = "description",
             author           = "author",
             path             = "path/to/content",
index d6e382ad7e2fba49eebec3763c20fea8dd35c7d6..0f5656c99db8a334ebaebe6e1707e2e80b650084 100644 (file)
@@ -1,2 +1,2 @@
-name = Development Test
+title = Development Test
 description = Testing environment to help with testing the engine features of Minetest. It can also be helpful in mod development.
index 66ef83d42bbfec76362f5512d7426bde565b39b3..e576943ffcc0873aacfaa942f80608b497849bcf 100644 (file)
@@ -96,7 +96,12 @@ void parseContentInfo(ContentSpec &spec)
 
        Settings conf;
        if (!conf_path.empty() && conf.readConfigFile(conf_path.c_str())) {
-               if (conf.exists("name"))
+               if (conf.exists("title"))
+                       spec.title = conf.get("title");
+               else if (spec.type == "game" && conf.exists("name"))
+                       spec.title = conf.get("name");
+
+               if (spec.type != "game" && conf.exists("name"))
                        spec.name = conf.get("name");
 
                if (conf.exists("description"))
index e246ed4113cf1b35b72b0e0d18be5e93515ffe20..ce09a2eb9c081cda3fb8f079bd86a24ffef39830 100644 (file)
@@ -27,7 +27,14 @@ struct ContentSpec
        std::string type;
        std::string author;
        u32 release = 0;
+
+       /// Technical name / Id
        std::string name;
+
+       /// Human-readable title
+       std::string title;
+
+       /// Short description
        std::string desc;
        std::string path;
 };
index 23355990ec442671acd4e7fe8bf73853cd63645a..d0de926ef367e1fdc059bf4a3af82d4901dbbd6a 100644 (file)
@@ -17,6 +17,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */
 
+#include <common/c_internal.h>
 #include "content/subgames.h"
 #include "porting.h"
 #include "filesys.h"
@@ -45,6 +46,25 @@ bool getGameMinetestConfig(const std::string &game_path, Settings &conf)
 
 }
 
+
+void SubgameSpec::checkAndLog() const
+{
+       // Log deprecation messages
+       auto handling_mode = get_deprecated_handling_mode();
+       if (!deprecation_msgs.empty() && handling_mode != DeprecatedHandlingMode::Ignore) {
+               std::ostringstream os;
+               os << "Game " << title << " at " << path << ":" << std::endl;
+               for (auto msg : deprecation_msgs)
+                       os << "\t" << msg << std::endl;
+
+               if (handling_mode == DeprecatedHandlingMode::Error)
+                       throw ModError(os.str());
+               else
+                       warningstream << os.str();
+       }
+}
+
+
 struct GameFindPath
 {
        std::string path;
@@ -121,11 +141,13 @@ SubgameSpec findSubgame(const std::string &id)
        Settings conf;
        conf.readConfigFile(conf_path.c_str());
 
-       std::string game_name;
-       if (conf.exists("name"))
-               game_name = conf.get("name");
+       std::string game_title;
+       if (conf.exists("title"))
+               game_title = conf.get("title");
+       else if (conf.exists("name"))
+               game_title = conf.get("name");
        else
-               game_name = id;
+               game_title = id;
 
        std::string game_author;
        if (conf.exists("author"))
@@ -140,8 +162,14 @@ SubgameSpec findSubgame(const std::string &id)
        menuicon_path = getImagePath(
                        game_path + DIR_DELIM + "menu" + DIR_DELIM + "icon.png");
 #endif
-       return SubgameSpec(id, game_path, gamemod_path, mods_paths, game_name,
+
+       SubgameSpec spec(id, game_path, gamemod_path, mods_paths, game_title,
                        menuicon_path, game_author, game_release);
+
+       if (conf.exists("name") && !conf.exists("title"))
+               spec.deprecation_msgs.push_back("\"name\" setting in game.conf is deprecated, please use \"title\" instead");
+
+       return spec;
 }
 
 SubgameSpec findWorldSubgame(const std::string &world_path)
@@ -159,10 +187,12 @@ SubgameSpec findWorldSubgame(const std::string &world_path)
                std::string conf_path = world_gamepath + DIR_DELIM + "game.conf";
                conf.readConfigFile(conf_path.c_str());
 
-               if (conf.exists("name"))
-                       gamespec.name = conf.get("name");
+               if (conf.exists("title"))
+                       gamespec.title = conf.get("title");
+               else if (conf.exists("name"))
+                       gamespec.title = conf.get("name");
                else
-                       gamespec.name = world_gameid;
+                       gamespec.title = world_gameid;
 
                return gamespec;
        }
index d36b4952fde076fd490ed6dbb17ce4f066efea30..d5d168243b6a92b2d70da0947e53bc711013fc4a 100644 (file)
@@ -29,7 +29,7 @@ class Settings;
 struct SubgameSpec
 {
        std::string id;
-       std::string name;
+       std::string title;
        std::string author;
        int release;
        std::string path;
@@ -41,20 +41,24 @@ struct SubgameSpec
        std::unordered_map<std::string, std::string> addon_mods_paths;
        std::string menuicon_path;
 
+       // For logging purposes
+       std::vector<const char *> deprecation_msgs;
+
        SubgameSpec(const std::string &id = "", const std::string &path = "",
                        const std::string &gamemods_path = "",
                        const std::unordered_map<std::string, std::string> &addon_mods_paths = {},
-                       const std::string &name = "",
+                       const std::string &title = "",
                        const std::string &menuicon_path = "",
                        const std::string &author = "", int release = 0) :
                        id(id),
-                       name(name), author(author), release(release), path(path),
+                       title(title), author(author), release(release), path(path),
                        gamemods_path(gamemods_path), addon_mods_paths(addon_mods_paths),
                        menuicon_path(menuicon_path)
        {
        }
 
        bool isValid() const { return (!id.empty() && !path.empty()); }
+       void checkAndLog() const;
 };
 
 SubgameSpec findSubgame(const std::string &id);
index db031dde5d49b36c8c1a55b7920d8fce5c4fa959..4d9fa5b14b4570df0dd32724b94c6df7a814b908 100644 (file)
@@ -304,7 +304,11 @@ int ModApiMainMenu::l_get_games(lua_State *L)
                lua_settable(L,    top_lvl2);
 
                lua_pushstring(L,  "name");
-               lua_pushstring(L,  game.name.c_str());
+               lua_pushstring(L,  game.title.c_str());
+               lua_settable(L,    top_lvl2);
+
+               lua_pushstring(L,  "title");
+               lua_pushstring(L,  game.title.c_str());
                lua_settable(L,    top_lvl2);
 
                lua_pushstring(L,  "author");
@@ -356,6 +360,11 @@ int ModApiMainMenu::l_get_content_info(lua_State *L)
        lua_pushstring(L, spec.author.c_str());
        lua_setfield(L, -2, "author");
 
+       if (!spec.title.empty()) {
+               lua_pushstring(L, spec.title.c_str());
+               lua_setfield(L, -2, "title");
+       }
+
        lua_pushinteger(L, spec.release);
        lua_setfield(L, -2, "release");
 
index d93f300d287f2152952e3e2252872b849eddd5d9..b6330c96a839705d0ce7b02dc8ecd413b8411aaa 100644 (file)
@@ -440,6 +440,7 @@ void Server::init()
 
        m_script->loadMod(getBuiltinLuaPath() + DIR_DELIM "init.lua", BUILTIN_MOD_NAME);
 
+       m_gamespec.checkAndLog();
        m_modmgr->loadMods(m_script);
 
        // Read Textures and calculate sha1 sums
@@ -3109,7 +3110,7 @@ std::string Server::getStatusString()
        // Version
        os << "version: " << g_version_string;
        // Game
-       os << " | game: " << (m_gamespec.name.empty() ? m_gamespec.id : m_gamespec.name);
+       os << " | game: " << (m_gamespec.title.empty() ? m_gamespec.id : m_gamespec.title);
        // Uptime
        os << " | uptime: " << duration_to_string((int) m_uptime_counter->get());
        // Max lag estimate