Zum Inhalt springen

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
 
(26 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt)
Zeile 5: Zeile 5:
local H = {}
local H = {}


local function loadTable(name)
-- nur die eigentlichen Helden laden
    local ok, data = pcall(mw.loadData, name)
local HEROES = Util.loadTable('Modul:Firestone/Data/Heroes')
     if ok and type(data) == 'table' then return data end
 
    ok, data = pcall(require, name)
-- I18n holen
    if ok and type(data) == 'table' then return data end
local function getI18n()
     return {}
     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
     return I18n or {}
end
end


local function mergedHeroes()
-- Skins in eine saubere Liste bringen
     local all = {}
local function normalizeSkins(skins)
     local sources = {
     local list = {}
         'Modul:Firestone/Data/Heroes',
     if type(skins) ~= "table" then
        'Modul:Firestone/Data/Guardians',
         return list
        'Modul:Firestone/Data/WM',
    end
     }
 
     for _,name in ipairs(sources) do
    -- numerische zuerst einsammeln (loadData macht da gern komische Dinge)
         local t = loadTable(name)
     local numeric = {}
        for k,v in pairs(t) do
     for k, v in pairs(skins) do
             all[k] = v
         if type(k) == "number" then
            numeric[k] = v
        else
             list[#list+1] = v
         end
         end
     end
     end
     return all
 
    local idx = {}
    for k in pairs(numeric) do
        idx[#idx+1] = k
    end
    table.sort(idx)
    for _, k in ipairs(idx) do
        list[#list+1] = numeric[k]
    end
 
     return list
end
end


local HEROES = mergedHeroes()
-- ========================================================================
-- Avatar/Skins: {{Firestone|hero|Talia|avatar}}
-- ========================================================================
local function buildAvatarMarkup(hero, realKey, i18)
    local frame      = mw.getCurrentFrame()
    local skinLabels = ((i18.ui or {}).skins) or {}
    local skins      = normalizeSkins(hero.skins)


local function autotr(key_name, value)
    -- keine Skins → nur Standardbild
     if type(value) ~= "string" then return value end
    if #skins == 0 then
     local k = Util.norm(key_name)
        return string.format(
    local i18 = I18n.get()
            "[[Datei:%s.png|210px|class=avatar-img|link=%s]]",
    local m1 = (i18.i18n or {})[k]
            realKey,
     local = m1 and m1[Util.norm(value)]
            realKey
     return v or value
        )
     end
 
    -- Tabber bauen
    local panels = {}
 
    -- Standard (Name des Helden)
    local heroDisplayName = hero.name or realKey
    panels[#panels+1] =
        heroDisplayName .. "=\n" ..
        string.format("[[Datei:%s.png|210px|class=avatar-img|link=%s]]", realKey, realKey)
 
    -- weitere Skins
     for _, id in ipairs(skins) do
        local idNorm  = Util.norm(id)
        local label    = skinLabels[idNorm] or id
        local filename = string.format("%s_%s.png", realKey, id)
 
        panels[#panels+1] =
            label .. "=\n" ..
            string.format("[[Datei:%s|210px|class=avatar-img|link=%s]]", filename, realKey)
    end
 
     local content = table.concat(panels, "\n|-|\n")
     return frame:extensionTag('tabber', content)
end
end


-- UI-Zweig: {{Firestone|hero|ui|basics|class}}
function H.ui(frame, args)
    local i18    = getI18n()
    local uiRoot = i18.ui or {}
    local path = {}
    for i = 3, #args do
        path[#path+1] = args[i]
    end
    local val = Util.deepGet(uiRoot, path)
    if type(val) == 'string' then
        return mw.text.trim(val)
    end
    return ''
end
-- normaler Held: {{Firestone|hero|Talia|...}}
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
 
    -- nur in den Heroes nachgucken
    local realKey = Util.pickKey(HEROES, name)
    if not realKey then
        return name
    end
 
    local hero = HEROES[realKey]
    local i18  = getI18n()
 
    -- nur {{Firestone|hero|Talia}} → Key
    if Util.isEmpty(args[3]) then
        return realKey
    end


     local real = Util.pickKey(HEROES, name)
     -- Avatar?
     if not real then return "" end
    if Util.norm(args[3]) == "avatar" then
    local hero = HEROES[real]
        return buildAvatarMarkup(hero, realKey, i18)
     end


    -- restlicher Pfad
     local path, i = {}, 3
     local path, i = {}, 3
     while args[i] do
     while args[i] do
         table.insert(path, args[i])
         path[#path+1] = args[i]
         i = i + 1
         i = i + 1
     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 ""
     v = autotr(last, v)
local nlast = Util.norm(last)
if nlast == "awakening_id" then
    -- gib nur den übersetzten Titel zurück
    return Util.heroAwakeningTitle(v, i18)
elseif nlast == "awakening_desc" then
    -- gib die übersetzte Beschreibung zurück
    return Util.heroAwakeningDesc(hero.awakening_id, i18)
elseif nlast == "awakening_icon" then
    return Util.heroAwakeningIcon(hero.awakening_id, i18)
end
 
    if v == nil and nlast == "name" then
        return realKey
    end
 
     v = Util.autotrFrom(i18, last, v)
    if v == nil then
        return ""
    end


     return tostring(v or "")
     return tostring(v)
end
end


return H
return H

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

-- nur die eigentlichen Helden laden
local HEROES = Util.loadTable('Modul:Firestone/Data/Heroes')

-- I18n holen
local function getI18n()
    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
    return I18n or {}
end

-- Skins in eine saubere Liste bringen
local function normalizeSkins(skins)
    local list = {}
    if type(skins) ~= "table" then
        return list
    end

    -- numerische zuerst einsammeln (loadData macht da gern komische Dinge)
    local numeric = {}
    for k, v in pairs(skins) do
        if type(k) == "number" then
            numeric[k] = v
        else
            list[#list+1] = v
        end
    end

    local idx = {}
    for k in pairs(numeric) do
        idx[#idx+1] = k
    end
    table.sort(idx)
    for _, k in ipairs(idx) do
        list[#list+1] = numeric[k]
    end

    return list
end

-- ========================================================================
-- Avatar/Skins: {{Firestone|hero|Talia|avatar}}
-- ========================================================================
local function buildAvatarMarkup(hero, realKey, i18)
    local frame      = mw.getCurrentFrame()
    local skinLabels = ((i18.ui or {}).skins) or {}
    local skins      = normalizeSkins(hero.skins)

    -- keine Skins → nur Standardbild
    if #skins == 0 then
        return string.format(
            "[[Datei:%s.png|210px|class=avatar-img|link=%s]]",
            realKey,
            realKey
        )
    end

    -- Tabber bauen
    local panels = {}

    -- Standard (Name des Helden)
    local heroDisplayName = hero.name or realKey
    panels[#panels+1] =
        heroDisplayName .. "=\n" ..
        string.format("[[Datei:%s.png|210px|class=avatar-img|link=%s]]", realKey, realKey)

    -- weitere Skins
    for _, id in ipairs(skins) do
        local idNorm   = Util.norm(id)
        local label    = skinLabels[idNorm] or id
        local filename = string.format("%s_%s.png", realKey, id)

        panels[#panels+1] =
            label .. "=\n" ..
            string.format("[[Datei:%s|210px|class=avatar-img|link=%s]]", filename, realKey)
    end

    local content = table.concat(panels, "\n|-|\n")
    return frame:extensionTag('tabber', content)
end

-- UI-Zweig: {{Firestone|hero|ui|basics|class}}
function H.ui(frame, args)
    local i18    = getI18n()
    local uiRoot = i18.ui or {}

    local path = {}
    for i = 3, #args do
        path[#path+1] = args[i]
    end

    local val = Util.deepGet(uiRoot, path)
    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

    -- nur in den Heroes nachgucken
    local realKey = Util.pickKey(HEROES, name)
    if not realKey then
        return name
    end

    local hero = HEROES[realKey]
    local i18  = getI18n()

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

    -- Avatar?
    if Util.norm(args[3]) == "avatar" then
        return buildAvatarMarkup(hero, realKey, i18)
    end

    -- restlicher Pfad
    local path, i = {}, 3
    while args[i] do
        path[#path+1] = 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)
	
	if nlast == "awakening_id" then
	    -- gib nur den übersetzten Titel zurück
	    return Util.heroAwakeningTitle(v, i18)
	elseif nlast == "awakening_desc" then
	    -- gib die übersetzte Beschreibung zurück
	    return Util.heroAwakeningDesc(hero.awakening_id, i18)
	elseif nlast == "awakening_icon" then
	    return Util.heroAwakeningIcon(hero.awakening_id, i18)
	end	

    if v == nil and nlast == "name" then
        return realKey
    end

    v = Util.autotrFrom(i18, last, v)
    if v == nil then
        return ""
    end

    return tostring(v)
end

return H