Modul:Firestone/Hero: Unterschied zwischen den Versionen
Keine Bearbeitungszusammenfassung |
Keine Bearbeitungszusammenfassung |
||
| Zeile 12: | Zeile 12: | ||
} | } | ||
-- I18n holen | -- I18n holen | ||
local function getI18n() | local function getI18n() | ||
if type(I18n) == "table" and type(I18n.get) == "function" then | if type(I18n) == "table" and type(I18n.get) == "function" then | ||
local ok, data = pcall(I18n.get) | local ok, data = pcall(I18n.get) | ||
| Zeile 21: | Zeile 20: | ||
end | end | ||
end | end | ||
return I18n or {} | return I18n or {} | ||
end | |||
-- kleine Helfer: aus hero.skins eine saubere Liste bauen | |||
local function normalizeSkins(skins) | |||
local list = {} | |||
if type(skins) ~= 'table' then | |||
return list | |||
end | |||
-- 1) erst die numerischen Einträge (1,2,3,…) | |||
for i = 1, #skins do | |||
list[#list+1] = skins[i] | |||
end | |||
-- 2) falls jemand per keys gearbeitet hat (wild="Wild"), auch mitnehmen | |||
for k,v in pairs(skins) do | |||
if type(k) ~= "number" then | |||
list[#list+1] = v | |||
end | |||
end | |||
return list | |||
end | end | ||
-- ======================================================================== | -- ======================================================================== | ||
-- Avatar/Skins | -- Avatar/Skins: {{Firestone|hero|Talia|avatar}} | ||
-- default: | -- default: Talia.png | ||
-- | -- extra: Talia_Wild.png, Talia_Cheerleader.png ... | ||
-- Labels: aus i18.heroes.ui | -- Labels: aus i18.ui.skins (weil dein I18n nicht unter heroes.ui liegt) | ||
-- ======================================================================== | -- ======================================================================== | ||
local function buildAvatarMarkup(hero, realKey, i18) | local function buildAvatarMarkup(hero, realKey, i18) | ||
-- | -- du hast deine Skinnamen unter ui.skins liegen, nicht unter heroes.ui.skins | ||
local skinLabels = | local skinLabels = ((i18.ui or {}).skins) or {} | ||
local out = {} | local out = {} | ||
-- helper: | local skins = normalizeSkins(hero.skins) | ||
-- helper: ein Tab | |||
local function imgLine(label, filename) | local function imgLine(label, filename) | ||
return string.format("%s=[[Datei:%s|210px|class=ic-avatar-img|link=%s]]", | return string.format( | ||
"%s=[[Datei:%s|210px|class=ic-avatar-img|link=%s]]", | |||
label, filename, realKey | label, filename, realKey | ||
) | ) | ||
end | end | ||
-- FALL: keine Skins → einfach nur NAME.png | |||
if #skins == 0 then | |||
-- FALL | |||
if | |||
return string.format( | return string.format( | ||
"[[Datei:%s.png|210px|class=ic-avatar-img|link=%s]]", | "[[Datei:%s.png|210px|class=ic-avatar-img|link=%s]]", | ||
| Zeile 54: | Zeile 75: | ||
end | end | ||
-- | -- sonst Tabber | ||
out[#out+1] = "<tabber>" | out[#out+1] = "<tabber>" | ||
-- | -- Default-Tab soll der Heldenname sein | ||
local | local heroDisplayName = hero.name or realKey | ||
out[#out+1] = imgLine( | out[#out+1] = imgLine(heroDisplayName, realKey .. ".png") | ||
out[#out+1] = "|-|" | out[#out+1] = "|-|" | ||
-- | -- alle weiteren Skins | ||
for _,id in ipairs(skins) do | for _,id in ipairs(skins) do | ||
local idNorm = Util.norm(id) | local idNorm = Util.norm(id) | ||
local label = skinLabels[idNorm] or id | local label = skinLabels[idNorm] or id | ||
local filename = string.format("%s_%s.png", realKey, id) | local filename = string.format("%s_%s.png", realKey, id) | ||
out[#out+1] = imgLine(label, filename) | out[#out+1] = imgLine(label, filename) | ||
| Zeile 71: | Zeile 92: | ||
end | end | ||
-- letztes |-| | -- letztes "|-|" entfernen | ||
out[#out] = nil | out[#out] = nil | ||
out[#out+1] = "</tabber>" | out[#out+1] = "</tabber>" | ||
| Zeile 81: | Zeile 102: | ||
function H.ui(frame, args) | function H.ui(frame, args) | ||
local i18 = getI18n() | local i18 = getI18n() | ||
-- bei dir liegt das Zeug direkt unter "ui" | |||
local uiRoot = (i18.ui) or {} | |||
local path = {} | local path = {} | ||
for i = 3, #args do | for i = 3, #args do | ||
| Zeile 93: | Zeile 110: | ||
end | end | ||
local val = Util.deepGet(uiRoot, path) | local val = Util.deepGet(uiRoot, path) | ||
if type(val) == 'string' then | if type(val) == 'string' then | ||
return mw.text.trim(val) | return mw.text.trim(val) | ||
| Zeile 112: | Zeile 126: | ||
local realKey = Util.pickKey(HEROES, name) | local realKey = Util.pickKey(HEROES, name) | ||
if not realKey then | if not realKey then | ||
return name | return name | ||
end | end | ||
local hero = HEROES[realKey] | local hero = HEROES[realKey] | ||
local i18 = getI18n() | local i18 = getI18n() | ||
| Zeile 122: | Zeile 136: | ||
return realKey | return realKey | ||
end | end | ||
-- SPEZIAL: Avatar angefordert | -- SPEZIAL: Avatar angefordert | ||
if Util.norm(args[3]) == "avatar" then | if Util.norm(args[3]) == "avatar" then | ||
return buildAvatarMarkup(hero, realKey, i18) | return buildAvatarMarkup(hero, realKey, i18) | ||
end | end | ||
-- | -- restlicher Pfad | ||
local path, i = {}, 3 | local path, i = {}, 3 | ||
while args[i] do | while args[i] do | ||
path[#path+1] = args[i] | |||
i = i + 1 | i = i + 1 | ||
end | end | ||
| Zeile 139: | Zeile 153: | ||
local nlast = Util.norm(last) | local nlast = Util.norm(last) | ||
-- | -- unlock / awakening übersetzen | ||
if nlast == "unlock_at" then | if nlast == "unlock_at" then | ||
return Util.heroUnlockText(v, i18) | return Util.heroUnlockText(v, i18) | ||
| Zeile 146: | Zeile 160: | ||
end | end | ||
-- | -- name-Fallback | ||
if v == nil and nlast == "name" then | if v == nil and nlast == "name" then | ||
return realKey | return realKey | ||
end | end | ||
-- | -- auto-übersetzung für class / spec / resource … | ||
v = Util.autotrFrom(i18, last, v) | v = Util.autotrFrom(i18, last, v) | ||
Version vom 7. November 2025, 17:50 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 = {}
-- alle Heldentabellen zusammenziehen
local HEROES = Util.mergeSources{
'Modul:Firestone/Data/Heroes',
'Modul:Firestone/Data/Guardians',
'Modul:Firestone/Data/WM',
}
-- 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
-- kleine Helfer: aus hero.skins eine saubere Liste bauen
local function normalizeSkins(skins)
local list = {}
if type(skins) ~= 'table' then
return list
end
-- 1) erst die numerischen Einträge (1,2,3,…)
for i = 1, #skins do
list[#list+1] = skins[i]
end
-- 2) falls jemand per keys gearbeitet hat (wild="Wild"), auch mitnehmen
for k,v in pairs(skins) do
if type(k) ~= "number" then
list[#list+1] = v
end
end
return list
end
-- ========================================================================
-- Avatar/Skins: {{Firestone|hero|Talia|avatar}}
-- default: Talia.png
-- extra: Talia_Wild.png, Talia_Cheerleader.png ...
-- Labels: aus i18.ui.skins (weil dein I18n nicht unter heroes.ui liegt)
-- ========================================================================
local function buildAvatarMarkup(hero, realKey, i18)
-- du hast deine Skinnamen unter ui.skins liegen, nicht unter heroes.ui.skins
local skinLabels = ((i18.ui or {}).skins) or {}
local out = {}
local skins = normalizeSkins(hero.skins)
-- helper: ein Tab
local function imgLine(label, filename)
return string.format(
"%s=[[Datei:%s|210px|class=ic-avatar-img|link=%s]]",
label, filename, realKey
)
end
-- FALL: keine Skins → einfach nur NAME.png
if #skins == 0 then
return string.format(
"[[Datei:%s.png|210px|class=ic-avatar-img|link=%s]]",
realKey,
realKey
)
end
-- sonst Tabber
out[#out+1] = "<tabber>"
-- Default-Tab soll der Heldenname sein
local heroDisplayName = hero.name or realKey
out[#out+1] = imgLine(heroDisplayName, realKey .. ".png")
out[#out+1] = "|-|"
-- alle weiteren 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)
out[#out+1] = imgLine(label, filename)
out[#out+1] = "|-|"
end
-- letztes "|-|" entfernen
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()
-- bei dir liegt das Zeug direkt unter "ui"
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
-- 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
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
-- 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)
-- unlock / awakening übersetzen
if nlast == "unlock_at" then
return Util.heroUnlockText(v, i18)
elseif nlast == "awakening_id" then
return Util.heroAwakeningText(v, i18)
end
-- name-Fallback
if v == nil and nlast == "name" then
return realKey
end
-- auto-übersetzung für class / spec / resource …
v = Util.autotrFrom(i18, last, v)
if v == nil then
return ""
end
return tostring(v)
end
return H