Modul:Firestone/Hero
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 = {}
-- alle Heldentabellen zusammenziehen
local HEROES = Util.mergeSources{
'Modul:Firestone/Data/Heroes',
'Modul:Firestone/Data/Guardians',
'Modul:Firestone/Data/WM',
}
-- I18n holen (wir lassen dir deine bisherige Struktur)
local function getI18n()
-- falls dein Haupt-I18n ein .get() hat:
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
-- sonst direkt
return I18n or {}
end
-- ========================================================================
-- Avatar/Skins nach deiner Konvention:
-- default: Name.png
-- skins: Name_<id>.png
-- Labels: aus i18.heroes.ui.skins[id]
-- ========================================================================
local function buildAvatarMarkup(hero, realKey, i18)
-- i18n-Skin-Labels einsammeln
local skinLabels = (((i18.heroes or {}).ui or {}).skins) or {}
local out = {}
-- helper: einzelnes Bild als Wikitext
local function imgLine(label, filename)
return string.format("%s=[[Datei:%s|210px|class=ic-avatar-img|link=%s]]",
label, filename, realKey
)
end
local skins = hero.skins
-- FALL 1: es gibt gar keine skins → nur Name.png
if type(skins) ~= "table" or #skins == 0 then
return string.format(
"[[Datei:%s.png|210px|class=ic-avatar-img|link=%s]]",
realKey,
realKey
)
end
-- FALL 2: es gibt mindestens 1 Skin → wir machen Tabber
out[#out+1] = "<tabber>"
-- zuerst der Standard
local defaultLabel = skinLabels["default"] or "Standard"
out[#out+1] = imgLine(defaultLabel, realKey .. ".png")
out[#out+1] = "|-|"
-- dann alle weiteren
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)
out[#out+1] = imgLine(label, filename)
out[#out+1] = "|-|"
end
-- letztes |-|
out[#out] = nil
out[#out+1] = "</tabber>"
return table.concat(out, "\n")
end
-- UI-Zweig: {{Firestone|hero|ui|basics|class}}
function H.ui(frame, args)
local i18 = getI18n()
-- so wie du dein I18n gepostet hast:
-- Modul:Firestone/I18n/Heroes → wird in getI18n() zusammengeführt
-- und liegt dann unter i18.heroes.ui
local uiRoot = (i18.heroes and i18.heroes.ui) or (i18.ui) or {}
-- alles ab dem 3. Argument ist der Pfad: basics → class
local path = {}
for i = 3, #args do
path[#path+1] = args[i]
end
-- über deinen Util-Helfer tief holen
local val = Util.deepGet(uiRoot, path)
-- WICHTIG: trimmen, damit kein führendes \n mehr drin ist
if type(val) == 'string' then
return mw.text.trim(val)
end
return ''
end
-- normaler Held: {{Firestone|hero|Talia|...}}
function H.handle(frame, args)
local name = args[2]
if Util.isEmpty(name) then
return ""
end
local realKey = Util.pickKey(HEROES, name)
if not realKey then
-- nichts gefunden → gib den angefragten Namen zurück
return name
end
local hero = HEROES[realKey]
local i18 = getI18n()
-- nur {{Firestone|hero|Talia}} → Key
if Util.isEmpty(args[3]) then
return realKey
end
-- SPEZIAL: Avatar angefordert
if Util.norm(args[3]) == "avatar" then
return buildAvatarMarkup(hero, realKey, i18)
end
-- restliche Pfadteile einsammeln
local path, i = {}, 3
while args[i] do
table.insert(path, 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)
-- spezielle Felder über Util übersetzen lassen
if nlast == "unlock_at" then
return Util.heroUnlockText(v, i18)
elseif nlast == "awakening_id" then
return Util.heroAwakeningText(v, i18)
end
-- "name" nicht vorhanden? → Key
if v == nil and nlast == "name" then
return realKey
end
-- generisches autotr für class / spec / resource ...
v = Util.autotrFrom(i18, last, v)
if v == nil then
return ""
end
return tostring(v)
end
return H