Module:Technology

天津风不是天津的风讨论 | 贡献2025年7月9日 (三) 07:40的版本 (merge from official wiki)
(差异) ←上一版本 | 最后版本 (差异) | 下一版本→ (差异)

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

Implements {{Technology}}.

------------------------------------------------------------------------------
-- 
--                                 Module:Technology
-- 
-- This module implements Template:Technology.
------------------------------------------------------------------------------

local iconify = require('Module:Iconify').iconify
local getArgs = require('Module:Arguments').getArgs
local ttUtils = require('Module:Tooltip')
local p = {};
p = require('Module:Tooltip/Types')

function p.main(frame)
    local args = getArgs(frame)
    if args.table then
        return '<span style="color:red;">WIP</span>' --p.table(args)
    else
        return p.tech(args)
    end
end
--[=[
function p.tech(args)
    local index = tonumber(args.index)
    local techID = mw.ustring.lower(args[1])
    local techData = mw.loadData('Module:Technology/List')[techID] --load pm data

    -- catch unknown/error
    if not techData then
        return '<span style="color:red; font-size:11px;">(unrecognized production method "' .. args[1] .. '" for [[Module:Technology]])</span>[[Category:Pages with unrecognized technologies]]'
    end

    -- set tooltip display as icon and text, short-circuit tooltip if out of index 
    local displayText = iconify{icon=techData.loc, group="Invention", link=techData.category.."#"..techData.loc}
    if type(index) ~= 'number' or index > 3 then -- any non number or index over 3 returns basic display
        return ttUtils.tooltip(displayText)
    end

    -- set tooltip style, imitates in-game tooltips
    local tooltipStyle = 'color: #c2bdb8; background: linear-gradient(to bottom,#47373a,#211b1c); border: solid #b19656; border-radius: 10px; width: max-content; padding: 5px;'

    -- set up header subtitle, with building for pm, tooltip building if pm called directly
    local cost = { "7,000", "10,000", "12,500", 15,000", "17,500" }
    cost = mw.ustring.format([[%s <span title="Innovation">Inno.</span> '''%s''']], "[[File:Innovation.png|16px|link=Innovation]]", cost[techData.era])
    local subtitle = mw.ustring.format("<span>%s | %s</span>", cost, techData.era)

    local header = ttUtils.headerStyle('2LR', {
        leftText=iconify{icon=techData.loc, group="Invention", width="48px", text=0, link=techData.category.."#"..techData.loc},
        rightText=techData.category,
        mainText=techData.loc,
        subText=subtitle
    })

    -- start body with reqs and blockers
    local body = '<hr>'
    if techData.reqs then
        body = body .. 'Requires:<div style="margin-left:1em;">' .. ttUtils.ttList(techData.reqs, {index=(index+1), from="tech"})..'</div><hr>'
    end

    local effects = ''

    if techData.modifiers then
        effects = effects .. '<div>Modifiers:<div style="margin-left:1em;">' .. ttUtils.effectList(techData.modifiers) .. '</div></div>'
    end
    if techData.unlocks then
        effects = effects .. '<div>Modifiers:<div style="margin-left:1em;">' .. ttUtils.effectList(techData.unlocks) .. '</div></div>'
    end

    if effects ~= '' then
        body = body .. tostring(mw.html.create('div'):cssText("display:grid; grid-template-columns: auto auto; gap:5px 10px;"):wikitext(effects))
    else
        body = body .. "No effects"
    end
    return ttUtils.tooltip(displayText, header, body, {style=tooltipStyle, index=index})
end
--]=]

-- Temp copied from building module, not usable yet
function p.table(args)
    local techID = mw.ustring.lower(args[1])
    local techData = mw.loadData('Module:Technology/List')[techID] --load pm data

    -- catch unknown/error
    if not techData then
        return '<span style="color:red; font-size:11px;">(unrecognized production method "' .. args[1] .. '" for [[Module:Technology]])</span>[[Category:Pages with unrecognized technologies]]'
    end
    local s = iconify{icon = args[1], group = "invention"}

    local reqs = ''
    if techData.reqs then
        reqs = '\n' .. ttUtils.ttList(techData.reqs, {index=1, listStyle="newline"})
    end
    s = mw.ustring.format("%s || %s || %s || %s || %s || %s", s, techData.era, reqs, techData.modifiers, techData.unlocks)

    return s
end

return p