Zuletzt bearbeitet vor 21 Stunden
von Xineohp1506

Player

Die Dokumentation für dieses Modul kann unter Modul:LPON/Player/Doku erstellt werden

local player = {}
local helper = require("Module:LPON/Helper")
local transcluder = require("Module:Transcluder")
local getArgs = require("Module:Arguments").getArgs

function player.render(frame)
    local args = getArgs(frame)
    local output = ''
    local name = args["Name"] or mw.title.getCurrentTitle().text
    local cleanName = helper.cleanString(name)

    -- DISPLAYTITLE setzen
    helper.setDisplayTitle({ title = name })

    -- Semantische Eigenschaften
    helper.setProperty({ args = { ["LPON:Spieler"] = name } })
    if args["Status"] then helper.setProperty({ args = { ["LPON:Status"] = args["Status"] } }) end
    if args["Beitritt"] then helper.setProperty({ args = { ["LPON:Beitritt"] = args["Beitritt"] } }) end
    if args["Rolle"] then helper.setProperty({ args = { ["LPON:Rolle"] = args["Rolle"] } }) end

    -- Headergrafik aus MediaWiki-Datei (oder Default)
    local headerImage = args["Headerbild"] or "LPON:DefaultHeaderPlayer.webp"
    output = output .. string.format(
        '<div class="lpon-player-header">[[File:%s|class=lpon-player-header-img|alt=Headerbild]]</div>\n',
        headerImage
    )

    -- Container für alle Boxen
    output = output .. '<div class="lpon-player-container">'

    -- Über mich
    output = output .. '<div class="lpon-player-box">\n'
    output = output .. '    <h2>Über mich</h2>\n'
    output = output .. '    <p>' .. (args["Über"] or "Keine Beschreibung vorhanden.") .. '</p>\n'
    output = output .. '</div>\n'

    -- Allgemein + Statistiken
    local projectQuery = string.format("[[LPON:Spieler::%s]][[LPON:Typ::Projekt]]|?LPON:Status", name)
    local projectResult = mw.smw.getQueryResult(projectQuery)
    local projekteCount = projectResult and #projectResult.results or 0

    local episodeQuery = string.format("[[LPON:Spieler::%s]][[LPON:Typ::Episode]]", name)
    local episodeResult = mw.smw.getQueryResult(episodeQuery)
    local episoden = episodeResult and #episodeResult.results or 0

    output = output .. '<div class="lpon-player-box">\n'
    output = output .. '    <h2>Allgemein</h2>\n'
    output = output .. '    <ul>\n'
    output = output .. '        <li><b>Status:</b> ' .. (args["Status"] or "Unbekannt") .. '</li>\n'
    output = output .. '        <li><b>Beitritt:</b> ' .. (args["Beitritt"] or "Unbekannt") .. '</li>\n'
    output = output .. '        <li><b>Rolle:</b> ' .. (args["Rolle"] or "Unbekannt") .. '</li>\n'
    output = output .. '    </ul>\n'
    output = output .. '    <h2>Statistiken</h2>\n'
    output = output .. '    <ul>\n'
    output = output .. '        <li><b>Projekte:</b> ' .. projekteCount .. '</li>\n'
    output = output .. '        <li><b>Episoden:</b> ' .. episoden .. '</li>\n'
    output = output .. '    </ul>\n'
    output = output .. '</div>\n'

    -- Projekte (max. 8 anzeigen + Status in Klammern)
    output = output .. '<div class="lpon-player-box">\n'
    output = output .. '    <h2>Projekte</h2>\n'
    output = output .. '    <ul>'
    local maxProjects = 8
    local projectCount = 0
    local hasMoreProjects = false

    if projectResult and projectResult.results then
        for _, result in ipairs(projectResult.results) do
            projectCount = projectCount + 1
            if projectCount > maxProjects then
                hasMoreProjects = true
                break
            end

            local projTitle = result.fulltext or "Unbekannt"
            local status = result.printouts["LPON:Status"] and result.printouts["LPON:Status"][1] or ""
            local display = projTitle
            if status and status ~= "" then
                display = string.format("%s (%s)", projTitle, status)
            end
            output = output .. string.format('<li>[[%s|%s]]</li>', projTitle, display)
        end
    else
        output = output .. '<li>Keine Projekte hinterlegt.</li>'
    end
    output = output .. '</ul>\n'
    if hasMoreProjects then
        output = output .. string.format('<p>[[LetsPlayOrNot:%s/Projekte|Alle Projekte anzeigen]]</p>', name)
    end
    output = output .. '</div>\n'

    output = output .. '</div>' -- Ende von .lpon-player-container

    -- Links (falls aktiviert)
    if args["Links"] == "true" then
        output = output .. '<div class="lpon-player-links">\n'
        output = output .. '    <h2>Links</h2>'
        local linkPage = 'LetsPlayOrNot:' .. name .. '/Links'
        local rawContent = transcluder.get(linkPage)
        output = output .. frame:preprocess(rawContent)
        output = output .. '</div>'
    end

    return output
end

return player