Item: add optional rarity color in title. Close #35
This commit is contained in:
@@ -4,6 +4,14 @@ local tableCopy, tableMerge, colorize = table.copy, table.merge, core.colorize
|
|||||||
|
|
||||||
local ItemFactory = Smc.requireItemFactory()
|
local ItemFactory = Smc.requireItemFactory()
|
||||||
|
|
||||||
|
---Colors the title according to the rarity of the item.
|
||||||
|
---
|
||||||
|
---Note: that if `true`, the `_title_color` will be ignored.
|
||||||
|
local TITLE_RARITY_COLOR = true
|
||||||
|
|
||||||
|
---Shows rarity on a separate line.
|
||||||
|
local SHOW_RARITY = false
|
||||||
|
|
||||||
---Determines whether common rarity will be shown in item descriptions or not.
|
---Determines whether common rarity will be shown in item descriptions or not.
|
||||||
local SHOW_COMMON_RARITY = true
|
local SHOW_COMMON_RARITY = true
|
||||||
|
|
||||||
@@ -57,6 +65,10 @@ local Item = {
|
|||||||
---@param desc string
|
---@param desc string
|
||||||
---@return string
|
---@return string
|
||||||
local function addRarityToDesc(rarity, desc)
|
local function addRarityToDesc(rarity, desc)
|
||||||
|
if not SHOW_RARITY then
|
||||||
|
return desc
|
||||||
|
end
|
||||||
|
|
||||||
if not SHOW_COMMON_RARITY and rarity == 'common' then
|
if not SHOW_COMMON_RARITY and rarity == 'common' then
|
||||||
return desc
|
return desc
|
||||||
end
|
end
|
||||||
@@ -98,15 +110,19 @@ local function itemDefToLuantiDef(itemDef)
|
|||||||
description = string.match(s.name, '%S:(%S+)')..'-desc'
|
description = string.match(s.name, '%S:(%S+)')..'-desc'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
assert(s._rarity ~= nil, 'The rarity of an item cannot be empty.')
|
||||||
|
|
||||||
if s._title_color ~= nil and s._description_color ~= nil then
|
if s._title_color ~= nil and s._description_color ~= nil then
|
||||||
|
if TITLE_RARITY_COLOR then
|
||||||
|
title = colorize(RARITY_COLORS[s._rarity], S(title))
|
||||||
|
else
|
||||||
title = colorize(s._title_color, S(title))
|
title = colorize(s._title_color, S(title))
|
||||||
|
end
|
||||||
description = colorize(s._description_color, S(description))
|
description = colorize(s._description_color, S(description))
|
||||||
else
|
else
|
||||||
error('Item description color parameters cannot be empty.')
|
error('Item description color parameters cannot be empty.')
|
||||||
end
|
end
|
||||||
|
|
||||||
assert(s._rarity ~= nil, 'The rarity of an item cannot be empty.')
|
|
||||||
|
|
||||||
local luantiDescription = addRarityToDesc(s._rarity, title..'\n '..description)
|
local luantiDescription = addRarityToDesc(s._rarity, title..'\n '..description)
|
||||||
|
|
||||||
s._title = title
|
s._title = title
|
||||||
|
|||||||
Reference in New Issue
Block a user