WARFRAME Wiki
Advertisement
WARFRAME Wiki

Documentation for this module may be created at Module:Tooltips/icon/doc

-- n: /data page link
-- loc: name of subtable(s) in the table returned by /data
-- link: ? not sure what this does [[User:Cephalon Scientia]]
-- icon: function that formats icon image link
-- color: function that returns text color
-- TODO: Add better documentation
local modIcon = {'https://static.wikia.nocookie.net/warframe/images/7/73/Mod_TT_20px.png/revision/latest/scale-to-width-down/12?cb=20190608095452'}
local modules = {
Ability     = {n=[[Module:Ability/data]],    loc={'Ability'},          link='Link',
                icon = function(v, link)
                    return ('[[File:%s|19px|link=%s]]'):format((v or {DarkIcon='panel.png'}).DarkIcon, link)
                end,},
Mods        = {n=[[Module:Mods/data]],       loc={'Mods'},             link='Link',
                icon = function(v, link) 
                    return modIcon--'[[File:Mod_TT_20px.png|12px|link='..link..']]' 
                end,},
Warframes   = {n=[[Module:Warframes/data]],  loc={'Warframes'},
                icon = function(v, link) 
                    return ('[[File:%s|19px|link=%s]]'):format(v.Portrait, link)
                end,},
Void        = {n=[[Module:Void/data]],       loc={'RelicData'},
                icon = function(v, link) 
                    return ('[[File:VoidRelic%sIcon64.png|x19px|link=%s]]'):format(({Lith='Iron', Meso='Bronze', Neo='Silver', Axi='Gold'})[v.Tier], link)
                 end,},
Weapons     = {n=[[Module:Weapons/data]],    loc={'Weapons'},    link='Link',
                icon = function(v, link) 
                    return ('[[File:%s|x19px|link=%s]]'):format(v.Image, link)
                end,},
DamageTypes = {n=[[Module:DamageTypes/data]],loc={'Types'}, loc2={'Health'}, link='link',
                icon = function(v, link, k) 
                    return v.icon and ('[[File:%s|18px|link=%s]]'):format(v.icon or 'spacer.png', link)
                end,
                color = function(v, k) 
                    return (function(s)return s~='' and s or nil end)(v.color)
                end,},
Arcane      = {n=[[Module:Arcane/data]],     loc={'Arcanes'},
                icon = function(v, link) 
                    return ('[[File:%s|23px|link=%s]]'):format(v.Icon, link)
                end,},
}--could use a loop for ['n'], but this properly autodetects the links

local function find(t,l)
    local tt = t
    for i, v in ipairs(l) do
        t=t[v]
    end
    return t or error('failed to find '..require'Module:Shared'.upk({l,'\nin\n',tt},2):gsub('\n','\n\n'))
end

local t = {}
for name, module in pairs(modules) do
    --only loops through the modules
    t[name] = function(index) -- t.Mods(), etc
        -- is only called later
        -- mw.log(index..name)
        --if _G.tooltipIcons and _G.tooltipIcons[index] then mw.log 'Global bullshit works' return _G.tooltipIcons[index] end
        --if _G.tooltipIcons then mw.log 'Global bullshit works' end
        --_G.tooltipIcons = _G.tooltipIcons or {} -- global storage trick, does it work between #invokes -- no

        for _, locale in ipairs{module.loc,module.loc2,module.loc3,} do -- for each set of location instructions
            local data = find(mw.loadData(module.n), locale) -- find data in that location
            local v = data[index]
            -- [=[ fallback
            if not v then
                for k,vv in pairs(data) do
                    if index == k:gsub(' ?%(.+%)','') then
                        v = vv break
                    end
                end
            end
            --]=]
            if v then
                -- mw.log('found')
                --_G.tooltipIcons[index] = {
                return {
                    name,-- Source module
                    k~=index and k or nil,-- Key in data table
                    v[module.link],-- Link destination (page location)
                    icon= module.icon and module.icon(v, v[module.link] or index, k),-- Icon in wikitext
                    color= module.color and module.color(v, k),-- Hex color
                }
                --return _G.tooltipIcons[index]
            end
        end
    end
end
t.Modules = modules
t._find = find -- might as well
function t.table(name)
    local icon = t
    local modules = icon.Modules
    local find = icon._find

    local index = {}

    --for name, module in pairs(modules) do 
    --local name = 'Mods'
    local module = modules[name]
    for i, locale in ipairs{module.loc,module.loc2,module.loc3,} do
    for k,v in pairs(find(mw.loadData(module.n), locale)) do -- find and iterate through names of objects
        local kk = k:gsub(' ?%(.+%)','')-- qwe (asd)
        index[kk]=index[kk]or{}
        table.insert(index[kk], icon[name](k))
        if not index[k] and kk~=k then index[k] = index[kk] end
    end
    end
    --end

    return index
end
return t