Modul:Firestone/Hero: Unterschied zwischen den Versionen
Keine Bearbeitungszusammenfassung Markierung: Manuelle Zurücksetzung |
Keine Bearbeitungszusammenfassung |
||
| Zeile 108: | Zeile 108: | ||
-- Liste/Tabber aller Helden: {{Firestone|hero|list}} | -- Liste/Tabber aller Helden: {{Firestone|hero|list}} | ||
function H.list(frame, args) | function H.list(frame, args) | ||
local iconSize = args.icon_size or args.size or "32" | local iconSize = args.icon_size or args.size or "32" | ||
-- | -- unsere geladene Tabelle (oben: local HEROES = Util.loadTable(...) or {}) | ||
if not next(HEROES) then | |||
return "<div class='error'>[Hero.list] keine Helden in Modul:Firestone/Data/Heroes gefunden.</div>" | |||
end | |||
for name | -- sortierte Namen | ||
local names = {} | |||
for name in pairs(HEROES) do | |||
names[#names+1] = name | names[#names+1] = name | ||
end | end | ||
table.sort(names) | table.sort(names) | ||
-- | -- kleine Hilfsfunktion, die versucht, die Karte zu expanden | ||
local function expandCard(name) | |||
-- 1. Versuch: Vorlage:Card/Hero | |||
local ok, html = pcall(function() | |||
local | |||
-- | |||
local ok, | |||
return frame:expandTemplate{ | return frame:expandTemplate{ | ||
title = 'Vorlage:Card/Hero', | |||
title = 'Card/Hero', | |||
args = { | args = { | ||
name, | [1] = name, | ||
icon_size = iconSize, | icon_size = iconSize, | ||
}, | }, | ||
} | } | ||
end) | end) | ||
if ok and html and html ~= '' then | |||
return html | |||
end | |||
-- wenn beides nicht ging → klarer Hinweis | |||
return "<div class='error'>[Hero.list] Karte für „" .. name .. "“ nicht gefunden.</div>" | |||
end | |||
-- Tabber bauen | |||
local out = {} | |||
out[#out+1] = "<tabber>" | |||
for i, name in ipairs(names) do | |||
local card = expandCard(name) | |||
out[#out+1] = name .. "=\n" .. card | out[#out+1] = name .. "=\n" .. card | ||
if i < #names then | if i < #names then | ||
| Zeile 151: | Zeile 152: | ||
end | end | ||
end | end | ||
out[#out+1] = "</tabber>" | out[#out+1] = "</tabber>" | ||
Version vom 12. November 2025, 13:14 Uhr
Die Dokumentation für dieses Modul kann unter Modul:Firestone/Hero/Doku erstellt werden
-- Modul:Firestone/Hero
local Util = require('Modul:Firestone/Util')
local I18n = require('Modul:Firestone/I18n')
local H = {}
-- nur die eigentlichen Helden laden
local HEROES = Util.loadTable('Modul:Firestone/Data/Heroes') or {}
-- I18n holen
local function getI18n()
if type(I18n) == "table" and type(I18n.get) == "function" then
local ok, data = pcall(I18n.get)
if ok and type(data) == "table" then
return data
end
end
return I18n or {}
end
-- Skins in eine saubere Liste bringen
local function normalizeSkins(skins)
local list = {}
if type(skins) ~= "table" then
return list
end
-- numerische zuerst einsammeln (loadData macht da gern komische Dinge)
local numeric = {}
for k, v in pairs(skins) do
if type(k) == "number" then
numeric[k] = v
else
list[#list+1] = v
end
end
local idx = {}
for k in pairs(numeric) do
idx[#idx+1] = k
end
table.sort(idx)
for _, k in ipairs(idx) do
list[#list+1] = numeric[k]
end
return list
end
-- ========================================================================
-- Avatar/Skins: {{Firestone|hero|Talia|avatar}}
-- ========================================================================
local function buildAvatarMarkup(hero, realKey, i18)
local frame = mw.getCurrentFrame()
local skinLabels = ((i18.ui or {}).skins) or {}
local skins = normalizeSkins(hero.skins)
-- keine Skins → nur Standardbild
if #skins == 0 then
return string.format(
"[[Datei:%s.png|210px|class=avatar-img|link=%s]]",
realKey,
realKey
)
end
-- Tabber bauen
local panels = {}
-- Standard (Name des Helden)
local heroDisplayName = hero.name or realKey
panels[#panels+1] =
heroDisplayName .. "=\n" ..
string.format("[[Datei:%s.png|210px|class=avatar-img|link=%s]]", realKey, realKey)
-- weitere Skins
for _, id in ipairs(skins) do
local idNorm = Util.norm(id)
local label = skinLabels[idNorm] or id
local filename = string.format("%s_%s.png", realKey, id)
panels[#panels+1] =
label .. "=\n" ..
string.format("[[Datei:%s|210px|class=avatar-img|link=%s]]", filename, realKey)
end
local content = table.concat(panels, "\n|-|\n")
return frame:extensionTag('tabber', content)
end
-- UI-Zweig: {{Firestone|hero|ui|basics|class}}
function H.ui(frame, args)
local i18 = getI18n()
local uiRoot = i18.ui or {}
local path = {}
for i = 3, #args do
path[#path+1] = args[i]
end
local val = Util.deepGet(uiRoot, path)
if type(val) == 'string' then
return mw.text.trim(val)
end
return ''
end
-- Liste/Tabber aller Helden: {{Firestone|hero|list}}
function H.list(frame, args)
local iconSize = args.icon_size or args.size or "32"
-- unsere geladene Tabelle (oben: local HEROES = Util.loadTable(...) or {})
if not next(HEROES) then
return "<div class='error'>[Hero.list] keine Helden in Modul:Firestone/Data/Heroes gefunden.</div>"
end
-- sortierte Namen
local names = {}
for name in pairs(HEROES) do
names[#names+1] = name
end
table.sort(names)
-- kleine Hilfsfunktion, die versucht, die Karte zu expanden
local function expandCard(name)
-- 1. Versuch: Vorlage:Card/Hero
local ok, html = pcall(function()
return frame:expandTemplate{
title = 'Vorlage:Card/Hero',
args = {
[1] = name,
icon_size = iconSize,
},
}
end)
if ok and html and html ~= '' then
return html
end
-- wenn beides nicht ging → klarer Hinweis
return "<div class='error'>[Hero.list] Karte für „" .. name .. "“ nicht gefunden.</div>"
end
-- Tabber bauen
local out = {}
out[#out+1] = "<tabber>"
for i, name in ipairs(names) do
local card = expandCard(name)
out[#out+1] = name .. "=\n" .. card
if i < #names then
out[#out+1] = "|-|"
end
end
out[#out+1] = "</tabber>"
return table.concat(out, "\n")
end
-- normaler Held: {{Firestone|hero|Talia|...}}
function H.handle(frame, args)
local name = args[2]
if Util.isEmpty(name) then
return ""
end
-- nur in den Heroes nachgucken
local realKey = Util.pickKey(HEROES, name)
if not realKey then
return name
end
local hero = HEROES[realKey]
local i18 = getI18n()
-- nur {{Firestone|hero|Talia}} → Key
if Util.isEmpty(args[3]) then
return realKey
end
-- Avatar?
if Util.norm(args[3]) == "avatar" then
return buildAvatarMarkup(hero, realKey, i18)
end
-- restlicher Pfad
local path, i = {}, 3
while args[i] do
path[#path+1] = args[i]
i = i + 1
end
local v = Util.deepGet(hero, path)
local last = path[#path] and tostring(path[#path]) or ""
local nlast = Util.norm(last)
if nlast == "unlock_at" then
return Util.heroUnlockText(v, i18)
elseif nlast == "awakening_id" then
return Util.heroAwakeningText(v, i18)
end
if v == nil and nlast == "name" then
return realKey
end
v = Util.autotrFrom(i18, last, v)
if v == nil then
return ""
end
return tostring(v)
end
return H