Added auto-completion of items title and description for localization
This commit is contained in:
@@ -25,13 +25,38 @@ local defMerge = function(...)
|
|||||||
return table.merge(...)
|
return table.merge(...)
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param itemDef Item.ItemDefinition
|
---@param itemDef Item.ItemDefinition
|
||||||
---@return NodeDefinition|ItemDefinition
|
---@param addModName boolean? Whether to add the mod name to the settings.name. Default: `true`
|
||||||
local function itemDefToLuantiDef(itemDef)
|
---@return NodeDefinition|ItemDefinition
|
||||||
|
local function itemDefToLuantiDef(itemDef, addModName)
|
||||||
|
local modName = Mod.getInfo().shortName
|
||||||
|
local S = core.get_translator(modName)
|
||||||
|
|
||||||
|
if addModName == nil then
|
||||||
|
addModName = true
|
||||||
|
end
|
||||||
|
|
||||||
itemDef = table.copy(itemDef)
|
itemDef = table.copy(itemDef)
|
||||||
local s = itemDef.settings
|
local s = itemDef.settings
|
||||||
local c = itemDef.callbacks
|
local c = itemDef.callbacks
|
||||||
local description = s.title .. "\n" .. s.description
|
|
||||||
|
if addModName then
|
||||||
|
s.name = modName .. ':' .. s.name
|
||||||
|
end
|
||||||
|
|
||||||
|
local title = s.title
|
||||||
|
local description = s.description
|
||||||
|
|
||||||
|
if title == nil or title == '' then
|
||||||
|
title = string.match(s.name, '%S:(%S+)')..'-title'
|
||||||
|
end
|
||||||
|
|
||||||
|
if description == nil or description == '' then
|
||||||
|
description = string.match(s.name, '%S:(%S+)')..'-description'
|
||||||
|
end
|
||||||
|
|
||||||
|
local description = S(title)..'\n'..S(description)
|
||||||
|
|
||||||
s.title, s.description = nil, description
|
s.title, s.description = nil, description
|
||||||
|
|
||||||
local luantiDef = defMerge(s, c)
|
local luantiDef = defMerge(s, c)
|
||||||
@@ -65,23 +90,13 @@ end
|
|||||||
---@param addModName boolean? Whether to add the mod name to the settings.name. Default: `true`
|
---@param addModName boolean? Whether to add the mod name to the settings.name. Default: `true`
|
||||||
---@return Item
|
---@return Item
|
||||||
function Item:new(itemDef, addModName)
|
function Item:new(itemDef, addModName)
|
||||||
if addModName == nil then
|
|
||||||
addModName = true
|
|
||||||
end
|
|
||||||
|
|
||||||
---Adding default parameters
|
---Adding default parameters
|
||||||
itemDef = defMerge(itemDef, self.defaultDef, true)
|
itemDef = defMerge(itemDef, self.defaultDef, true)
|
||||||
|
|
||||||
local modName = Mod.getInfo().shortName
|
|
||||||
|
|
||||||
if addModName then
|
|
||||||
itemDef.settings.name = modName .. ':' .. itemDef.settings.name
|
|
||||||
end
|
|
||||||
|
|
||||||
---@type Item
|
---@type Item
|
||||||
local instance = setmetatable({}, {__index = self})
|
local instance = setmetatable({}, {__index = self})
|
||||||
|
|
||||||
local luantiDef = itemDefToLuantiDef(itemDef)
|
local luantiDef = itemDefToLuantiDef(itemDef, addModName)
|
||||||
local visual = itemDef.settings.visual
|
local visual = itemDef.settings.visual
|
||||||
|
|
||||||
if visual == nil then
|
if visual == nil then
|
||||||
|
|||||||
@@ -22,12 +22,9 @@ for i=0, 3 do
|
|||||||
Plant:new({
|
Plant:new({
|
||||||
settings = {
|
settings = {
|
||||||
name = 'plant'..tostring(i),
|
name = 'plant'..tostring(i),
|
||||||
description = 'Plant',
|
title = 'Plant',
|
||||||
tiles = { ts:t(i,0) },
|
tiles = { ts:t(i,0) },
|
||||||
place_param2 = 3,
|
place_param2 = 3,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
core.log(dump(core.registered_nodes))
|
|
||||||
|
|||||||
Reference in New Issue
Block a user