Add Item.Rarity
This commit is contained in:
9
mods/CORE/Item/locale/item.ru.tr
Normal file
9
mods/CORE/Item/locale/item.ru.tr
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
# textdomain: item
|
||||||
|
|
||||||
|
Rarity=Редкость
|
||||||
|
common=простой
|
||||||
|
uncommon=необычный
|
||||||
|
distinguished=выдающийся
|
||||||
|
eminent=исключительный
|
||||||
|
prime=Превосходный
|
||||||
|
unique=Уникальный
|
||||||
@@ -5,6 +5,33 @@ local require = modInfo.require
|
|||||||
|
|
||||||
local ItemFactory = Mod.getInfo('smc__core__item_factory').require('ItemFactory')
|
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<Item.Rarity, ColorString>
|
||||||
|
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<Item.Rarity, integer>
|
||||||
|
local RARITY_INDEX = {
|
||||||
|
['common'] = 1,
|
||||||
|
['uncommon'] = 2,
|
||||||
|
['distinguished'] = 3,
|
||||||
|
['eminent'] = 4,
|
||||||
|
['prime'] = 5,
|
||||||
|
['unique'] = 0
|
||||||
|
}
|
||||||
|
|
||||||
---@class Item
|
---@class Item
|
||||||
---@field itemDef Item.ItemDefinition
|
---@field itemDef Item.ItemDefinition
|
||||||
---@field luantiDef table
|
---@field luantiDef table
|
||||||
@@ -18,20 +45,42 @@ local Item = {
|
|||||||
description = '',
|
description = '',
|
||||||
titleColor = '#FFFFFF',
|
titleColor = '#FFFFFF',
|
||||||
descriptionColor = '#C0C0C0',
|
descriptionColor = '#C0C0C0',
|
||||||
|
rarity = 'common',
|
||||||
addModName = true,
|
addModName = true,
|
||||||
},
|
},
|
||||||
callbacks = {}
|
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
|
---The alias `table.merge` for EmmyLua
|
||||||
---@type fun(...):(NodeDefinition|ItemDefinition)
|
---@type fun(...):(NodeDefinition|ItemDefinition)
|
||||||
local defMerge = function(...)
|
local defMerge = function(...)
|
||||||
return table.merge(...)
|
return table.merge(...)
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param itemDef Item.ItemDefinition
|
---@param itemDef Item.ItemDefinition
|
||||||
---@return NodeDefinition|ItemDefinition
|
---@return NodeDefinition|ItemDefinition
|
||||||
local function itemDefToLuantiDef(itemDef)
|
local function itemDefToLuantiDef(itemDef)
|
||||||
local modName = Mod.getInfo().shortName
|
local modName = Mod.getInfo().shortName
|
||||||
local S = core.get_translator(modName)
|
local S = core.get_translator(modName)
|
||||||
@@ -62,7 +111,11 @@ local function itemDefToLuantiDef(itemDef)
|
|||||||
error('Item description color parameters cannot be empty.')
|
error('Item description color parameters cannot be empty.')
|
||||||
end
|
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)
|
local luantiDef = defMerge(s, c)
|
||||||
|
|
||||||
|
|||||||
8
mods/CORE/Item/src/Item/Rarity.lua
Normal file
8
mods/CORE/Item/src/Item/Rarity.lua
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
---Rarity of items:
|
||||||
|
--- * `common`
|
||||||
|
--- * `uncommon`
|
||||||
|
--- * `distinguished`
|
||||||
|
--- * `eminent`
|
||||||
|
--- * `prime`
|
||||||
|
--- * `unique`
|
||||||
|
---@alias Item.Rarity 'common'|'uncommon'|'distinguished'|'eminent'|'prime'|'unique'
|
||||||
@@ -37,6 +37,9 @@ Settings.descriptionColor = nil
|
|||||||
---@type Item.Visual?
|
---@type Item.Visual?
|
||||||
Settings.visual = nil
|
Settings.visual = nil
|
||||||
|
|
||||||
|
---Formal (lore) rarity of an item. Default `common`.
|
||||||
|
---@type Item.Rarity?
|
||||||
|
Settings.rarity = nil
|
||||||
|
|
||||||
|
|
||||||
---Table of groups-characteristics of Item.
|
---Table of groups-characteristics of Item.
|
||||||
|
|||||||
@@ -197,6 +197,7 @@ soilFactory:registerItems({
|
|||||||
title = "Barren Rocky Soil",
|
title = "Barren Rocky Soil",
|
||||||
--description = "",
|
--description = "",
|
||||||
tiles = rockyTiles,
|
tiles = rockyTiles,
|
||||||
|
rarity = 'uncommon'
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
---@type Node.NodeDefinition
|
---@type Node.NodeDefinition
|
||||||
@@ -206,6 +207,7 @@ soilFactory:registerItems({
|
|||||||
title = "Poor Rocky Soil",
|
title = "Poor Rocky Soil",
|
||||||
--description = "",
|
--description = "",
|
||||||
tiles = rockyTiles,
|
tiles = rockyTiles,
|
||||||
|
rarity = 'distinguished'
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
---@type Node.NodeDefinition
|
---@type Node.NodeDefinition
|
||||||
@@ -215,6 +217,7 @@ soilFactory:registerItems({
|
|||||||
title = "Moderate Rocky Soil",
|
title = "Moderate Rocky Soil",
|
||||||
--description = "",
|
--description = "",
|
||||||
tiles = rockyTiles,
|
tiles = rockyTiles,
|
||||||
|
rarity = 'eminent'
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
---@type Node.NodeDefinition
|
---@type Node.NodeDefinition
|
||||||
@@ -224,6 +227,7 @@ soilFactory:registerItems({
|
|||||||
title = "Fertile Rocky Soil",
|
title = "Fertile Rocky Soil",
|
||||||
--description = "",
|
--description = "",
|
||||||
tiles = rockyTiles,
|
tiles = rockyTiles,
|
||||||
|
rarity = 'prime'
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
---@type Node.NodeDefinition
|
---@type Node.NodeDefinition
|
||||||
@@ -248,6 +252,7 @@ Node:new({
|
|||||||
groups = {
|
groups = {
|
||||||
dig_immediate = 2,
|
dig_immediate = 2,
|
||||||
soil_fertiliry = 100, -- Soil fertility for agriculture
|
soil_fertiliry = 100, -- Soil fertility for agriculture
|
||||||
}
|
},
|
||||||
|
rarity = 'unique'
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
Reference in New Issue
Block a user