Module:Decree

天津风不是天津的风讨论 | 贡献2025年7月9日 (三) 08:06的版本 (merge from official wiki)
(差异) ←上一版本 | 最后版本 (差异) | 下一版本→ (差异)
This module depends on the following other modules:
Module:Arguments
Module:Decree/List
Module:Tooltip
Module:Tooltip/Types

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

Implements {{Decree}}.

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

--local iconify = require('Module:Iconify').iconify
local getArgs = require('Module:Arguments').getArgs
local ttUtils = require('Module:Tooltip')
local p = {};
local gameTT = 'color: #c2bdb8; font-style: normal; background: linear-gradient(to bottom,#47373a,#211b1c); border: solid #b19656; border-radius: 10px; width: max-content; padding: 5px;'
local uString = mw.ustring

function p.main(frame)
    local args = getArgs(frame)
    if args.table then
        return p.table(args)
    else
        return p.decree(args)
    end
end

function p.decree(args)
    local index = tonumber(args.index)
    local decreeID = uString.lower(args[1])
    local decreeData = mw.loadData('Module:Decree/List')[decreeID] --load decree data

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

    -- set tooltip display as icon and text, short-circuit tooltip if out of index 
    local displayText = uString.format("[[File:Decree %s.png|%s|link=Decrees#%s|%s]] %s", decreeID, args.width or "24px", args[1], args[1], args[1])
-- iconify{icon=args[1], group="Decree", link="Decrees#"..args[1], extra=args[1]}
    if (args.from == "decree") or (index == 0) then index = index + 1 end
    if args.fromfrom == "decree" then index = 4 end
    if type(index) ~= 'number' or index > 3 then -- any non number or index over 3 returns basic display
        return args.from and ttUtils.tooltip(displayText,'','',{tagType='span'}) or displayText
    end

    local subtitle = '<div style="line-height: 1.2em; font-style:italic; font-size:smaller; max-width:360px">'..decreeData.desc..'</div>'
    local cost = 'Cost: <span style="font-weight:bold;">' .. (decreeData.cost or 100) .. '</span>'
    local header = ttUtils.headerStyle('2LR', {
        leftText=uString.format("[[File:Decree %s.png|48px|link=Decrees#%s|%s]]", decreeID, args[1], args[1], args[1]),
--iconify{icon=args[1], group="Decree", width="48px", text=0, link="Decrees#"..args[1], extra=args[1]},
        mainText=args[1],
        rightText=cost,
        subText=subtitle,
        extra="align-items: center;"
    })

    -- start body with reqs
    local body = '<hr>'
    if decreeData.reqs then
        body = body .. '<div>Requires:' .. ttUtils.ttList(decreeData.reqs, {index=(index + 1), from="decree", fromfrom=args.from})..'</div><hr>'
    end

    local effects = ''

    if decreeData.modifiers and decreeData.modifiers[1] then
        body = body .. '<div>Modifiers:<div style="margin-left:1em;">' .. ttUtils.effectList(decreeData.modifiers) .. '</div></div>'
    end

    return ttUtils.tooltip(displayText, header, body, {style=gameTT, index=index})
end

function p.table(args)
    local index = tonumber(args.index) or 3
    local decreeID = uString.lower(args[1])
    local decreeData = mw.loadData('Module:Decree/List')[decreeID] --load decree data

    -- catch unknown/error
    if not decreeData then
        return '<span style="color:red; font-size:11px;">(unrecognized decree "' .. args[1] .. '" for [[Module:Decree]])</span>[[Category:Pages with unrecognized decrees]]'
    end
    local s = uString.format('<div style="display:flex; align-items:center;>[[File:Decree %s.png|64px|link=|%s]]', decreeID, args[1], args[1])
-- .. iconify{icon = args[1], group = "decree", width = "64px", text = "0", link = '', extra = args[1] }
    s = uString.format('%s<div style="margin-left:5px;"><div style="font-weight: bold; font-size:larger;">%s</div><div style="line-height: 1.2em; font-style: italic; font-size:smaller;">%s</div></div></div>', s, args[1], decreeData.desc)

    local tech = ''
    local reqs = {}
    for k, v in pairs(decreeData.reqs) do
        reqs[k] = v
    end
    if reqs and reqs.tech then
        tech = ttUtils.ttList({ tech = reqs.tech }, {index=(index + 1), from="decree", listStyle="newline"})
        reqs.tech = nil
    end
    local reqStr = reqs and ttUtils.ttList(reqs, {index=index+1, listStyle="newline", from="decree"}) or ''
    local mods = decreeData.modifiers and ttUtils.effectList(decreeData.modifiers, {listStyle="newline",color={css=1}}) or ''

    s = uString.format("%s\n|%s\n|%s\n|%s", s, tech, reqStr, mods)

    return s
end

--[=[
--------------------
-- See [[Module:Decree/List]] for current updated list of decrees
--------------------
decreeList = {};
decreeList['emergency relief'] = {
 cost = 50,
 reqs = {
  tech = { 'centralization' },
  state = {
   'Decree is active and state has 20% or more starving pops',
   'State has a [[File:State status famine.png|24px|link=Famine]] famine',
   'State has more than 20% [[File:State status devastation.png|24px|link=Devastation]] devastation',
   'State has a <span class="tooltip" title="Disease Outbreak, Drought, Extreme Winds, Flood, Wildfire">negative</span> [[harvest condition]]'
  }
 },
 desc = "Promote charitable support and care for the state's most unfortunate",
 modifiers = {
  { 'inherit', '−50%', 'Tax collection' },
  { 'green', '+10%', { icon='Infrastructure', group='State status' } },
  { 'green', '+5%', 'Market access price impact' },
  { 'green', '+5%', 'Food security' },
 }
}
decreeList['encourage agricultural industry'] = {
 reqs = {
  tech = { 'enclosure' },
  state = { [[State does <span style="color:red; font-weight:bold;">not</span> have another ''Encourage __ Industry'' decree]] }
 },
 desc = "Increase Agricultural and Plantation sector throughput",
 modifiers = {
  { 'green', '+20%', 'Agriculture throughput' },
  { 'green', '+20%', 'Ranches throughput' },
  { 'green', '+20%', 'Plantations throughput' },
  { "<hr>''Note:'' Does not affect subsistence buildings" },
 }
}
decreeList['encourage manufacturing industry'] = {
 reqs = {
  tech = { 'manufacturies' },
  state = { [[State does <span style="color:red; font-weight:bold;">not</span> have another ''Encourage __ Industry'' decree]] }
 },
 desc = "Increase Manufacturing and Service sector throughput",
 modifiers = {
  { 'green', '+20%', 'Manufacturing Industries throughput' },
  { 'green', '+20%', 'Service Industries throughput' },
 }
}
decreeList['encourage resource industry'] = {
 reqs = {
  tech = { 'shaft mining' },
  state = { [[State does <span style="color:red; font-weight:bold;">not</span> have another ''Encourage __ Industry'' decree]] }
 },
 desc = "Increase Resource sector throughput",
 modifiers = {
  { 'green', '+20%', 'Mines throughput' },
  { 'green', '+20%', 'Logging Industry throughput' },
  { 'green', '+20%', 'Fishing Industry throughput' },
  { 'green', '+20%', 'Whaling Industry throughput' },
  { 'green', '+20%', 'Oil Extractors throughput' },
  { 'green', '+20%', 'Rubber Plantations throughput' },
 }
}
decreeList['enlistment efforts'] = {
 reqs = { tech = { 'mandatory service' } },
 desc = "Incentivizing recruitment and training of local troops through financial incentives and preferential treatment",
 modifiers = {
  { 'green', '+5%', 'Conscription rate' },
  { 'green', '+25%', 'Training rate' }
 }
}
decreeList['greener grass campaign'] = {
 reqs = {
  tech = { 'romanticism' },
  state = { 'State is <span style="color:red; font-weight:bold;">not</span> isolated' }
 },
 desc = "Promote the state as a desirable place to migrate to",
 modifiers = {
  { 'green', '+20', 'Migration attraction' },
  { 'green', '+25%', 'Migration attraction' }
 }
}
decreeList['promote national values'] = {
 reqs = {
  tech = { 'centralization' },
  state = { 'State has any assimilating or converting pops' }
 },
 desc = "Increase cultural assimilation and religious conversion rates",
 modifiers = {
  { 'green', '+100%', { icon='Assimilation' } },
  { 'green', '+100%', { icon='Conversion' } }
 }
}
decreeList['promote social mobility'] = {
 desc = "Encourage the population to strive for higher job qualifications",
 reqs = {
  state = {
   "State has less than 30% [[File:Religion hindu.png|24px|link=Hindu]] Hindu pops",
   'Owner does <span style="color:red; font-weight:bold;">not</span> have ' .. iconify{icon='Caste System Enforced', group='Law'} .. ' or ' .. iconify{icon='Caste System Codified', group='Law'}
  }
 },
 modifiers = {
  { 'green', '+25%', 'Education access' },
  { 'green', '+25%', 'Qualifications' }
 }
}
decreeList['road maintenance'] = {
 reqs = { tech = { 'centralization' } },
 desc = "Expand and maintain road networks",
 modifiers = {
  { 'green', '+1', 'Infrastructure per 100K population', '[[File:State status infrastructure.png|24px|link=Infrastructure]]' },
  { 'green', '+20', 'Maximum infrastructure per 100K population', '[[File:State status infrastructure.png|24px|link=Infrastructure]]' },
  { 'green', '+10%', 'State construction efficiency', '[[File:State status construction.png|24px|link=Construction]]' }
 }
}
decreeList['violent suppression'] = {
 reqs = {
  tech = { 'standing army' },
  state = { iconify{icon='Turmoil', group='State status'} .. ' in state is at least <span style="color:red; font-weight:bold;">25%</span>' },
 -- [[File:State status turmoil.png|24px|link=Turmoil]] Turmoil
  owner = { 'Owner does <span style="color:red; font-weight:bold;">not</span> have the law ' .. iconify{icon='Guaranteed Liberties', group='Law'} }
 -- [[File:Law guaranteed liberties.png|24px|link=Guaranteed Liberties]] Guaranteed Liberties'
 },
 desc = "Use the nation's national guard to control the angry mobs",
 modifiers = {
  { 'green', '−50%', 'State penalties from turmoil', '[[File:State status turmoil.png|24px|link=Turmoil]]' },
  { 'red', '+2%', 'Mortality per turmoil', '[[File:State status turmoil.png|24px|link=Turmoil]]' }
 }
}
--]=]
return p