3 Commits

Author SHA1 Message Date
44916bcd3b BaseUI: remove print() 2026-03-20 23:06:05 +03:00
3483cd650a Item: add optional rarity color in title. Close #35 2026-03-20 23:05:40 +03:00
c4104a1834 HelperLib: add craft system requires 2026-03-20 22:10:26 +03:00
3 changed files with 42 additions and 4 deletions

View File

@@ -24,7 +24,6 @@ function BaseUI:new(name, getFormSpecString, clearContex)
instance.getFormSpecString = getFormSpecString
if clearContex then
core.log(name)
-- Ensure that when the form is closed, the context is cleared.
instance:registerOnFormQuit(function(player)
instance:clearContex(player)

View File

@@ -4,6 +4,14 @@ local tableCopy, tableMerge, colorize = table.copy, table.merge, core.colorize
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.
local SHOW_COMMON_RARITY = true
@@ -57,6 +65,10 @@ local Item = {
---@param desc string
---@return string
local function addRarityToDesc(rarity, desc)
if not SHOW_RARITY then
return desc
end
if not SHOW_COMMON_RARITY and rarity == 'common' then
return desc
end
@@ -98,15 +110,19 @@ local function itemDefToLuantiDef(itemDef)
description = string.match(s.name, '%S:(%S+)')..'-desc'
end
assert(s._rarity ~= nil, 'The rarity of an item cannot be empty.')
if s._title_color ~= nil and s._description_color ~= nil then
title = colorize(s._title_color , S(title))
if TITLE_RARITY_COLOR then
title = colorize(RARITY_COLORS[s._rarity], S(title))
else
title = colorize(s._title_color, S(title))
end
description = colorize(s._description_color, S(description))
else
error('Item description color parameters cannot be empty.')
end
assert(s._rarity ~= nil, 'The rarity of an item cannot be empty.')
local luantiDescription = addRarityToDesc(s._rarity, title..'\n '..description)
s._title = title

View File

@@ -64,3 +64,26 @@ function Smc.requireFormspec()
return class
end
---@return CraftSystem
function Smc.requireCraftSystem()
---@type CraftSystem
local class = Mod.getInfo('smc__core__craft_system').require('CraftSystem')
return class
end
---@return CraftSystem.PrimitiveCraftHandler
function Smc.requireCraftSystemPrimitiveCraftHandler()
---@type CraftSystem.PrimitiveCraftHandler
local class = Mod.getInfo('smc__core__craft_system').require('CraftSystem.PrimitiveCraftHandler')
return class
end
---@return CraftSystem.ImmersiveCraftHandler
function Smc.requireCraftSystemImmersiveCraftHandler()
---@type CraftSystem.ImmersiveCraftHandler
local class = Mod.getInfo('smc__core__craft_system').require('CraftSystem.ImmersiveCraftHandler')
return class
end