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: Unterschied zwischen den Versionen

Aus Firestone Idle Rpg Wiki
Keine Bearbeitungszusammenfassung
Keine Bearbeitungszusammenfassung
Zeile 5: Zeile 5:
local H = {}
local H = {}


local function loadTable(name)
-- alle Heldentabellen zusammenziehen
    local ok, data = pcall(mw.loadData, name)
local HEROES = Util.mergeSources{
     if ok and type(data) == 'table' then return data end
     'Modul:Firestone/Data/Heroes',
     ok, data = pcall(require, name)
     'Modul:Firestone/Data/Guardians',
     if ok and type(data) == 'table' then return data end
     'Modul:Firestone/Data/WM',
    return {}
}
end


local function mergedHeroes()
-- I18n holen (wir lassen dir deine bisherige Struktur)
     local all = {}
local function getI18n()
     local sources = {
     -- falls dein Haupt-I18n ein .get() hat:
        'Modul:Firestone/Data/Heroes',
     if type(I18n) == "table" and type(I18n.get) == "function" then
        'Modul:Firestone/Data/Guardians',
         local ok, data = pcall(I18n.get)
        'Modul:Firestone/Data/WM',
         if ok and type(data) == "table" then
    }
             return data
    for _,name in ipairs(sources) do
         local t = loadTable(name)
         for k,v in pairs(t) do
             all[k] = v
         end
         end
     end
     end
     return all
    -- sonst direkt
     return I18n or {}
end
end


local HEROES = mergedHeroes()
-- 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 function autotr(key_name, value)
    local section = ui[bucket]
     if type(value) ~= "string" then return value end
     if type(section) == "table" then
    local k = Util.norm(key_name)
        if key ~= "" then
     local i18 = I18n.get()
            return section[key] or ""
    local m1 = (i18.i18n or {})[k]
        end
     local v  = m1 and m1[Util.norm(value)]
        return ""
    return v or value
     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


    -- passenden Datensatz finden (Case-insensitive usw.)
     local realKey = Util.pickKey(HEROES, name)
     local realKey = Util.pickKey(HEROES, name)
     if not realKey then
     if not realKey then
         -- nichts gefunden → wenn user nur {{Firestone|hero|X}} schreibt, gib X zurück
         -- 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()


     -- wenn nur {{Firestone|hero|Talia}} → gib den Key aus
     -- nur {{Firestone|hero|Talia}} → Key
     if Util.isEmpty(args[3]) then
     if Util.isEmpty(args[3]) then
         return realKey
         return realKey
     end
     end


     -- ab hier: Pfad wie gehabt
     -- 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


     -- FALLBACK 1:
     -- "name" nicht vorhanden? → Key
    -- {{Firestone|hero|Talia|name}} wenn im Datensatz KEIN name steht,
     if v == nil and nlast == "name" then
    -- nimm einfach den Key.
     if v == nil and Util.norm(last) == 'name' then
         return realKey
         return realKey
     end
     end


     -- auto-translate für vorhandene Werte
     -- generisches autotr für class / spec / resource ...
     v = autotr(last, v)
     v = Util.autotrFrom(i18, last, v)


    -- FALLBACK 2:
    -- falls aus irgendeinem Grund immer noch nil, gib lieber den Key als "table" aus
     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