Zum Inhalt springen
Das Halloween-Event (Süßes oder Saures) ist beendet. Du kannst verbleibende Kürbisse noch im Hexenhütte eintauschen.

Modul:Firestone/Hero

Aus Firestone Idle Rpg Wiki

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