Module:InfoboxItem: Difference between revisions

From Evospace
Jump to navigation Jump to search
No edit summary
No edit summary
Line 1: Line 1:
-- Module:InfoboxItem
-- Module:InfoboxItem
local p = {}
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


function p.show(frame)
function p.show(frame)
Line 8: Line 18:
     end
     end
      
      
     local data = mw.loadData('Module:Data/' .. itemModule)
     local data = safeLoadData(name)
    if not data then
        return "" -- ничего не выводим
    end


     local description = ""
     local description = ""

Revision as of 08:55, 31 July 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

function p.show(frame)
    local itemModule = frame.args[1]
    if not itemModule or itemModule == "" then
        return "❌ No data module provided"
    end
    
    local data = safeLoadData(name)
    if not data then
        return "" -- ничего не выводим
    end

    local description = ""
    if data.DescriptionParts and #data.DescriptionParts > 0 then
        description = table.concat(data.DescriptionParts[1], " ")
    end

    local out = {}
    table.insert(out, '{| class="infobox"')
    table.insert(out, '|-')
    table.insert(out, '| colspan="2" style="text-align:center;" | [[File:' .. (data.Image..'.png' or '') .. '|64px]]')
    table.insert(out, '|-')
    table.insert(out, '! Name')
    table.insert(out, '| ' .. (data.Name or ''))
    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

return p