Module:InfoboxItem: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
Line 72: | Line 72: | ||
table.insert(out, '| ' .. (data.StackSize or '')) | table.insert(out, '| ' .. (data.StackSize or '')) | ||
table.insert(out, '|}') | table.insert(out, '|}') | ||
return table.concat(out, '\n') | |||
end | |||
function p.show_open(frame) | |||
local itemModule = frame.args[1] | |||
if not itemModule or itemModule == "" then | |||
return "❌ No data module provided" | |||
end | |||
local data = safeLoadData(itemModule) | |||
if not data then | |||
return "" | |||
end | |||
local pageName = splitCamelCase(itemModule) | |||
local imageName = (data.Image or "") .. ".png" | |||
local out = {} | |||
table.insert(out, '{| class="infobox"') | |||
-- Первая строка: объединённая ячейка, иконка + название со ссылками | |||
table.insert(out, '|-') | |||
table.insert(out, '| colspan="2" style="text-align:center;" | ' .. | |||
string.format('[[File:%s|64px|link=%s]] [[%s]]', | |||
imageName, pageName, pageName)) | |||
return table.concat(out, '\n') | return table.concat(out, '\n') |
Revision as of 09:33, 2 August 2025
Documentation for this module may be created at Module:InfoboxItem/doc
-- Module:InfoboxItem
local p = {}
local function safeLoadData(name)
local success, data = pcall(function()
return mw.loadData('Module:Data/' .. name)
end)
if success and type(data) == "table" then
return data
end
return nil
end
local function splitCamelCase(str)
str = str:gsub("_", " ")
str = str:gsub("(%l)(%u)", "%1 %2")
str = str:gsub("(%a)(%d)", "%1 %2")
str = str:gsub("(%d)(%a)", "%1 %2")
return str
end
function p.show_inline(frame)
local itemModule = frame.args[1]
if not itemModule or itemModule == "" then
return "❌ No data module provided"
end
local data = safeLoadData(itemModule)
if not data then
return ""
end
local pageName = splitCamelCase(itemModule)
local imageName = (data.Image or "") .. ".png"
return string.format("[[File:%s|32px|link=%s]] [[%s]]",
imageName, pageName, pageName);
end
function p.show(frame)
local itemModule = frame.args[1]
if not itemModule or itemModule == "" then
return "❌ No data module provided"
end
local data = safeLoadData(itemModule)
if not data then
return ""
end
local pageName = splitCamelCase(itemModule)
local imageName = (data.Image or "") .. ".png"
local out = {}
table.insert(out, '{| class="infobox"')
-- Первая строка: объединённая ячейка, иконка + название со ссылками
table.insert(out, '|-')
table.insert(out, '| colspan="2" style="text-align:center;" | ' ..
string.format('[[File:%s|64px|link=%s]] [[%s]]',
imageName, pageName, pageName))
-- Остальные поля
table.insert(out, '|-')
table.insert(out, '! Category')
table.insert(out, '| ' .. (data.Category or ''))
table.insert(out, '|-')
table.insert(out, '! Tier')
table.insert(out, '| ' .. (data.Tier or ''))
table.insert(out, '|-')
table.insert(out, '! Stack size')
table.insert(out, '| ' .. (data.StackSize or ''))
table.insert(out, '|}')
return table.concat(out, '\n')
end
function p.show_open(frame)
local itemModule = frame.args[1]
if not itemModule or itemModule == "" then
return "❌ No data module provided"
end
local data = safeLoadData(itemModule)
if not data then
return ""
end
local pageName = splitCamelCase(itemModule)
local imageName = (data.Image or "") .. ".png"
local out = {}
table.insert(out, '{| class="infobox"')
-- Первая строка: объединённая ячейка, иконка + название со ссылками
table.insert(out, '|-')
table.insert(out, '| colspan="2" style="text-align:center;" | ' ..
string.format('[[File:%s|64px|link=%s]] [[%s]]',
imageName, pageName, pageName))
return table.concat(out, '\n')
end
return p