Zum Inhalt springen


Modul:HeroCard: Unterschied zwischen den Versionen

Aus Firestone Idle RPG Wiki
Keine Bearbeitungszusammenfassung
Keine Bearbeitungszusammenfassung
Zeile 14: Zeile 14:
end
end


-- Lazy load der ausgelagerten Module
-- ===== Lazy load: Config / I18n =====
local CFG, I18N
local CFG, I18N
local function loadConfig()
local function loadConfig()
   if CFG then return CFG end
   if CFG then return CFG end
   for _,t in ipairs{ "Modul:HeroConfig", "Module:HeroConfig" } do
   for _,t in ipairs{ "Modul:HeroConfig", "Module:HeroConfig" } do
     local ok, mod = pcall(require, t); if ok and type(mod)=="table" then CFG=mod; return CFG end
     local ok, mod = pcall(require, t)
    if ok and type(mod)=="table" then CFG=mod; return CFG end
   end
   end
   error("HeroConfig not found")
   error("HeroConfig not found")
Zeile 26: Zeile 27:
   if I18N then return I18N end
   if I18N then return I18N end
   for _,t in ipairs{ "Modul:HeroI18n", "Module:HeroI18n" } do
   for _,t in ipairs{ "Modul:HeroI18n", "Module:HeroI18n" } do
     local ok, mod = pcall(require, t); if ok and type(mod)=="table" then I18N=mod; return I18N end
     local ok, mod = pcall(require, t)
    if ok and type(mod)=="table" then I18N=mod; return I18N end
   end
   end
   I18N = { i18n = {}, aw_desc = {}, ui = {} }; return I18N
   I18N = { i18n = {}, aw_desc = {}, ui = {} }; return I18N
end
end


-- HeroData (de/en)
-- ===== HeroData (de/en) =====
local function loadHeroes()
local function loadHeroes()
   for _,t in ipairs{ "Modul:HeroData", "Module:HeroData" } do
   for _,t in ipairs{ "Modul:HeroData", "Module:HeroData" } do
Zeile 42: Zeile 44:
end
end


-- ===== MediaWiki-Bildmarkup =====
local function fileWikitext(filename, opts)
local function fileWikitext(filename, opts)
   if isempty(filename) then return "" end
   if isempty(filename) then return "" end
Zeile 48: Zeile 51:
   if opts and opts.link  then table.insert(parts, "link="..opts.link) end
   if opts and opts.link  then table.insert(parts, "link="..opts.link) end
   if opts and opts.class then table.insert(parts, "class="..opts.class) end
   if opts and opts.class then table.insert(parts, "class="..opts.class) end
   if opts and opts.lazy  then table.insert(parts, "loading=lazy") end
   -- KEIN loading=lazy: ältere MW zeigt es sonst als Text
   return string.format("[[%s]]", table.concat(parts, "|"))
   return string.format("[[%s]]", table.concat(parts, "|"))
end
end


-- Übersetzen per HeroI18n
-- ===== i18n-Mapping =====
local function tr(kind, value)
local function tr(kind, value)
   if isempty(value) then return value end
   if isempty(value) then return value end
Zeile 59: Zeile 62:
end
end


-- Tooltip-HTML (Dark-Box; Pfeil wird per CSS entfernt)
-- ===== Tooltips =====
local function addTooltip(box, title, desc)
local function addTooltip(box, title, desc)
   if (isempty(title) and isempty(desc)) then return end
   if (isempty(title) and isempty(desc)) then return end
Zeile 68: Zeile 71:
end
end


-- Kleine Bausteine
-- ===== kleine Bausteine =====
local function pill(parent, label, val, icon, showLabels, desc)
local function pill(parent, label, val, icon, showLabels, desc)
   if isempty(val) then return end
   if isempty(val) then return end
   local box = parent:tag("div"):addClass("kr-hc-pill kr-tip")
   local box = parent:tag("div"):addClass("kr-hc-pill kr-tip")
   local left = box:tag("div"):addClass("kr-hc-pill-icon")
   local left = box:tag("div"):addClass("kr-hc-pill-icon")
   if not isempty(icon) then left:wikitext(fileWikitext(icon, {size="36x36px", link="", lazy=true})) end
   if not isempty(icon) then left:wikitext(fileWikitext(icon, {size="36x36px", link=""})) end
   local text = box:tag("div"):addClass("kr-hc-pill-text")
   local text = box:tag("div"):addClass("kr-hc-pill-text")
   local lab = text:tag("div"):addClass("kr-hc-pill-label"):wikitext(label or "")
   local lab = text:tag("div"):addClass("kr-hc-pill-label"):wikitext(label or "")
Zeile 85: Zeile 88:
   local box = parent:tag("div"):addClass("kr-hc-adv kr-tip")
   local box = parent:tag("div"):addClass("kr-hc-adv kr-tip")
   local left = box:tag("div"):addClass("kr-hc-adv-icon")
   local left = box:tag("div"):addClass("kr-hc-adv-icon")
   if not isempty(icon) then left:wikitext(fileWikitext(icon, {size="36x36px", link="", lazy=true})) end
   if not isempty(icon) then left:wikitext(fileWikitext(icon, {size="36x36px", link=""})) end
   local main = box:tag("div"):addClass("kr-hc-adv-main")
   local main = box:tag("div"):addClass("kr-hc-adv-main")
   local lab = main:tag("div"):addClass("kr-hc-adv-label"):wikitext(label or "")
   local lab = main:tag("div"):addClass("kr-hc-adv-label"):wikitext(label or "")
Zeile 93: Zeile 96:
end
end


-- Unlock-Text
-- ===== Freischaltungs-Text =====
local function unlock_text_de(s)
local function unlock_text_de(s)
   if isempty(s) then return nil end
   if isempty(s) then return nil end
Zeile 103: Zeile 106:
end
end


-- Awakening-Desc: NUR englische Keys (wie in HeroData)
-- ===== Awakening-Descriptions (englische Keys) =====
local function awakeningDesc(raw_value, override)
local function awakeningDesc(raw_value, override)
   if not isempty(override) then return override end
   if not isempty(override) then return override end
Zeile 111: Zeile 114:
end
end


-- Baut den Avatar (Single-Bild oder TabberNeue mit Skins)
-- ===== Avatar (Single oder Tabber) =====
local function buildAvatar(name, linkto, defaultFile, skinsTable)
local function buildAvatar(name, linkto, defaultFile, skinsTable, defaultLabel)
   -- kein Skins-Array → einfach Standardbild
   -- kein Skins-Array → einfach Standardbild
   if type(skinsTable) ~= "table" or next(skinsTable) == nil then
   if type(skinsTable) ~= "table" or next(skinsTable) == nil then
     return fileWikitext(defaultFile, { class="kr-hc-avatar-img", link=linkto, lazy=true })
     return fileWikitext(defaultFile, { class="kr-hc-avatar-img", link=linkto })
   end
   end


   local frame = mw.getCurrentFrame()
   local frame = mw.getCurrentFrame()
   local defaultLabel = (loadI18n().ui and loadI18n().ui.default_skin) or "Standard"
   defaultLabel = defaultLabel or (loadI18n().ui and loadI18n().ui.default_skin) or "Standard"


  -- Panels aufbauen
   local panels = {}
   local panels = {}
   local function push(label, file)
   local function push(label, file)
    -- Duplikate vermeiden (falls Skin die gleiche Datei wie der Default ist)
    if file == defaultFile then return end
     table.insert(panels,
     table.insert(panels,
       tostring(label) .. "=\n" ..
       tostring(label) .. "=\n" ..
       fileWikitext(file, { class="kr-hc-avatar-img", link=linkto, lazy=true })
       fileWikitext(file, { class="kr-hc-avatar-img", link=linkto })
     )
     )
   end
   end


   -- Standard zuerst
   -- Standard zuerst
   push(defaultLabel, defaultFile)
   table.insert(panels,
    defaultLabel .. "=\n" ..
    fileWikitext(defaultFile, { class="kr-hc-avatar-img", link=linkto })
  )


   -- Skins: Liste ODER Map
   -- Skins: Liste ODER Map
   if skinsTable[1] ~= nil then
   if skinsTable[1] ~= nil then
    -- numerische Liste: {"Wild","Cheerleader"} oder { {label="…",file="…"} }
     for _, v in ipairs(skinsTable) do
     for _, v in ipairs(skinsTable) do
       if type(v) == "table" then
       if type(v) == "table" then
Zeile 147: Zeile 153:
     end
     end
   else
   else
    -- Map: { wild="Wild", cheerleader="Cheerleader" } oder { wild={label="…",file="…"} }
     local tmp = {}
     local tmp = {}
     for k, v in pairs(skinsTable) do
     for k, v in pairs(skinsTable) do
Zeile 177: Zeile 182:
   local showLabels = norm(args.show_labels) == "yes" or norm(args.show_labels) == "1"
   local showLabels = norm(args.show_labels) == "yes" or norm(args.show_labels) == "1"


   -- UI-Labels & Guardian-Flag (MUSS innerhalb von render stehen!)
   -- UI-Labels & Guardian-Flag
   local UI = (loadI18n().ui or {})
   local UI = (loadI18n().ui or {})
   local entity = norm(pick(args.entity, data.entity))
   local entity = norm(pick(args.entity, data.entity))
Zeile 206: Zeile 211:
   local awakening_desc  = awakeningDesc(awakening_bonusRaw, pick(args.awakening_desc, data.awakening_desc))
   local awakening_desc  = awakeningDesc(awakening_bonusRaw, pick(args.awakening_desc, data.awakening_desc))


   local CFGmod = loadConfig()
   local CFGmod = loadConfig()
   local icon_map = CFGmod.icon_map
   local iconmap = CFGmod.icon_map or {}


   local attackstyle_icon    = (icon_map.attackstyle    or {})[norm(attackstyleRaw)]
   local attackstyle_icon    = (iconmap.attackstyle    or {})[norm(attackstyleRaw)]
   local specialization_icon = (icon_map.specialization or {})[norm(specializationRaw)]
   local specialization_icon = (iconmap.specialization or {})[norm(specializationRaw)]
   local resource_icon      = (icon_map.resource      or {})[norm(resourceRaw)]
   local resource_icon      = (iconmap.resource      or {})[norm(resourceRaw)]
   local awakening_bonus_icon= (icon_map.awakening_bonus or {})[norm(awakening_bonusRaw)]
   local awakening_bonus_icon= (iconmap.awakening_bonus or {})[norm(awakening_bonusRaw)]


   -- Bilder/Links
   -- Bilder/Links – Default-Avatar beachten (avatar/default_skin)
   local linkto = pick(args.linkto, name)
   local linkto       = pick(args.linkto, name)
   local avatar = pick(args.avatar, (not isempty(name) and (name .. ".png")) or nil)
  local defaultSkin  = pick(args.default_skin, data.default_skin)    -- z.B. "Young"
   local avatar = pick(
    args.avatar,
    data.avatar,
    (not isempty(defaultSkin) and (name .. "_" .. defaultSkin .. ".png")) or
    ((not isempty(name)) and (name .. ".png")) or nil
  )
  local defaultTabLabel = pick(
    args.default_skin_label, data.default_skin_label,
    (loadI18n().ui and loadI18n().ui.default_skin) or "Standard"
  )


   -- Root
   -- Root
Zeile 224: Zeile 239:
   -- Avatar (links)
   -- Avatar (links)
   local avatarDiv = root:tag("div"):addClass("kr-hc-avatar")
   local avatarDiv = root:tag("div"):addClass("kr-hc-avatar")
   avatarDiv:wikitext( buildAvatar(name, linkto, avatar, data.skins) )
   avatarDiv:wikitext( buildAvatar(name, linkto, avatar, data.skins, defaultTabLabel) )


  -- Content
   local content = root:tag("div"):addClass("kr-hc-content")
   local content = root:tag("div"):addClass("kr-hc-content")
   if not isempty(name) then
   if not isempty(name) then
Zeile 241: Zeile 257:
     it:tag("span"):addClass("label"):wikitext(label)
     it:tag("span"):addClass("label"):wikitext(label)
     local v = it:tag("span"):addClass("value"):wikitext(value)
     local v = it:tag("span"):addClass("value"):wikitext(value)
     if icon then v:tag("span"):addClass("value-icon"):wikitext(fileWikitext(icon, {size="24x24px", link="", lazy=true})) end
     if icon then v:tag("span"):addClass("value-icon"):wikitext(fileWikitext(icon, {size="24x24px", link=""})) end
   end
   end
   pair(L.class, class, nil)
   pair(L.class, class, nil)
Zeile 274: Zeile 290:
   end
   end


   -- Erweckungsbonus / Wächteraura – Tooltip-TITEL = Bonusname
   -- Erweckungsbonus / Wächteraura
   if not isempty(awakening_bonus) then
   if not isempty(awakening_bonus) then
     content:tag("h3"):addClass("kr-hc-h"):wikitext(L.awakening)
     content:tag("h3"):addClass("kr-hc-h"):wikitext(L.awakening)
Zeile 282: Zeile 298:
     if awakening_bonus_icon then
     if awakening_bonus_icon then
       box:tag("div"):addClass("kr-hc-adv-icon")
       box:tag("div"):addClass("kr-hc-adv-icon")
         :wikitext(fileWikitext(awakening_bonus_icon, {size="64x64px", link="", lazy=true}))
         :wikitext(fileWikitext(awakening_bonus_icon, {size="64x64px", link=""}))
     end
     end
     local main = box:tag("div"):addClass("kr-hc-adv-main")
     local main = box:tag("div"):addClass("kr-hc-adv-main")
     local lab = main:tag("div"):addClass("kr-hc-adv-label"):wikitext(L.awakening)
     local lab = main:tag("div"):addClass("kr-hc-adv-label"):wikitext(L.awakening)
     if not showLabels then lab:addClass("is-hidden") end
     if not showLabels then lab:addClass("is-hidden") end
     main:tag("div"):addClass("kr-hc-adv-value"):wikitext(awakening_bonus)
     main:tag("div"):addClass("kr-hc-adv-value"):wikitext(awakening_bonus)

Version vom 9. Oktober 2025, 16:27 Uhr

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

-- Modul:HeroCard
local p = {}

-- ===== Helpers =====
local function isempty(v) return v == nil or v == "" end
local function pick(...) local n=select('#',...); for i=1,n do local v=select(i,...); if not isempty(v) then return v end end end
local function norm(s) if isempty(s) then return "" end return mw.ustring.lower(mw.text.trim(s)):gsub("%s+"," ") end

local function getArgs(frame)
  local args, f1, f2 = {}, frame.args or {}, (frame:getParent() and frame:getParent().args) or {}
  for k,v in pairs(f1) do if not isempty(v) then args[k]=v end end
  for k,v in pairs(f2) do if not isempty(v) then args[k]=v end end
  return args
end

-- ===== Lazy load: Config / I18n =====
local CFG, I18N
local function loadConfig()
  if CFG then return CFG end
  for _,t in ipairs{ "Modul:HeroConfig", "Module:HeroConfig" } do
    local ok, mod = pcall(require, t)
    if ok and type(mod)=="table" then CFG=mod; return CFG end
  end
  error("HeroConfig not found")
end
local function loadI18n()
  if I18N then return I18N end
  for _,t in ipairs{ "Modul:HeroI18n", "Module:HeroI18n" } do
    local ok, mod = pcall(require, t)
    if ok and type(mod)=="table" then I18N=mod; return I18N end
  end
  I18N = { i18n = {}, aw_desc = {}, ui = {} }; return I18N
end

-- ===== HeroData (de/en) =====
local function loadHeroes()
  for _,t in ipairs{ "Modul:HeroData", "Module:HeroData" } do
    local ok, mod = pcall(require, t)
    if ok and type(mod)=="table" and type(mod.heroes)=="table" then
      return mod.heroes, {ok=true, from=t}
    end
  end
  return nil, {ok=false}
end

-- ===== MediaWiki-Bildmarkup =====
local function fileWikitext(filename, opts)
  if isempty(filename) then return "" end
  local parts = { ("Datei:%s"):format(filename) }
  if opts and opts.size  then table.insert(parts, opts.size) end
  if opts and opts.link  then table.insert(parts, "link="..opts.link) end
  if opts and opts.class then table.insert(parts, "class="..opts.class) end
  -- KEIN loading=lazy: ältere MW zeigt es sonst als Text
  return string.format("[[%s]]", table.concat(parts, "|"))
end

-- ===== i18n-Mapping =====
local function tr(kind, value)
  if isempty(value) then return value end
  local map = loadI18n().i18n[kind] or {}
  return map[norm(value)] or value
end

-- ===== Tooltips =====
local function addTooltip(box, title, desc)
  if (isempty(title) and isempty(desc)) then return end
  local tip = box:tag("span"):addClass("kr-tipbox")
  if not isempty(title) then tip:tag("span"):addClass("kr-tip-title"):wikitext(title) end
  if not (isempty(title) or isempty(desc)) then tip:tag("span"):addClass("kr-tip-sep") end
  if not isempty(desc)  then tip:tag("span"):addClass("kr-tip-desc"):wikitext(desc) end
end

-- ===== kleine Bausteine =====
local function pill(parent, label, val, icon, showLabels, desc)
  if isempty(val) then return end
  local box = parent:tag("div"):addClass("kr-hc-pill kr-tip")
  local left = box:tag("div"):addClass("kr-hc-pill-icon")
  if not isempty(icon) then left:wikitext(fileWikitext(icon, {size="36x36px", link=""})) end
  local text = box:tag("div"):addClass("kr-hc-pill-text")
  local lab = text:tag("div"):addClass("kr-hc-pill-label"):wikitext(label or "")
  if not showLabels then lab:addClass("is-hidden") end
  text:tag("div"):addClass("kr-hc-pill-value"):wikitext(val)
  addTooltip(box, label, desc)
end

local function adv(parent, label, val, icon, showLabels, desc)
  if isempty(val) then return end
  local box = parent:tag("div"):addClass("kr-hc-adv kr-tip")
  local left = box:tag("div"):addClass("kr-hc-adv-icon")
  if not isempty(icon) then left:wikitext(fileWikitext(icon, {size="36x36px", link=""})) end
  local main = box:tag("div"):addClass("kr-hc-adv-main")
  local lab = main:tag("div"):addClass("kr-hc-adv-label"):wikitext(label or "")
  if not showLabels then lab:addClass("is-hidden") end
  main:tag("div"):addClass("kr-hc-adv-value"):wikitext(val)
  addTooltip(box, label, desc)
end

-- ===== Freischaltungs-Text =====
local function unlock_text_de(s)
  if isempty(s) then return nil end
  local t = norm(s)
  local n = t:match("stage%s*(%d+)"); if n then return "Freischaltung bei Abschnitt: " .. n end
  if t:match("pirate%s*ship") then return "Wird auf dem Piratenschiff freigeschaltet." end
  if s:match("[%.%!%?]$") or t:find(" ") then return s end
  return "Freischaltung: " .. s
end

-- ===== Awakening-Descriptions (englische Keys) =====
local function awakeningDesc(raw_value, override)
  if not isempty(override) then return override end
  if isempty(raw_value) then return "Bonus, der beim Erwachen freigeschaltet wird." end
  local map = loadI18n().aw_desc or {}
  return map[norm(raw_value)] or "Bonus, der beim Erwachen freigeschaltet wird."
end

-- ===== Avatar (Single oder Tabber) =====
local function buildAvatar(name, linkto, defaultFile, skinsTable, defaultLabel)
  -- kein Skins-Array → einfach Standardbild
  if type(skinsTable) ~= "table" or next(skinsTable) == nil then
    return fileWikitext(defaultFile, { class="kr-hc-avatar-img", link=linkto })
  end

  local frame = mw.getCurrentFrame()
  defaultLabel = defaultLabel or (loadI18n().ui and loadI18n().ui.default_skin) or "Standard"

  local panels = {}
  local function push(label, file)
    -- Duplikate vermeiden (falls Skin die gleiche Datei wie der Default ist)
    if file == defaultFile then return end
    table.insert(panels,
      tostring(label) .. "=\n" ..
      fileWikitext(file, { class="kr-hc-avatar-img", link=linkto })
    )
  end

  -- Standard zuerst
  table.insert(panels,
    defaultLabel .. "=\n" ..
    fileWikitext(defaultFile, { class="kr-hc-avatar-img", link=linkto })
  )

  -- Skins: Liste ODER Map
  if skinsTable[1] ~= nil then
    for _, v in ipairs(skinsTable) do
      if type(v) == "table" then
        local label = v.label or v[1]
        local file  = v.file  or (name .. "_" .. (v.filename or label) .. ".png")
        push(label, file)
      else
        local label = tostring(v)
        push(label, name .. "_" .. label .. ".png")
      end
    end
  else
    local tmp = {}
    for k, v in pairs(skinsTable) do
      if type(v) == "table" then
        local label = v.label or v[1] or tostring(k)
        local file  = v.file  or (name .. "_" .. (v.filename or label) .. ".png")
        table.insert(tmp, {label=label, file=file})
      else
        local label = tostring(v)
        table.insert(tmp, {label=label, file=(name .. "_" .. label .. ".png")})
      end
    end
    table.sort(tmp, function(a,b) return tostring(a.label) < tostring(b.label) end)
    for _,it in ipairs(tmp) do push(it.label, it.file) end
  end

  local content = table.concat(panels, "\n|-|\n")
  return frame:extensionTag('tabber', content)
end

-- ======= RENDER =======
function p.render(frame)
  local args = getArgs(frame)
  local name = pick(args.name, args[1]) or ""

  local heroes = select(1, loadHeroes())
  local data = (heroes and (heroes[name] or heroes[mw.ustring.gsub(name or "", "_", " ")])) or {}

  local showLabels = norm(args.show_labels) == "yes" or norm(args.show_labels) == "1"

  -- UI-Labels & Guardian-Flag
  local UI = (loadI18n().ui or {})
  local entity = norm(pick(args.entity, data.entity))
  local isGuardian = (entity == "guardian")
      or norm(pick(args.guardian, data.guardian)) == "1"
      or pick(args.is_guardian, data.is_guardian) == true

  local labelsHero     = (UI.labels and UI.labels.hero)     or { class="Klasse:",   awakening="Erweckungsbonus" }
  local labelsGuardian = (UI.labels and UI.labels.guardian) or { class="Typ:",      awakening="Wächteraura"     }
  local L = isGuardian and labelsGuardian or labelsHero

  -- Daten + Übersetzungen
  local class             = tr("class",          pick(args.class,          data.class))
  local attackstyleRaw    = pick(args.attackstyle,    data.attackstyle)
  local specializationRaw = pick(args.specialization, data.specialization)
  local resourceRaw       = pick(args.resource,       data.resource)
  local attackstyle       = tr("attackstyle",    attackstyleRaw)
  local specialization    = tr("specialization", specializationRaw)
  local resource          = tr("resource",       resourceRaw)
  local unlock_at         = pick(args.unlock_at, data.unlock_at)

  local awakening_bonusRaw = pick(
    args.awakening_bonus, data.awakening_bonus,   -- Held
    args.guardian_aura,   data.guardian_aura,     -- Wächter
    data.aura                                        -- optional
  )
  local awakening_bonus = tr("awakening_bonus", awakening_bonusRaw)
  local awakening_desc  = awakeningDesc(awakening_bonusRaw, pick(args.awakening_desc, data.awakening_desc))

  local CFGmod  = loadConfig()
  local iconmap = CFGmod.icon_map or {}

  local attackstyle_icon    = (iconmap.attackstyle    or {})[norm(attackstyleRaw)]
  local specialization_icon = (iconmap.specialization or {})[norm(specializationRaw)]
  local resource_icon       = (iconmap.resource       or {})[norm(resourceRaw)]
  local awakening_bonus_icon= (iconmap.awakening_bonus or {})[norm(awakening_bonusRaw)]

  -- Bilder/Links – Default-Avatar beachten (avatar/default_skin)
  local linkto       = pick(args.linkto, name)
  local defaultSkin  = pick(args.default_skin, data.default_skin)     -- z.B. "Young"
  local avatar = pick(
    args.avatar,
    data.avatar,
    (not isempty(defaultSkin) and (name .. "_" .. defaultSkin .. ".png")) or
    ((not isempty(name)) and (name .. ".png")) or nil
  )
  local defaultTabLabel = pick(
    args.default_skin_label, data.default_skin_label,
    (loadI18n().ui and loadI18n().ui.default_skin) or "Standard"
  )

  -- Root
  local root = mw.html.create("div"):addClass("kr-hero-card")
  if showLabels then root:addClass("kr-show-labels") end

  -- Avatar (links)
  local avatarDiv = root:tag("div"):addClass("kr-hc-avatar")
  avatarDiv:wikitext( buildAvatar(name, linkto, avatar, data.skins, defaultTabLabel) )

  -- Content
  local content = root:tag("div"):addClass("kr-hc-content")
  if not isempty(name) then
    local h = content:tag("h2"):addClass("kr-hc-name")
    local unlock_text = unlock_text_de(unlock_at)
    h:wikitext(string.format("[[%s|%s]]%s", linkto, name,
      unlock_text and (" <span class=\"kr-hc-unlock\">(" .. unlock_text .. ")</span>") or ""))
  end

  -- Basics 2×2
  local basics = content:tag("div"):addClass("kr-hc-basics2")
  local function pair(label, value, icon)
    if isempty(value) then return end
    local it = basics:tag("div"):addClass("kr-hc-basic")
    it:tag("span"):addClass("label"):wikitext(label)
    local v = it:tag("span"):addClass("value"):wikitext(value)
    if icon then v:tag("span"):addClass("value-icon"):wikitext(fileWikitext(icon, {size="24x24px", link=""})) end
  end
  pair(L.class, class, nil)
  pair("Spezialisierung:", specialization, specialization_icon)
  pair("Angriffsart:",     attackstyle,    attackstyle_icon)
  pair("Ressource:",       resource,       resource_icon)

  -- Hauptattribute
  content:tag("h3"):addClass("kr-hc-h"):wikitext("Hauptattribute")
  local mains = content:tag("div"):addClass("kr-hc-main-attrs")
  local heroMain = type(data.main)=="table" and data.main or {}
  for i, key in ipairs(CFGmod.main_order) do
    local meta  = CFGmod.main_meta[key]
    pill(mains, meta.label, pick(args["main"..i.."_val"], heroMain[key]),
         pick(args["main"..i.."_icon"], meta.icon), showLabels,
         pick(args["main"..i.."_desc"], meta.desc))
  end

  -- Erweiterte Attribute
  content:tag("h3"):addClass("kr-hc-h"):wikitext("Erweiterte Attribute")
  local advs = content:tag("div"):addClass("kr-hc-adv-attrs")
  local heroAdv = type(data.adv)=="table" and data.adv or {}
  for i, key in ipairs(CFGmod.adv_order) do
    local meta = CFGmod.adv_meta[key]
    adv(advs, meta.label, pick(args["adv"..i.."_val"], heroAdv[key]),
        pick(args["adv"..i.."_icon"], meta.icon), showLabels,
        pick(args["adv"..i.."_desc"], meta.desc))
  end
  for i=#CFGmod.adv_order+1,8 do
    local val=args["adv"..i.."_val"]; if isempty(val) then break end
    adv(advs, args["adv"..i.."_label"] or "", val, args["adv"..i.."_icon"], showLabels, args["adv"..i.."_desc"])
  end

  -- Erweckungsbonus / Wächteraura
  if not isempty(awakening_bonus) then
    content:tag("h3"):addClass("kr-hc-h"):wikitext(L.awakening)
    local awk = content:tag("div"):addClass("kr-hc-awakening")
    local box = awk:tag("div"):addClass("kr-hc-adv kr-tip")
    addTooltip(box, awakening_bonus, awakening_desc)
    if awakening_bonus_icon then
      box:tag("div"):addClass("kr-hc-adv-icon")
         :wikitext(fileWikitext(awakening_bonus_icon, {size="64x64px", link=""}))
    end
    local main = box:tag("div"):addClass("kr-hc-adv-main")
    local lab  = main:tag("div"):addClass("kr-hc-adv-label"):wikitext(L.awakening)
    if not showLabels then lab:addClass("is-hidden") end
    main:tag("div"):addClass("kr-hc-adv-value"):wikitext(awakening_bonus)
  end

  return tostring(root)
end

return p