Modul:Firestone/Hero: Unterschied zwischen den Versionen
Keine Bearbeitungszusammenfassung |
Keine Bearbeitungszusammenfassung |
||
| Zeile 25: | Zeile 25: | ||
end | end | ||
-- UI-Zweig: {{Firestone|hero | -- UI-Zweig: {{Firestone|hero|ui|basics|class}} | ||
function H.ui(frame, args) | function H.ui(frame, args) | ||
local i18 = getI18n() | local i18 = getI18n() | ||
-- so wie du dein I18n gepostet hast: | |||
local | -- 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 | end | ||
local | -- über deinen Util-Helfer tief holen | ||
if type( | 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 | end | ||
return '' | |||
end | end | ||
Version vom 7. November 2025, 09:58 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 (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
-- 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
-- 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