diff --git a/mods/CORE/Item/locale/item.ru.tr b/mods/CORE/Item/locale/item.ru.tr new file mode 100644 index 0000000..a73273c --- /dev/null +++ b/mods/CORE/Item/locale/item.ru.tr @@ -0,0 +1,9 @@ +# textdomain: item + +Rarity=Редкость +common=простой +uncommon=необычный +distinguished=выдающийся +eminent=исключительный +prime=Превосходный +unique=Уникальный \ No newline at end of file diff --git a/mods/CORE/Item/src/Item.lua b/mods/CORE/Item/src/Item.lua index 8058537..5506996 100644 --- a/mods/CORE/Item/src/Item.lua +++ b/mods/CORE/Item/src/Item.lua @@ -5,6 +5,33 @@ local require = modInfo.require local ItemFactory = Mod.getInfo('smc__core__item_factory').require('ItemFactory') +---Determines whether common rarity will be shown in item descriptions or not. +local SHOW_COMMON_RARITY = true + +---Colors corresponding to the rarity color in the item description. +---@type table +local RARITY_COLORS = { + ['common'] = '#C0C0C0', + ['uncommon'] = '#7cd2e2', + ['distinguished'] = '#7ce2da', + ['eminent'] = '#44d1a9', + ['prime'] = '#9CF0B1', + ['unique'] = '#f4c95a' +} + +---Whether to show the numeric index in the rarity description. +local SHOW_RARITY_INDEX = true + +---@type table +local RARITY_INDEX = { + ['common'] = 1, + ['uncommon'] = 2, + ['distinguished'] = 3, + ['eminent'] = 4, + ['prime'] = 5, + ['unique'] = 0 +} + ---@class Item ---@field itemDef Item.ItemDefinition ---@field luantiDef table @@ -18,20 +45,42 @@ local Item = { description = '', titleColor = '#FFFFFF', descriptionColor = '#C0C0C0', + rarity = 'common', addModName = true, }, callbacks = {} } } +---Adds an item's rarity tag to the description. +---@param rarity Item.Rarity +---@param desc string +---@return string +local function addRarityToDesc(rarity, desc) + if not SHOW_COMMON_RARITY and rarity == 'common' then + return desc + end + + local S = core.get_translator('item') + local color = RARITY_COLORS[rarity] + + local rarityString = S('Rarity')..': '..S(rarity) + + if SHOW_RARITY_INDEX then + rarityString = rarityString..' ['..RARITY_INDEX[rarity]..']' + end + + return desc..'\n'..core.colorize(color, rarityString) +end + ---The alias `table.merge` for EmmyLua ---@type fun(...):(NodeDefinition|ItemDefinition) local defMerge = function(...) return table.merge(...) end ----@param itemDef Item.ItemDefinition ----@return NodeDefinition|ItemDefinition +---@param itemDef Item.ItemDefinition +---@return NodeDefinition|ItemDefinition local function itemDefToLuantiDef(itemDef) local modName = Mod.getInfo().shortName local S = core.get_translator(modName) @@ -62,7 +111,11 @@ local function itemDefToLuantiDef(itemDef) error('Item description color parameters cannot be empty.') end - s.title, s.description = nil, description + assert(s.rarity ~= nil, 'The rarity of an item cannot be empty.') + + description = addRarityToDesc(s.rarity, description) + + s.title, s.description = nil, description..core.get_background_escape_sequence('#110F13') local luantiDef = defMerge(s, c) diff --git a/mods/CORE/Item/src/Item/Rarity.lua b/mods/CORE/Item/src/Item/Rarity.lua new file mode 100644 index 0000000..914e0d4 --- /dev/null +++ b/mods/CORE/Item/src/Item/Rarity.lua @@ -0,0 +1,8 @@ +---Rarity of items: +--- * `common` +--- * `uncommon` +--- * `distinguished` +--- * `eminent` +--- * `prime` +--- * `unique` +---@alias Item.Rarity 'common'|'uncommon'|'distinguished'|'eminent'|'prime'|'unique' \ No newline at end of file diff --git a/mods/CORE/Item/src/Item/Settings.lua b/mods/CORE/Item/src/Item/Settings.lua index f681043..d3de7af 100644 --- a/mods/CORE/Item/src/Item/Settings.lua +++ b/mods/CORE/Item/src/Item/Settings.lua @@ -37,6 +37,9 @@ Settings.descriptionColor = nil ---@type Item.Visual? Settings.visual = nil +---Formal (lore) rarity of an item. Default `common`. +---@type Item.Rarity? +Settings.rarity = nil ---Table of groups-characteristics of Item. diff --git a/mods/GAME/ITEMS/soils/init.lua b/mods/GAME/ITEMS/soils/init.lua index f898f03..5afee81 100644 --- a/mods/GAME/ITEMS/soils/init.lua +++ b/mods/GAME/ITEMS/soils/init.lua @@ -197,6 +197,7 @@ soilFactory:registerItems({ title = "Barren Rocky Soil", --description = "", tiles = rockyTiles, + rarity = 'uncommon' }, }, ---@type Node.NodeDefinition @@ -206,6 +207,7 @@ soilFactory:registerItems({ title = "Poor Rocky Soil", --description = "", tiles = rockyTiles, + rarity = 'distinguished' }, }, ---@type Node.NodeDefinition @@ -215,6 +217,7 @@ soilFactory:registerItems({ title = "Moderate Rocky Soil", --description = "", tiles = rockyTiles, + rarity = 'eminent' }, }, ---@type Node.NodeDefinition @@ -224,6 +227,7 @@ soilFactory:registerItems({ title = "Fertile Rocky Soil", --description = "", tiles = rockyTiles, + rarity = 'prime' }, }, ---@type Node.NodeDefinition @@ -248,6 +252,7 @@ Node:new({ groups = { dig_immediate = 2, soil_fertiliry = 100, -- Soil fertility for agriculture - } + }, + rarity = 'unique' } }) \ No newline at end of file