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
Die Seite wurde neu angelegt: „-- Modul:Firestone/Hero local Util = require('Modul:Firestone/Util') local I18n = require('Modul:Firestone/I18n') local H = {} local function loadTable(name) local ok, data = pcall(mw.loadData, name) if ok and type(data) == 'table' then return data end ok, data = pcall(require, name) if ok and type(data) == 'table' then return data end return {} end local function mergedHeroes() local all = {} local sources = { 'Modu…“
 
Keine Bearbeitungszusammenfassung
Zeile 42: Zeile 42:
function H.handle(frame, args)
function H.handle(frame, args)
     local name = args[2]
     local name = args[2]
     if Util.isEmpty(name) then return "" end
     if Util.isEmpty(name) then
        return ""
    end


     local real = Util.pickKey(HEROES, name)
    -- passenden Datensatz finden (Case-insensitive usw.)
     if not real then return "" end
     local realKey = Util.pickKey(HEROES, name)
     local hero = HEROES[real]
     if not realKey then
        -- nichts gefunden → wenn user nur {{Firestone|hero|X}} schreibt, gib X zurück
        return name
    end
     local hero = HEROES[realKey]


    -- wenn nur {{Firestone|hero|Talia}} → gib den Key aus
    if Util.isEmpty(args[3]) then
        return realKey
    end
    -- ab hier: Pfad wie gehabt
     local path, i = {}, 3
     local path, i = {}, 3
     while args[i] do
     while args[i] do
Zeile 56: Zeile 68:
     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 ""
    -- FALLBACK 1:
    -- {{Firestone|hero|Talia|name}} → wenn im Datensatz KEIN name steht,
    -- nimm einfach den Key.
    if v == nil and Util.norm(last) == 'name' then
        return realKey
    end
    -- auto-translate für vorhandene Werte
     v = autotr(last, v)
     v = autotr(last, v)


     return tostring(v or "")
    -- FALLBACK 2:
    -- falls aus irgendeinem Grund immer noch nil, gib lieber den Key als "table" aus
    if v == nil then
        return ""
    end
 
     return tostring(v)
end
end


return H
return H

Version vom 5. November 2025, 13:13 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 = {}

local function loadTable(name)
    local ok, data = pcall(mw.loadData, name)
    if ok and type(data) == 'table' then return data end
    ok, data = pcall(require, name)
    if ok and type(data) == 'table' then return data end
    return {}
end

local function mergedHeroes()
    local all = {}
    local sources = {
        'Modul:Firestone/Data/Heroes',
        'Modul:Firestone/Data/Guardians',
        'Modul:Firestone/Data/WM',
    }
    for _,name in ipairs(sources) do
        local t = loadTable(name)
        for k,v in pairs(t) do
            all[k] = v
        end
    end
    return all
end

local HEROES = mergedHeroes()

local function autotr(key_name, value)
    if type(value) ~= "string" then return value end
    local k = Util.norm(key_name)
    local i18 = I18n.get()
    local m1 = (i18.i18n or {})[k]
    local v  = m1 and m1[Util.norm(value)]
    return v or value
end

function H.handle(frame, args)
    local name = args[2]
    if Util.isEmpty(name) then
        return ""
    end

    -- passenden Datensatz finden (Case-insensitive usw.)
    local realKey = Util.pickKey(HEROES, name)
    if not realKey then
        -- nichts gefunden → wenn user nur {{Firestone|hero|X}} schreibt, gib X zurück
        return name
    end
    local hero = HEROES[realKey]

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

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

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

    -- auto-translate für vorhandene Werte
    v = autotr(last, v)

    -- FALLBACK 2:
    -- falls aus irgendeinem Grund immer noch nil, gib lieber den Key als "table" aus
    if v == nil then
        return ""
    end

    return tostring(v)
end

return H