Module:Focus: Difference between revisions

(创建页面,内容为“------------------------------------------------------------------------------- -- -- Module:Focus -- -- This module implements Template:Focus. ------------------------------------------------------------------------------- local p = {}; local tagSet = { generic = {dlc = "generic"}, warlord = {dlc = "generic"}, hoa = {dlc = "generic"}, ast = {dlc = "tfv"}, can = {dlc = "tfv"}, saf = {dlc = "tfv"}, raj = {dlc = "tfv"}, nzl =…”)
 
No edit summary
 
Line 1: Line 1:
-------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- 
-- 
--                 Module:Focus
--                 Module:Focus
-- 
--
-- This module implements Template:Focus.
--------------------------------------------------------------------------------
-------------------------------------------------------------------------------
local cfg = mw.loadData("Module:Focus/Config")
 
local p = {};
 
local tagSet = {
generic = {dlc = "generic"}, warlord = {dlc = "generic"}, hoa = {dlc = "generic"},
ast = {dlc = "tfv"}, can = {dlc = "tfv"}, saf = {dlc = "tfv"}, raj = {dlc = "tfv"}, nzl = {dlc = "tfv"},
cze = {dlc = "dod"}, hun = {dlc = "dod"}, yug = {dlc = "dod"}, rom = {dlc = "dod"},
ger = {dlc = "wtt"}, jap = {dlc = "wtt"}, chi = {dlc = "wtt"}, prc = {dlc = "wtt"}, man = {dlc = "wtt"},
usa = {dlc = "mtg"}, eng = {dlc = "mtg"}, hol = {dlc = "mtg"}, mex = {dlc = "mtg"},
fra = {dlc = "lar"}, spr = {dlc = "lar"}, spa = {dlc = "lar"}, por = {dlc = "lar"}, vic = {dlc = "lar"}, fre = {dlc = "lar"},
tur = {dlc = "bftb"}, gre = {dlc = "bftb"}, bul = {dlc = "bftb"},
sov = {dlc = "nsb"}, pol = {dlc = "nsb"}, est = {dlc = "nsb"}, lat = {dlc = "nsb"}, lit = {dlc = "nsb"}, baltic = {dlc = "nsb"},
ita = {dlc = "bba"}, swi = {dlc = "bba"}, eth = {dlc = "bba"},
den = {dlc = "aat"}, swe = {dlc = "aat"}, nor = {dlc = "aat"}, fin = {dlc = "aat"}, ice = {dlc = "aat"}, nordic = {dlc = "aat"},
arg = {dlc = "toa"}, bra = {dlc = "toa"}, chl = {dlc = "toa"}, par = {dlc = "toa"}, urg = {dlc = "toa"}, smb = {dlc = "toa"}, guay = {dlc = "toa"},
};


local chinese_warlords = {
gxc = {}, shx = {}, sik = {}, xsm = {}, yun = {},
};


local hoa_nations = {
local p = {}
afa = {}, beg = {}, gba = {}, har = {}, oro = {}, gem = {}, sid = {}, tig = {},
};


function p.main(frame)
function p.main(frame)
local args = frame.args
   local args = frame.args
local aTag = args['tag']
   local aTag = args['tag']


--Check tag
   --Check tag
if chinese_warlords[aTag] then --Set chinese warlords tag to "warlord"
   if cfg.tags.chinese_warlords[aTag] then --Set chinese warlords tag to "warlord"
aTag = "warlord"
     aTag = "warlord"
elseif hoa_nations[aTag] then --Set horn of africa countries tag to "hoa"
   elseif cfg.tags.hoa_nations[aTag] then --Set horn of africa countries tag to "hoa"
aTag = "hoa"
     aTag = "hoa"
elseif not tagSet[aTag] then
   elseif not cfg.tags.tagset[aTag] then
return "<span style=\"color: red; font-size: 11px;\">(unrecognized TAG \"" .. aTag .. "\" for [[Template:Focus]])</span>[[Category:Pages with unrecognized focus strings]]"
     return "<span style=\"color: red; font-size: 11px;\">(Unrecognized focus TAG \"" .. aTag .. "\" for [[Template:Focus]])</span>[[Category:Pages with unrecognized focus strings]]"
end
   end


--Load only 1 module at a time (One page per dlc)
   --Load only 1 module at a time (One page per dlc)
local dlcPage = "Module:Focus/" .. tagSet[aTag].dlc
   local dlcPage = "Module:Focus/" .. cfg.tags.tagset[aTag]
local tag = mw.loadData(dlcPage)[aTag]
   local tag = mw.loadData(dlcPage)[aTag]


--Check id
   --Check id
if not tag[args['id']] then
   if not tag[args['id']] then
return "<span style=\"color: red; font-size: 11px;\">(unrecognized id \"" .. args['id'] .. "\" in TAG \"" .. aTag .. "\" for [[Template:Focus]])</span>[[Category:Pages with unrecognized focus strings]]"
     return "<span style=\"color: red; font-size: 11px;\">(Unrecognized focus id \"" .. args['id'] .. "\" in TAG \"" .. aTag .. "\" for [[Template:Focus]])</span>[[Category:Pages with unrecognized focus strings]]"
end
   end


local id = tag[args['id']]
   local id = tag[args['id']]


local page = ""
   --page
if id.continuous then
   local page = ""
page = "Continuous focus"
   if id.continuous then
elseif id.shared then
     page = cfg.pages.continuous
page = tag.shared_page
   else
elseif id.joint then
     page = cfg.pages[id.page]
page = tag.joint_page
   end
else
page = tag.page
end


--icon
   --icon
local icon = ""
   local icon = ""
if args.icon ~= nil and args.icon ~= "" then
   if args.icon ~= nil and args.icon ~= "" then
icon = args.icon
     icon = args.icon
elseif type(id.icon) == "table" then
   elseif type(id.icon) == "table" then
args.iconid = tonumber(args.iconid)
     args.iconid = tonumber(args.iconid)
if id.icon[args.iconid] then
     if id.icon[args.iconid] then
icon = id.icon[args.iconid]
       icon = id.icon[args.iconid]
else --Fallback value (default) if out of range
     else --Fallback value (default) if out of range
icon = id.icon[1]
       icon = id.icon[1]
end
     end
else
   else
icon = id.icon
     icon = id.icon
end
   end


local ic = string.format("[[File:%s.png|%s|%s|link=", icon, id.name, args['size'])
   --text
if args['link'] == "yes" then
   local text = ""
ic = ic .. page
   if args.text ~= nil and args.text ~= "" then
if id.subtree ~= nil then
     text = args.text
ic = ic .. id.subtree
   else
end
     text = id.name
end
   end
if id.replaceName == nil then
ic = ic .. "#" .. id.name
else
ic = ic .. "#" .. id.replaceName
end
if id.dup_name ~= nil then
ic = ic .. " " .. id.dup_name
end
ic = ic .. "]]"


--text
   --
local name = ""
   local linkName = ""
if args.text ~= nil and args.text ~= "" then
   if id.linkName == nil then
   name = args.text
     linkName = "#" .. id.name
else
   else
   name = id.name
     linkName = "#" .. id.linkName
end
   end
   if id.suffix ~= nil then
     linkName = linkName .. " " .. id.suffix
   end


local tx = name
   --
if args['link'] == "yes" then
   if args['nolink'] == "yes" then
tx = "[[" .. page
     icon = string.format("[[File:%s.png|%s|%s|link=%s]]", icon, text, args['size'], linkName)
if id.subtree ~= nil then
   else
tx = tx .. id.subtree
     icon = string.format("[[File:%s.png|%s|%s|link=%s]]", icon, text, args['size'], page .. linkName)
end
     text = string.format("[[%s|%s]]", page .. linkName, text)
if id.replaceName == nil then
   end
tx = tx .. "#" .. id.name
else
tx = tx .. "#" .. id.replaceName
end
if id.dup_name ~= nil then
tx = tx .. " " .. id.dup_name
end
tx = tx .. "|" .. name .. "]]"
end


return ic .. tx
   return icon .. text
end
end


return p
return p

Latest revision as of 00:21, 16 June 2025

This module depends on the following other modules:
Module:Focus/Config
Documentation Module:Focus/doc

Implements

  1. 重定向 Template:Tlx.

Submodules

The following modules are used as needed.

Submodule Tags
Module:Focus/generic GENERIC, WARLORD, HOA
Module:Focus/tfv AST, CAN, SAF, NZL
Module:Focus/dod CZE, HUN, ROM, YUG
Module:Focus/wtt GER, JAP, CHI, PRC, MAN, CHISHARED
Module:Focus/mtg ENG, USA, HOL, MEX,
Module:Focus/lar FRA, FRE, VIC, POR, SPR, SPA
Module:Focus/bftb BUL, GRE, TUR
Module:Focus/nsb SOV, POL, EST, LAT, LIT, BALTIC
Module:Focus/bba ITA, ETH, SWI
Module:Focus/aat DEN, FIN, ICE, NOR, SWE, NORDIC
Module:Focus/toa ARG, BRA, CHL, PRU, URG, GUAY, SMB
Module:Focus/gtd AUS, BEL, COG, BELCOG, HUN2, HABSBURG
Module:Focus/goe AFG, IRQ, RAJ2, PER

Adding/editing focuses

First, go to the appropriate subpage for the country you want to edit.

Add

To keep the order, find focus above/below the one you want to add.
To add a focus, start with the country tag followed by the focus ID in square brackets, example: sov['sov_infrastructure_effort_nsb'] = { }
Then, based on the parameters listed below, add an entry.

Edit

To edit the focus, find it and simply edit it.

Parameters

Parameter Required Type Example Note
name Yes String "Army Effort" Focus name from localization file.
icon Yes String
Table
"goal_generic_allies_build_infantry" Focus icon.
Focus icons. [1] is default.
suffix No String "C" Should be used only if 2 or more focuses have the same name.
Remember to update Template:Focus/doc.
linkName No String "Develop Capital" In case when anchor name in nf page is different than localization name.
page No String "ger" Set focus page.
See: Module:Focus/Config (cfg.pages)
continuous No Bool true If focus is from continuous focus file.

Example entry: fra['fra_autoroutes'] = { name = "Autoroutes", icon = "goal_generic_construct_infrastructure" }

The national focus page should be placed at the end of the module, right after the loops.


--------------------------------------------------------------------------------
-- 
--                                 Module:Focus
--
--------------------------------------------------------------------------------
local cfg = mw.loadData("Module:Focus/Config")


local p = {}

function p.main(frame)
    local args = frame.args
    local aTag = args['tag']

    --Check tag
    if cfg.tags.chinese_warlords[aTag] then --Set chinese warlords tag to "warlord"
        aTag = "warlord"
    elseif cfg.tags.hoa_nations[aTag] then --Set horn of africa countries tag to "hoa"
        aTag = "hoa"
    elseif not cfg.tags.tagset[aTag] then
        return "<span style=\"color: red; font-size: 11px;\">(Unrecognized focus TAG \"" .. aTag .. "\" for [[Template:Focus]])</span>[[Category:Pages with unrecognized focus strings]]"
    end

    --Load only 1 module at a time (One page per dlc)
    local dlcPage = "Module:Focus/" .. cfg.tags.tagset[aTag]
    local tag = mw.loadData(dlcPage)[aTag]

    --Check id
    if not tag[args['id']] then
        return "<span style=\"color: red; font-size: 11px;\">(Unrecognized focus id \"" .. args['id'] .. "\" in TAG \"" .. aTag .. "\" for [[Template:Focus]])</span>[[Category:Pages with unrecognized focus strings]]"
    end

    local id = tag[args['id']]

    --page
    local page = ""
    if id.continuous then
        page = cfg.pages.continuous
    else
        page = cfg.pages[id.page]
    end

    --icon
    local icon = ""
    if args.icon ~= nil and args.icon ~= "" then
        icon = args.icon
    elseif type(id.icon) == "table" then
        args.iconid = tonumber(args.iconid)
        if id.icon[args.iconid] then
            icon = id.icon[args.iconid]
        else --Fallback value (default) if out of range
            icon = id.icon[1]
        end
    else
        icon = id.icon
    end

    --text
    local text = ""
    if args.text ~= nil and args.text ~= "" then
        text = args.text
    else
        text = id.name
    end

    --
    local linkName = ""
    if id.linkName == nil then
        linkName = "#" .. id.name
    else
        linkName = "#" .. id.linkName
    end
    if id.suffix ~= nil then
        linkName = linkName .. " " .. id.suffix
    end

    --
    if args['nolink'] == "yes" then
        icon = string.format("[[File:%s.png|%s|%s|link=%s]]", icon, text, args['size'], linkName)
    else
        icon = string.format("[[File:%s.png|%s|%s|link=%s]]", icon, text, args['size'], page .. linkName)
        text = string.format("[[%s|%s]]", page .. linkName, text)
    end

    return icon .. text
end

return p