Jump to content

📢 Please make sure to read our Style Guide before editing. For questions, suggestions, or technical issues, please contact Noah. ✖

Module:Infobox Player: Difference between revisions

From CrabCraft Wiki
Created player infobox module
 
testing a system to dynamically add fields
Line 1: Line 1:
local infobox = require('Module:Infobox')
local infobox = require('Module:Infobox')
local p = {}
local p = {}
-- Turn "seasonjoined" into "Seasonjoined" (or tweak this to split words on underscores/camelCase)
local function humanLabel(name)
    return mw.ustring.upper(mw.ustring.sub(name,1,1)) .. mw.ustring.sub(name,2)
end


function p.infobox(frame)
function p.infobox(frame)
local args = frame:getParent().args
    local args     = frame:getParent().args
local playerArgs = {
    local outArgs  = { title = args.username }
title = args.username,
    local count    = 0
rows = 3,
label1 = 'Season Joined',
data1 = args.seasonjoined,
label2 = 'Nationality',
data2 = args.nationality,
label3 = 'Discord',
data3 = args.discord,
}


local newFrame = {
    for key, val in pairs(args) do
getParent = function()
        if key ~= 'username' and val and val ~= '' then
return { args = playerArgs }
            count = count + 1
end
            outArgs['label'..count] = humanLabel(key)
}
            outArgs['data' ..count] = val
        end
    end


return infobox.infobox(newFrame)
    outArgs.rows = count
    return infobox.infobox{
        getParent = function() return { args = outArgs } end
    }
end
end


return p
return p

Revision as of 15:28, 21 June 2025

Documentation for this module may be created at Module:Infobox Player/doc

local infobox = require('Module:Infobox')
local p = {}

-- Turn "seasonjoined" into "Seasonjoined" (or tweak this to split words on underscores/camelCase)
local function humanLabel(name)
    return mw.ustring.upper(mw.ustring.sub(name,1,1)) .. mw.ustring.sub(name,2)
end

function p.infobox(frame)
    local args     = frame:getParent().args
    local outArgs  = { title = args.username }
    local count    = 0

    for key, val in pairs(args) do
        if key ~= 'username' and val and val ~= '' then
            count = count + 1
            outArgs['label'..count] = humanLabel(key)
            outArgs['data' ..count] = val
        end
    end

    outArgs.rows = count
    return infobox.infobox{
        getParent = function() return { args = outArgs } end
    }
end

return p