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
Uses parent Infobox module for consistency
Tag: Reverted
Adds player stats to infobox
 
(12 intermediate revisions by 2 users not shown)
Line 1: Line 1:
local infobox = require('Module:Infobox')
local p = {}
local p = {}


local function humanLabel(key)
local infobox = require("Module:Infobox")
    key = mw.ustring.gsub(key, "%-", " ")
    return mw.ustring.upper(mw.ustring.sub(key,1,1)) .. mw.ustring.sub(key,2)
end
 
local sections = {
    ["Basic Information"] = { "season-joined", "nationality", "discord" },
}


function p.infobox(frame)
function p.infobox(frame)
     local args = frame:getParent().args
     local args = frame:getParent().args
    -- Determine which identifier to use for the head image: prefer UUID if provided
    local head_id = args.uuid and args.uuid ~= '' and args.uuid or args.username


     local used        = {}
     local player_args = {
    local outArgs    = { title = args.username }
        {'t',      args.username},
    local rowCount    = 0
        {'i',      'https://mc-heads.net/player/' .. head_id .. '/110.png'},
    local catCount    = 0
         {'s',      'Biography'},
 
         {'f',       'Username',      args.username},
    for sectionName, keys in pairs(sections) do
         {'f',      'Alias',          args.alias},
         local hasData = false
         {'f',      'Season Joined',  args.seasonjoined},
         for _, k in ipairs(keys) do
        {'f',      'Nationality',     args.nationality},
            if args[k] and args[k] ~= "" then hasData = true; break end
        {'f',      'Discord',        args.discord},
         end
        {'s',      'Personality'},
         if hasData then
         {'f',      'Quote',          args.quote},
            catCount = catCount + 1
        {'f',      'Favourite Item', args.favouriteitem},
            outArgs["category" .. catCount] = sectionName
         {'f',      'Favourite Block', args.favouriteblock},
 
         {'s',      'Government'},
            for _, k in ipairs(keys) do
         {'f',      'Minister Role',  args.ministerrole},
                if args[k] and args[k] ~= "" then
         {'f',      'Assumed Office',  args.assumedoffice},
                    rowCount = rowCount + 1
         {'f',      'Preceded By',    args.precededby},
                    outArgs["label" .. rowCount] = humanLabel(k)
         {'s',      'Links'},
                    outArgs["data"  .. rowCount] = args[k]
        {'f', 'Player Stats', args.uuid and args.uuid ~= '' and ('[https://www.crabcraft.net/stats/' .. args.uuid .. ' Link]') or nil},
                    used[k] = true
     }
                end
            end
         end
    end
 
    local extraKeys = {}
    for k, v in pairs(args) do
         if k ~= "username" and v and v ~= "" and not used[k] then
            table.insert(extraKeys, k)
         end
    end
    if #extraKeys > 0 then
         catCount = catCount + 1
         outArgs["category" .. catCount] = "Additional Data"
         table.sort(extraKeys)
         for _, k in ipairs(extraKeys) do
            rowCount = rowCount + 1
            outArgs["label" .. rowCount] = humanLabel(k)
            outArgs["data"  .. rowCount] = args[k]
        end
     end
 
    outArgs.rows      = rowCount
    outArgs.categories = catCount


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


return p
return p

Latest revision as of 21:14, 30 March 2026

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

local p = {}

local infobox = require("Module:Infobox")

function p.infobox(frame)
    local args = frame:getParent().args
    -- Determine which identifier to use for the head image: prefer UUID if provided
    local head_id = args.uuid and args.uuid ~= '' and args.uuid or args.username

    local player_args = {
        {'t',       args.username},
        {'i',       'https://mc-heads.net/player/' .. head_id .. '/110.png'},
        {'s',       'Biography'},
        {'f',       'Username',       args.username},
        {'f',       'Alias',          args.alias},
        {'f',       'Season Joined',  args.seasonjoined},
        {'f',       'Nationality',     args.nationality},
        {'f',       'Discord',        args.discord},
        {'s',       'Personality'},
        {'f',       'Quote',           args.quote},
        {'f',       'Favourite Item',  args.favouriteitem},
        {'f',       'Favourite Block', args.favouriteblock},
        {'s',       'Government'},
        {'f',       'Minister Role',   args.ministerrole},
        {'f',       'Assumed Office',  args.assumedoffice},
        {'f',       'Preceded By',     args.precededby},
        {'s',       'Links'},
        {'f', 'Player Stats', args.uuid and args.uuid ~= '' and ('[https://www.crabcraft.net/stats/' .. args.uuid .. ' Link]') or nil},
    }

    return infobox.infobox {
        getParent = function() return { args = player_args } end
    }
end

return p