Modul:ZauberNachGrad: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
Stewie (Diskussion | Beiträge) Keine Bearbeitungszusammenfassung |
Stewie (Diskussion | Beiträge) Keine Bearbeitungszusammenfassung |
||
Zeile 49: | Zeile 49: | ||
end | end | ||
local | local schuleArg = frame.args["Schule"] or "Unbekannt" | ||
table.insert(output, string.format('<h2>%d Zauber der Magieschule</h2>', totalCount)) | table.insert(output, string.format('<h2>%d Zauber der Magieschule %s</h2>', totalCount, schuleArg)) | ||
table.insert(output, '<table class="wikitable">') | table.insert(output, '<table class="wikitable">') | ||
table.insert(output, '<tr><th>Bild</th><th>Titel</th><th>Beschreibung</th><th>Typus</th><th>Art</th><th>Schwierigkeit</th><th>Option</th><th>Weitere Magieschulen</th></tr>') | table.insert(output, '<tr><th>Bild</th><th>Titel</th><th>Beschreibung</th><th>Typus</th><th>Art</th><th>Schwierigkeit</th><th>Option</th><th>Weitere Magieschulen</th></tr>') | ||
-- Hilfsfunktion zur sicheren Stringausgabe | |||
-- Hilfsfunktion zur sicheren | |||
local function safeString(value) | local function safeString(value) | ||
if type(value) == "table" then | if type(value) == "table" then | ||
local parts = {} | local parts = {} | ||
for _, v in ipairs(value) do table.insert(parts, | for _, v in ipairs(value) do | ||
if type(v) == "table" and v.text then | |||
table.insert(parts, v.text) | |||
else | |||
table.insert(parts, tostring(v)) | |||
end | |||
end | |||
return table.concat(parts, ", ") | return table.concat(parts, ", ") | ||
elseif value and value ~= "" then | elseif value and value ~= "" then | ||
return | if type(value) == "table" and value.text then | ||
return value.text | |||
end | |||
return tostring(value) | |||
else | else | ||
return "–" | return "–" | ||
end | end | ||
end | |||
-- Vergleichsbereinigung | |||
local function clean(str) | |||
return mw.ustring.lower(mw.text.trim(tostring(str))) | |||
end | end | ||
Zeile 93: | Zeile 92: | ||
image = "Icon_Vorlage_Platzhalter_dunkel_64.png" | image = "Icon_Vorlage_Platzhalter_dunkel_64.png" | ||
end | end | ||
local imageTag = string.format('[[Datei:%s|50px]]', | local imageTag = string.format('[[Datei:%s|50px]]', image) | ||
local typus = safeString(spell["Zaubertypus"]) | local typus = safeString(spell["Zaubertypus"]) | ||
Zeile 100: | Zeile 99: | ||
local option = safeString(spell["Zauberoption"]) | local option = safeString(spell["Zauberoption"]) | ||
-- Magieschulen | -- Andere Magieschulen herausfiltern | ||
local | local magieschulen = spell["Magieschule"] | ||
local | local weitere = {} | ||
if magieschulen then | |||
if type(magieschulen) ~= "table" then | |||
if | magieschulen = { magieschulen } | ||
if type( | |||
end | end | ||
for _, s in ipairs( | for _, s in ipairs(magieschulen) do | ||
local | local label = (type(s) == "table" and s.text) or tostring(s) | ||
if clean(label) ~= clean(schuleArg) then | |||
table.insert(weitere, label) | |||
table.insert( | |||
end | end | ||
end | end | ||
end | end | ||
local schuleAnzeigen = (#weitere > 0) and table.concat(weitere, ", ") or "–" | |||
table.insert(output, string.format( | table.insert(output, string.format( |
Version vom 16. Mai 2025, 09:02 Uhr
Die Dokumentation für dieses Modul kann unter Modul:ZauberNachGrad/Doku erstellt werden
--[[
Erstellt eine tabellarische Übersicht aller Zauber einer Magieschule,
gruppiert nach Zaubergrad mit Vorschaubild, Titel, Kurzbeschreibung und weiteren Eigenschaften.
getSpellList – holt die Daten.
renderSpellList – rendert die HTML-Ausgabe als Tabelle.
Verwendung:
{{#invoke:ZauberNachGrad|renderSpellList|Schule=Kampfmagie}}
--]]
local p = {}
-- Holt alle Zauber einer Magieschule, gruppiert nach Grad
function p.getSpellList(frame)
local schule = frame.args['Schule']
if not schule then return nil end
local spellData = {}
for grad = 0, 5 do
local query = string.format(
'[[Category::Zauber]][[%s::%d]]|?Seitentitel|?Kurzbeschreibung|?Profilbild|?Zaubertypus|?Zauberart|?Zauberschwierigkeit|?Zauberoption|?Magieschule|mainlabel=-|limit=199',
schule, grad
)
local result = mw.smw.ask(query)
if result then
spellData[grad] = result
end
end
return spellData
end
-- Gibt die Tabellenansicht mit Vorschaubild, Titel, Beschreibung und weiteren Attributen aus
function p.renderSpellList(frame)
local spellsByGrad = p.getSpellList(frame)
if not spellsByGrad then
return "Keine Zauber gefunden."
end
local output = {}
local totalCount = 0
for grad = 0, 5 do
local spells = spellsByGrad[grad]
if spells then
totalCount = totalCount + #spells
end
end
local schuleArg = frame.args["Schule"] or "Unbekannt"
table.insert(output, string.format('<h2>%d Zauber der Magieschule %s</h2>', totalCount, schuleArg))
table.insert(output, '<table class="wikitable">')
table.insert(output, '<tr><th>Bild</th><th>Titel</th><th>Beschreibung</th><th>Typus</th><th>Art</th><th>Schwierigkeit</th><th>Option</th><th>Weitere Magieschulen</th></tr>')
-- Hilfsfunktion zur sicheren Stringausgabe
local function safeString(value)
if type(value) == "table" then
local parts = {}
for _, v in ipairs(value) do
if type(v) == "table" and v.text then
table.insert(parts, v.text)
else
table.insert(parts, tostring(v))
end
end
return table.concat(parts, ", ")
elseif value and value ~= "" then
if type(value) == "table" and value.text then
return value.text
end
return tostring(value)
else
return "–"
end
end
-- Vergleichsbereinigung
local function clean(str)
return mw.ustring.lower(mw.text.trim(tostring(str)))
end
for grad = 0, 5 do
local spells = spellsByGrad[grad]
if spells and #spells > 0 then
table.insert(output, string.format('<tr><th colspan="8">Zaubergrad %d</th></tr>', grad))
for _, spell in ipairs(spells) do
local title = spell["Seitentitel"] or "Unbenannt"
local description = spell["Kurzbeschreibung"] or ""
local image = spell["Profilbild"]
if not image or image == "" then
image = "Icon_Vorlage_Platzhalter_dunkel_64.png"
end
local imageTag = string.format('[[Datei:%s|50px]]', image)
local typus = safeString(spell["Zaubertypus"])
local art = safeString(spell["Zauberart"])
local schwierigkeit = safeString(spell["Zauberschwierigkeit"])
local option = safeString(spell["Zauberoption"])
-- Andere Magieschulen herausfiltern
local magieschulen = spell["Magieschule"]
local weitere = {}
if magieschulen then
if type(magieschulen) ~= "table" then
magieschulen = { magieschulen }
end
for _, s in ipairs(magieschulen) do
local label = (type(s) == "table" and s.text) or tostring(s)
if clean(label) ~= clean(schuleArg) then
table.insert(weitere, label)
end
end
end
local schuleAnzeigen = (#weitere > 0) and table.concat(weitere, ", ") or "–"
table.insert(output, string.format(
'<tr><td>%s</td><td>[[%s]]</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>',
imageTag, title, description, typus, art, schwierigkeit, option, schuleAnzeigen
))
end
end
end
table.insert(output, '</table>')
return table.concat(output, '\n')
end
return p