Rename custom field use snake_case and _

This commit is contained in:
Van
2026-02-08 18:42:07 +03:00
parent 04f90a7b2d
commit bc03aa4ba6
10 changed files with 87 additions and 78 deletions

View File

@@ -1,4 +1,6 @@
local getInstance = Class.getInstance
local getInstance, extend = Class.getInstance, Class.extend
local tableCopy, tableMerge, colorize = table.copy, table.merge, core.colorize
local modInfo = Mod.getInfo('smc__core__item')
local require = modInfo.require
@@ -40,13 +42,13 @@ local RARITY_INDEX = {
local Item = {
defaultDef = {
settings = {
name = '',
title = '',
description = '',
titleColor = '#FFFFFF',
descriptionColor = '#C0C0C0',
rarity = 'common',
addModName = true,
name = '',
_title = '',
_description = '',
_title_color = '#FFFFFF',
_description_color = '#C0C0C0',
_rarity = 'common',
_add_mod_name = true,
},
callbacks = {}
}
@@ -70,13 +72,13 @@ local function addRarityToDesc(rarity, desc)
rarityString = rarityString..' ['..RARITY_INDEX[rarity]..']'
end
return desc..'\n'..core.colorize(color, rarityString)
return desc..'\n'..colorize(color, rarityString)
end
---The alias `table.merge` for EmmyLua
---@type fun(...):(NodeDefinition|ItemDefinition)
local defMerge = function(...)
return table.merge(...)
return tableMerge(...)
end
---@param itemDef Item.ItemDefinition
@@ -85,16 +87,16 @@ local function itemDefToLuantiDef(itemDef)
local modName = Mod.getInfo().shortName
local S = core.get_translator(modName)
itemDef = table.copy(itemDef)
itemDef = tableCopy(itemDef)
local s = itemDef.settings
local c = itemDef.callbacks
if s.addModName then
if s._add_mod_name then
s.name = modName .. ':' .. s.name
end
local title = s.title
local description = s.description
local title = s._title
local description = s._description
if title == nil or title == '' then
title = string.match(s.name, '%S:(%S+)')..'-title'
@@ -104,18 +106,18 @@ local function itemDefToLuantiDef(itemDef)
description = string.match(s.name, '%S:(%S+)')..'-desc'
end
if s.titleColor ~= nil and s.descriptionColor ~= nil then
description = core.colorize(s.titleColor ,S(title))..'\n'..
core.colorize(s.descriptionColor, S(description))
if s._title_color ~= nil and s._description_color ~= nil then
description = colorize(s._title_color ,S(title))..'\n'..
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.')
assert(s._rarity ~= nil, 'The rarity of an item cannot be empty.')
description = addRarityToDesc(s.rarity, description)
description = addRarityToDesc(s._rarity, description)
s.title, s.description = nil, description..core.get_background_escape_sequence('#110F13')
s.description = description..core.get_background_escape_sequence('#110F13')
local luantiDef = defMerge(s, c)
@@ -141,12 +143,17 @@ end
---The alias `table.merge` for EmmyLua
---@type fun(...):(Item.ItemDefinition)
local defMerge = function(...)
return table.merge(...)
return tableMerge(...)
end
---@param def Item.ItemDefinition|Node.NodeDefinition
---@return Item
function Item:new(def)
assert(def.settings.description == nil,
'The item description was specified using `description`, not `_description`. '..
'Please note that the `description` field should not be used when registering an item. '..
'Use `_title` and `_description` instead.')
---Adding default parameters
def = defMerge(def, self.defaultDef, true)
@@ -154,13 +161,13 @@ function Item:new(def)
local instance = getInstance(self, {})
local luantiDef = itemDefToLuantiDef(def)
local visual = def.settings.visual
local visual = def.settings._visual
if visual == nil then
visual = 'item_2d'
end
def.settings.visual = nil
def.settings._visual = nil
if visual == 'item_3d' then
register3dItem(luantiDef)
@@ -186,7 +193,7 @@ end
---@return Item
function Item:getExtended(defaultDef)
---@type Item
local ChildClass = Class.extend(self, {
local ChildClass = extend(self, {
defaultDef = defaultDef,
})

View File

@@ -5,41 +5,40 @@ local Settings = {}
---@type string
Settings.name = ''
---@type string?
Settings.description = nil
---Whether to add the mod name to the settings.name. Default: `true`
---@type boolean?
Settings.addModName = nil
Settings._add_mod_name = nil
---Item description. 1st line of item description.
---@type string?
Settings.title = nil
Settings._title = nil
---Item description. The rest of item description.
---@type string?
Settings.description = nil
Settings._description = nil
---Item title color in description.
---
---Default: `#FFFFFF`
---@type ColorString?
Settings.titleColor = nil
Settings._title_color = nil
---Item description color in description.
---
---Default: `#C0C0C0`
---@type ColorString?
Settings.descriptionColor = nil
---@alias Item.Visual
---'item_2d'|
---'item_3d'
Settings._description_color = nil
---Visual node type.
---@type Item.Visual?
Settings.visual = nil
Settings._visual = nil
---Formal (lore) rarity of an item. Default `common`.
---@type Item.Rarity?
Settings.rarity = nil
Settings._rarity = nil
---Table of groups-characteristics of Item.

View File

@@ -0,0 +1 @@
---@alias Item.Visual 'item_2d'|'item_3d'