Zuletzt bearbeitet vor 5 Monaten
von Xineohp1506

RezeptInfobox

Version vom 13. November 2024, 00:19 Uhr von Xineohp1506 (Diskussion | Beiträge) (Die Seite wurde neu angelegt: „local p = {} function p.render(frame) local args = frame.args local title = args["title"] or "Rezept" local image = args["image"] local caption = args["caption"] local type = args["type"] or "Speise" local difficulty = tonumber(args["difficulty"]) or 1 local strength = tonumber(args["strength"]) or 1 local categories = args["categories"] local infobox = {} -- Infobox-Header table.insert(infobox, '{| class="wi…“)
(Unterschied) ← Nächstältere Version | Aktuelle Version (Unterschied) | Nächstjüngere Version → (Unterschied)

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

local p = {}

function p.render(frame)
    local args = frame.args
    local title = args["title"] or "Rezept"
    local image = args["image"]
    local caption = args["caption"]
    local type = args["type"] or "Speise"
    local difficulty = tonumber(args["difficulty"]) or 1
    local strength = tonumber(args["strength"]) or 1
    local categories = args["categories"]

    local infobox = {}

    -- Infobox-Header
    table.insert(infobox, '{| class="wikitable infobox"')
    table.insert(infobox, '|+ ' .. title)

    -- Bild
    if image then
        table.insert(infobox, '|-\n| ' .. image)
        if caption then
            table.insert(infobox, '|-\n| ' .. caption)
        end
    end

    -- Schwierigkeitsgrad (Icons variieren je nach Typ)
    table.insert(infobox, '|-\n! Schwierigkeitsgrad\n| ' .. (type == "Speise" and p.getChefHatIcons(difficulty) or p.getCocktailGlassIcons(difficulty)))

    -- Stärke (Alkoholgehalt, angezeigt mit Twemoji12_1f4aa.svg)
    table.insert(infobox, '|-\n! Stärke\n| ' .. p.getStrengthIcons(strength))

    -- Hinweise für Speisen
    if type == "Speise" then
        local hints = p.getHints(args)
        if hints ~= "" then
            table.insert(infobox, '|-\n! Hinweise\n| ' .. hints)
        end
    end

    -- Kategorien
    if categories then
        table.insert(infobox, '|-\n! Kategorien\n| ' .. categories)
    end

    table.insert(infobox, '|}')
    return table.concat(infobox, "\n")
end

-- Funktion zur Anzeige der Schwierigkeitsgrade (Kochmützen)
function p.getChefHatIcons(level)
    local icons = {}
    for i = 1, math.min(level, 5) do
        table.insert(icons, '[[File:One_chef%27s_hat.png|20px|link=]]')
    end
    mw.smw.set("Has Difficulty=" .. level)
    return table.concat(icons, " ")
end

-- Funktion zur Anzeige der Schwierigkeitsgrade (Cocktailgläser)
function p.getCocktailGlassIcons(level)
    local icons = {}
    for i = 1, math.min(level, 5) do
        table.insert(icons, '[[File:Twemoji12_1f378.svg|20px|link=]]')
    end
    mw.smw.set("Has Difficulty=" .. level)
    return table.concat(icons, " ")
end

-- Funktion zur Anzeige der Stärke (Alkoholgehalt)
function p.getStrengthIcons(level)
    local icons = {}
    for i = 1, math.min(level, 5) do
        table.insert(icons, '[[File:Twemoji12_1f4aa.svg|20px|link=]]')
    end
    mw.smw.set("Has Strength=" .. level)
    return table.concat(icons, " ")
end

-- Funktion zur Erzeugung der Hinweise für Speisen
function p.getHints(args)
    local hints = {}
    if args["alcohol"] == "ja" then
        table.insert(hints, '[[File:MHWS_-_Alcoholism.svg|20px|Mit Alkohol|link=|alt=Mit Alkohol]]')
        mw.smw.set("Has RecipeHint=Mit Alkohol")
    end
    if args["noalcohol"] == "ja" then
        table.insert(hints, '[[File:No_alcohol-1.svg|20px|Ohne Alkohol|link=|alt=Ohne Alkohol]]')
        mw.smw.set("Has RecipeHint=Ohne Alkohol")
    end
    if args["vegetarian"] == "ja" then
        table.insert(hints, '[[File:Vegetarian-mark.svg|20px|Vegetarisch|link=|alt=Vegetarisch]]')
        mw.smw.set("Has RecipeHint=Vegetarisch")
    end
    if args["vegan"] == "ja" then
        table.insert(hints, '[[File:Vegan_friendly_icon.svg|20px|Vegan|link=|alt=Vegan]]')
        mw.smw.set("Has RecipeHint=Vegan")
    end
    return table.concat(hints, "<br>")
end

return p