40 lines
1.3 KiB
Lua
40 lines
1.3 KiB
Lua
local assert = assert
|
|
local ItemStack = ItemStack
|
|
|
|
---A pattern for describing an item, used when the
|
|
---item does not have a clearly defined pattern.
|
|
local DESC_PATTERN = '{title}\n {desc}'
|
|
|
|
---Returns the description of the item,
|
|
---concatenated according to the pattern specified in `settings._description_pattern`.
|
|
---
|
|
---If the `meta` parameter is passed, it can retrieve the necessary params from there.
|
|
---@param settings Item.Settings|Node.Settings
|
|
---@param meta ItemStackMetaRef?
|
|
---@param pattern string?
|
|
---@return string
|
|
function Smc.concatItemDescription(settings, meta, pattern)
|
|
-- If the meta is not provided,
|
|
-- we create an empty item stack in order to get dummy metadata.
|
|
meta = meta or ItemStack():get_meta()
|
|
local description = pattern or settings._description_pattern or DESC_PATTERN
|
|
|
|
local title = meta:get_string('_title')
|
|
if title == '' or title == nil then
|
|
title = settings._title or settings.description or ''
|
|
end
|
|
description = description:gsub('{title}', title)
|
|
|
|
local desc = meta:get_string('_desc')
|
|
if desc == '' or desc == nil then
|
|
desc = settings._description or settings.description or ''
|
|
end
|
|
description = description:gsub('{desc}', desc)
|
|
|
|
local rarityTitle = settings._rarity_title
|
|
assert(rarityTitle ~= nil)
|
|
description = description:gsub('{rarity_title}', rarityTitle)
|
|
|
|
return description
|
|
end
|