Modul:Firestone/Hero: Unterschied zwischen den Versionen
Keine Bearbeitungszusammenfassung |
Keine Bearbeitungszusammenfassung |
||
| Zeile 5: | Zeile 5: | ||
local H = {} | local H = {} | ||
-- alle Heldentabellen zusammenziehen | |||
local HEROES = Util.mergeSources{ | |||
'Modul:Firestone/Data/Heroes', | |||
'Modul:Firestone/Data/Guardians', | |||
'Modul:Firestone/Data/WM', | |||
} | |||
local function | -- 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 | |||
local | |||
end | end | ||
end | end | ||
return | -- sonst direkt | ||
return I18n or {} | |||
end | end | ||
local | -- UI-Zweig: {{Firestone|hero-ui|...}} | ||
function H.ui(frame, args) | |||
local i18 = getI18n() | |||
local ui = i18.ui or {} | |||
local bucket = Util.norm(args[2] or "") | |||
local key = Util.norm(args[3] or "") | |||
if bucket == "" then | |||
return "" | |||
end | |||
local | local section = ui[bucket] | ||
if type( | if type(section) == "table" then | ||
if key ~= "" then | |||
return section[key] or "" | |||
end | |||
return "" | |||
else | |||
return section or "" | |||
end | |||
end | end | ||
-- normaler Held: {{Firestone|hero|Talia|...}} | |||
function H.handle(frame, args) | function H.handle(frame, args) | ||
local name = args[2] | local name = args[2] | ||
| Zeile 46: | Zeile 55: | ||
end | end | ||
local realKey = Util.pickKey(HEROES, name) | local realKey = Util.pickKey(HEROES, name) | ||
if not realKey then | if not realKey then | ||
-- nichts gefunden → | -- nichts gefunden → gib den angefragten Namen zurück | ||
return name | return name | ||
end | end | ||
local hero = HEROES[realKey] | local hero = HEROES[realKey] | ||
local i18 = getI18n() | |||
-- | -- nur {{Firestone|hero|Talia}} → Key | ||
if Util.isEmpty(args[3]) then | if Util.isEmpty(args[3]) then | ||
return realKey | return realKey | ||
end | end | ||
-- | -- restliche Pfadteile einsammeln | ||
local path, i = {}, 3 | local path, i = {}, 3 | ||
while args[i] do | while args[i] do | ||
| Zeile 66: | Zeile 75: | ||
end | end | ||
local v = Util.deepGet(hero, path) | local v = Util.deepGet(hero, path) | ||
local last = path[#path] and tostring(path[#path]) or "" | 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 | |||
if v == nil and | |||
return realKey | return realKey | ||
end | end | ||
-- | -- generisches autotr für class / spec / resource ... | ||
v = | v = Util.autotrFrom(i18, last, v) | ||
if v == nil then | if v == nil then | ||
return "" | return "" | ||
Version vom 7. November 2025, 04:43 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|...}}
function H.ui(frame, args)
local i18 = getI18n()
local ui = i18.ui or {}
local bucket = Util.norm(args[2] or "")
local key = Util.norm(args[3] or "")
if bucket == "" then
return ""
end
local section = ui[bucket]
if type(section) == "table" then
if key ~= "" then
return section[key] or ""
end
return ""
else
return section or ""
end
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