Zuletzt bearbeitet vor 2 Monaten
von Xineohp1506

Projekt

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

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

function projekt.render(frame)
    local args = getArgs(frame)
    local frame = mw.getCurrentFrame()
    local output = ""

    -- DISPLAYTITLE setzen
    if args["Titel"] then
        helper.setDisplayTitle({title = args["Titel"]})
    end

    if args["Beschreibung"] then
        local truncatedDesc = mw.ustring.sub(args["Beschreibung"], 1, 250)
        helper.setProperty({args = {["LPON:Beschreibung"] = truncatedDesc}})
    end

    -- Infobox Container
    output = output .. '<div class="infobox lpnon-infobox">\n'

    -- Coverbild in der Infobox
    local coverImage = args["Coverbild"] or "DefaultProjektCover.webp"
    output = output .. '[[File:' .. coverImage .. '|250px|center|alt=Cover von ' .. (args["Titel"] or "Projekt") .. ']]\n'

    -- Titel in der Infobox
    output = output .. '<div class="infobox-title">' .. (args["Titel"] or "Unbekannt") .. '</div>\n'

    -- Tabelleninhalt der Infobox
    output = output .. '<table class="infobox-table">\n'

	-- Game
    if args["Game"] and args["Game"] ~= "" then
        helper.setProperty({ args = { ["LPON:Game"] = args["Game"] } })
        output = output .. '<tr><th>Game</th><td>[[' .. args["Game"] .. '|' .. args["Game"] .. ']]</td></tr>\n'
    end
    
    -- Status
    if args["Status"] and args["Status"] ~= "" then
        helper.setProperty({ args = { ["LPON:Status"] = args["Status"] } })
        output = output .. '<tr><th>Status</th><td>' .. args["Status"] .. '</td></tr>\n'
    end

    -- Spieler
    if args["Spieler"] and args["Spieler"] ~= "" then
        local playerList = {}
        for player in mw.text.gsplit(args["Spieler"], ",") do
            player = mw.text.trim(player)
            helper.setProperty({ args = { ["LPON:Spieler"] = player } })
            table.insert(playerList, player)
        end
        output = output .. '<tr><th>Spieler</th><td>' .. table.concat(playerList, ", ") .. '</td></tr>\n'
    end

    -- Startdatum
    if args["Startdatum"] and args["Startdatum"] ~= "" then
        helper.setProperty({ args = { ["LPON:Startdatum"] = args["Startdatum"] } })
        output = output .. '<tr><th>Startdatum</th><td>' .. args["Startdatum"] .. '</td></tr>\n'
    end

    output = output .. '</table>\n'  -- Ende der Tabelle
    output = output .. '</div>\n'  -- Ende der Infobox
    
    -- Beschreibung
    output = output .. string.format('<div class="lpnon-description">%s</div>', args["Beschreibung"] or "Keine Beschreibung verfügbar.")
    
	-- Screenshots ausgeben
	output = output .. '<h2>Screenshots</h2>\n'
	if args["Bilder"] and args["Bilder"] ~= "" then
	    output = output .. '<div class="lpon-gallery">\n'
	    for imageData in mw.text.gsplit(args["Bilder"], ",") do
	        local parts = mw.text.split(imageData, "|")
	        local image = mw.text.trim(parts[1])
	        local caption = parts[2] and mw.text.trim(parts[2]) or ""
	        output = output .. string.format('[[File:%s|thumb|alt=%s|%s]]\n', image, caption, caption)
	    end
	    output = output .. '</div>\n'
	else
	    output = output .. '<p>Keine Bilder verfügbar.</p>\n'
	end
    
	-- Spieler Links
	output = output .. '<h2>Links</h2>\n'
	output = output .. '<div class="lpon-links">\n'
	if args["Spieler"] and args["Spieler"] ~= "" then
	    for player in mw.text.gsplit(args["Spieler"], ",") do
	        player = mw.text.trim(player)
	        local linkPage = "LetsPlayOrNot:" .. player .. "/Links"
	        local rawContent = transcluder.get(linkPage)
	        local parsedContent = frame:preprocess(rawContent)
	        output = output .. '<div class="lpon-player-links"><h3>'  .. player ..  ':</h3>\n'
	        output = output .. parsedContent .. '\n'
	        output = output .. '</div>\n'
	    end
	else
	    output = output .. '<p>Keine Links verfügbar.</p>\n'
	end
	output = output .. '</div>\n'

    -- Mods (optional Subseite oder direkt)
    if args["useSubpage"] == "true" then
        output = output .. string.format('<div class="lpnon-mods"><a href="%s/Mods">Zur Modliste</a></div>', mw.title.getCurrentTitle().text)
    else
        output = output .. '<div class="lpnon-mods"><ul><li>Mod 1</li><li>Mod 2</li></ul></div>'
    end

    -- Folgen (optional Subseite oder direkt)
    if args["useEpisodesSubpage"] == "true" then
        output = output .. string.format('<div class="lpnon-episodes"><a href="%s/Folgen">Zur Folgenübersicht</a></div>', mw.title.getCurrentTitle().text)
    else
        output = output .. '<div class="lpnon-episodes"><ul><li>Folge 1</li><li>Folge 2</li></ul></div>'
    end

    -- Kategorien setzen
    local categories = {} -- Korrekte Initialisierung der Tabelle
    
    if args["Spieler"] then
        for player in mw.text.gsplit(args["Spieler"], ",") do
            table.insert(categories, "LPON:Spieler:" .. mw.text.trim(player))
        end
    end
    if args["Status"] then
        table.insert(categories, "LPON:Status:" .. args["Status"])
    end
    
    if args["Titel"] then
        table.insert(categories, "LPON:Projekte:" .. args["Titel"])
    end
    
    -- Hinzufügen allgemeiner Kategorien
    table.insert(categories, "All LPON")

    output = output .. helper.addCategories({categories = categories, sortkey = args["Titel"]})

    return output
end

return projekt