]> git.lizzy.rs Git - minetest.git/commitdiff
Fix short_description fallback order (#10943)
authorrubenwardy <rw@rubenwardy.com>
Wed, 17 Feb 2021 18:53:44 +0000 (18:53 +0000)
committerGitHub <noreply@github.com>
Wed, 17 Feb 2021 18:53:44 +0000 (18:53 +0000)
builtin/game/register.lua
doc/lua_api.txt
games/devtest/mods/unittests/itemdescription.lua
src/script/common/c_content.cpp

index b006957e914452a612b504ed47544953a6b87936..1cff858135719da9a958d786eba96d0455aec2b6 100644 (file)
@@ -118,10 +118,6 @@ function core.register_item(name, itemdef)
        end
        itemdef.name = name
 
-       -- default short_description to first line of description
-       itemdef.short_description = itemdef.short_description or
-               (itemdef.description or ""):gsub("\n.*","")
-
        -- Apply defaults and add to registered_* table
        if itemdef.type == "node" then
                -- Use the nodebox as selection box if it's not set manually
index 7b782561462f78444c829fc7d81874ff0609e5db..a09b9892494af81e2f2ad56393591afee2dbfe80 100644 (file)
@@ -6039,18 +6039,18 @@ an itemstring, a table or `nil`.
   stack).
 * `set_metadata(metadata)`: (DEPRECATED) Returns true.
 * `get_description()`: returns the description shown in inventory list tooltips.
-    * The engine uses the same as this function for item descriptions.
+    * The engine uses this when showing item descriptions in tooltips.
     * Fields for finding the description, in order:
         * `description` in item metadata (See [Item Metadata].)
         * `description` in item definition
         * item name
-* `get_short_description()`: returns the short description.
+* `get_short_description()`: returns the short description or nil.
     * Unlike the description, this does not include new lines.
-    * The engine uses the same as this function for short item descriptions.
     * Fields for finding the short description, in order:
         * `short_description` in item metadata (See [Item Metadata].)
         * `short_description` in item definition
-        * first line of the description (See `get_description()`.)
+        * first line of the description (From item meta or def, see `get_description()`.)
+        * Returns nil if none of the above are set
 * `clear()`: removes all items from the stack, making it empty.
 * `replace(item)`: replace the contents of this stack.
     * `item` can also be an itemstring or table.
@@ -7171,8 +7171,9 @@ Used by `minetest.register_node`, `minetest.register_craftitem`, and
 
         short_description = "Steel Axe",
         -- Must not contain new lines.
-        -- Defaults to the first line of description.
-        -- See also: `get_short_description` in [`ItemStack`]
+        -- Defaults to nil.
+        -- Use an [`ItemStack`] to get the short description, eg:
+        --   ItemStack(itemname):get_short_description()
 
         groups = {},
         -- key = name, value = rating; rating = 1..3.
index 1d082654535f42a018f9e3155262742058c75e49..d6ee6551affbce9a35a235e9d9577b00c5ed8699 100644 (file)
@@ -26,15 +26,22 @@ minetest.register_chatcommand("item_description", {
 })
 
 function unittests.test_short_desc()
+       local function get_short_description(item)
+               return ItemStack(item):get_short_description()
+       end
+
        local stack = ItemStack("unittests:colorful_pick")
        assert(stack:get_short_description() == "Colorful Pickaxe")
-       assert(stack:get_short_description() == minetest.registered_items["unittests:colorful_pick"].short_description)
+       assert(get_short_description("unittests:colorful_pick") == "Colorful Pickaxe")
+       assert(minetest.registered_items["unittests:colorful_pick"].short_description == nil)
        assert(stack:get_description() == full_description)
        assert(stack:get_description() == minetest.registered_items["unittests:colorful_pick"].description)
 
        stack:get_meta():set_string("description", "Hello World")
-       assert(stack:get_short_description() == "Colorful Pickaxe")
+       assert(stack:get_short_description() == "Hello World")
        assert(stack:get_description() == "Hello World")
+       assert(get_short_description(stack) == "Hello World")
+       assert(get_short_description("unittests:colorful_pick") == "Colorful Pickaxe")
 
        stack:get_meta():set_string("short_description", "Foo Bar")
        assert(stack:get_short_description() == "Foo Bar")
index ecab7baa1af4bec0bcc66f330ed67ab93f20f3c4..2f9fbd74bf69ab3447c8a2cde28bca9bfd2f6511 100644 (file)
@@ -140,8 +140,10 @@ void push_item_definition_full(lua_State *L, const ItemDefinition &i)
        lua_setfield(L, -2, "name");
        lua_pushstring(L, i.description.c_str());
        lua_setfield(L, -2, "description");
-       lua_pushstring(L, i.short_description.c_str());
-       lua_setfield(L, -2, "short_description");
+       if (!i.short_description.empty()) {
+               lua_pushstring(L, i.short_description.c_str());
+               lua_setfield(L, -2, "short_description");
+       }
        lua_pushstring(L, type.c_str());
        lua_setfield(L, -2, "type");
        lua_pushstring(L, i.inventory_image.c_str());