mirror of
https://github.com/minetest/minetest.git
synced 2024-08-18 20:44:16 +02:00
Fix short_description fallback order (#10943)
This commit is contained in:
parent
7832b6843e
commit
a8f6befd39
@ -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
|
||||
|
@ -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.
|
||||
|
@ -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")
|
||||
|
@ -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());
|
||||
|
Loading…
Reference in New Issue
Block a user