Модуль:Craft
Материал из ELDEN RING Вики
Дополнительные действия
Для документации этого модуля может быть создана страница Модуль:Craft/doc
local p = {}
local tableLua = require('Module:TableLua')
local getArgs = require('Module:Arguments').getArgs
local objectLua = require('Module:Object')
function p.renderTable(frame)
local args = getArgs(frame)
local props = {
hideCaption = 'true',
class = args['класс'] or '',
columns = {
{ id = 'item', label = 'Предмет', textAlign = 'start' },
{ id = 'recipe', label = 'Рецепт', textAlign = 'start' }
},
data = {}
}
local i = 1
while true do
local itemKey = 'предмет' .. i
local recipeKey = 'рецепт' .. i
local itemValue = args[itemKey]
local recipeValue = args[recipeKey]
if not itemValue and not recipeValue then
break
end
itemValue = itemValue or ''
recipeValue = recipeValue or ''
local formattedItem = ''
if itemValue ~= '' then
local mainItem, itemLetterCount = string.match(itemValue, "^%s*(.-)%s*%*%s*(%d+)%s*$")
if mainItem and itemLetterCount then
formattedItem = objectLua.render(frame, { mainItem, x = itemLetterCount })
else
local trimmedItem = mw.text.trim(itemValue)
if trimmedItem ~= '' then
formattedItem = objectLua.render(frame, { trimmedItem })
end
end
end
local formattedRecipe = {}
if recipeValue ~= '' then
for part in string.gmatch(recipeValue, "[^;]+") do
local ingredient, count = string.match(part, "^%s*(.-)%s*%*%s*(%d+)%s*$")
if ingredient and count then
local objHtml = objectLua.render(frame, { ingredient, x = count })
table.insert(formattedRecipe, objHtml)
else
local trimmedPart = mw.text.trim(part)
if trimmedPart ~= '' then
local objHtml = objectLua.render(frame, { trimmedPart })
table.insert(formattedRecipe, objHtml)
end
end
end
end
local recipeCellHtml = table.concat(formattedRecipe, '<br />')
table.insert(props.data, { formattedItem, recipeCellHtml })
i = i + 1
end
return tableLua.render(props)
end
return p