Module:Card

From DominionStrategy Wiki
Jump to navigation Jump to search

Usage

{{#invoke:card|cost|Donate}}
{{#invoke:card|cost|Possession}}
{{#invoke:card|cost|Wedding}}

$0008D $06P $0403D

{{#invoke:card|amount|Province}}
{{#invoke:card|amount|Province|3}}
{{#invoke:card|amount|Castles}}
{{#invoke:card|amount|Castles|3}}
{{#invoke:card|amount|Augurs}}
{{#invoke:card|amount|Smithy}}

8 12 8 12 16 10

{{#invoke:card|query|Wedding|set}}
{{#invoke:card|query|Wedding|illustrator}}

Empires Joshua Stewart

{{#invoke:card|text|Wedding}}

+1 Gain a Gold.

{{#invoke:card|text|Abundance}}

The next time you gain an Action card, +1 Buy and +.

{{#invoke:card|text|Wedding|de}}

+1 Nimm dir ein Gold.

{{#invoke:card|text|Abundance|de}}

Das nächste Mal, wenn du eine Aktionskarte nimmst: +1 Kauf und +.

{{#invoke:card|text|Capital}}

+1 Buy | When you discard this from play, take , and then you may pay off .

<span style='text-align:center; display:block; float:left;'>{{#invoke:card|text|Capital|en|vertical}}</span>{{clear|left}}

+1 Buy
When you discard this from
play, take , and then you
may pay off .
{{#invoke:card|text|Cemetery}}

2 | When you gain this, trash up to 4 cards from your hand. (Heirloom: Haunted Mirror)

<span style='text-align:center; display:block; float:left;'>{{#invoke:card|text|Cemetery|en|vertical}}</span>{{clear|left}}
2
When you gain this, trash up
to 4 cards from your hand.
(Heirloom: Haunted Mirror)
{{#invoke:card|text|Pooka}}

You may trash a Treasure other than Cursed Gold from your hand, for +4 Cards. (Heirloom: Cursed Gold)

{{#invoke:card|text|Miserable}}

-2

<span style='text-align:center; display:block; float:left;'>{{#invoke:card|text|Miserable|en|vertical}}</span>{{clear|left}}

-2

{{#invoke:card|text|Province}}

6

<span style='text-align:center; display:block; float:left;'>{{#invoke:card|text|Province|en|vertical}}</span>{{clear|left}}

6

{{#invoke:card|text|Gold}}

<span style='text-align:center; display:block; float:left;'>{{#invoke:card|text|Gold|en|vertical}}</span>{{clear|left}}

{{#invoke:card|text|Hunting Grounds|jp}}

+4 カードを引く | これを廃棄したとき、 公領1枚か屋敷3枚を 獲得する。

{{#invoke:card|text|Tea House}}

+1 +1 Card +1 Action +

{{#invoke:card|text|Tea House|jp}}

+1 +1 カードを引く +1 アクション

{{#invoke:card|text|Apprentice}}

+1 Action Trash a card from your hand. +1 Card per it costs. +2 Cards if it has in its cost.


local p = {} --p stands for package

function escape(str)
    local esc = mw.ustring.gsub(str, '([%^%$%(%)%%%.%[%]%*%+%-%?])', '%%%1')
    return esc
end

-- usage: {{#invoke:card|cost|Wedding}}
-- returns the cost of the card with a specific format (e.g. $0008D $06P $0403D)
function p.cost(frame)
    if not frame.args[1] then
        return ""
    end
    local card = mw.loadJsonData(frame.args[1] .. "/json")
    local coin = "$" .. string.format("%02d", card["cost"]["coin"])
    local debt = ""
    local potion = ""
    if card["cost"]["debt"] ~= 0 then
        debt = string.format("%02d", card["cost"]["debt"]) .. "D"
    end
    if card["cost"]["potion"] ~= 0 then
        potion = "P"
    end
    return coin .. card["cost"]["extra"] .. debt .. potion
end

-- usage: {{#invoke:card|amount|Province}} / {{#invoke:card|amount|Province|3}}
-- has an optional second variable for the number of players (default is 2)
-- returns the number of cards to play with
-- needs to be fixed: Copper, Silver, Gold, Curse, Ruins, Province
function p.amount(frame)
    if not frame.args[1] then
        return ""
    end
    local card = mw.loadJsonData(frame.args[1] .. "/json")
    local players = 2
    if frame.args[2] then
        players = frame.args[2]
    end
    local amounts = card["amount"]
    local amount = 0
    local victory = false
    for _, cardtype in ipairs(card["types"]) do
        if cardtype == "Victory" then
            victory = true
        end
    end
    if victory then
        if players == 2 then
            amount = amounts[1]
        else
            amount = amounts[2]
        end
    else
        for _, num in ipairs(amounts) do
            amount = amount + num
        end
    end
    return amount
end

-- usage: {{#invoke:card|query|Wedding|set}} / {{#invoke:card|query|Wedding|illustrator}}
-- generic card data query
function p.query(frame)
    if not frame.args[1] or not frame.args[2] then
        return ""
    end
    local card = mw.loadJsonData(frame.args[1] .. "/json")
    local result = card[frame.args[2]]
    if type(result) == "table" then
        if result["en"] then
            return result["en"]
        else
            for _, item in ipairs(result) do
                -- return first item
                return item
            end
        end
    end
    return result
end

-- usage: {{#invoke:card|text|Wedding}} / {{#invoke:card|text|Wedding|jp}} / {{#invoke:card|text|Wedding|en|vertical}}
function p.text(frame)
    local card = mw.loadJsonData(frame.args[1] .. "/json")
    local lang = "en"
    if frame.args[2] then
        lang = frame.args[2]
    end
    local result = card["text"][lang]
    local horizontal = true
    if frame.args[3] and frame.args[3] == "vertical" then
        horizontal = false
    end

    -- result = result .. "Above line.//---//Below line."
    result = mw.ustring.gsub(result, escape("//---//"), "ReplaceThisWithLine")

    -- local result = "A line////break"
    -- Note: had to put this first to get it to work
    if horizontal then
        result = mw.ustring.gsub(result, "////", " ")
    else
        result = mw.ustring.gsub(result, "////", "<br>")
    end

    -- result = result .. "Not bold or italics.%|Bold and italics.|%Not.|%%(Also bold and italics.)%%|"
    -- Note: for some reason the double escaped percent (%%%%) must be replaced before the others
    for capture in mw.ustring.gmatch(result, "%%%%([^%%]+)%%%%") do
        local heirloom = "<span style='background-color:#F0DE88'>" .. capture .. "</span>"
        result = mw.ustring.gsub(result, "%%%%" .. escape(capture) .. "%%%%", "''" .. heirloom .. "''")
    end
    for capture in mw.ustring.gmatch(result, "%%([^%%]+)%%") do
        result = mw.ustring.gsub(result, "%%" .. escape(capture) .. "%%", "''" .. capture .. "''")
    end
    for capture in mw.ustring.gmatch(result, "|([^|]+)|") do
        result = mw.ustring.gsub(result, "|" .. escape(capture) .. "|", "'''" .. capture .. "'''")
    end

    -- Must go after the bold code.
    -- result = result .. "Above line.//---//Below line."
    if horizontal then
        result = mw.ustring.gsub(result, "ReplaceThisWithLine", " | ")
    else
        result = mw.ustring.gsub(result, "ReplaceThisWithLine", "<hr/>")
    end

    -- Must go after the above line / below line code.
    -- result = result .. "Before line break//After line break. Before//After."
    if horizontal then
        result = mw.ustring.gsub(result, "//", " ")
    else
        result = mw.ustring.gsub(result, "//", "<br>")
    end

    -- result = result .. "{}.{-2}.{!2}"
    for capture in mw.ustring.gmatch(result, "{(![^}]+)}") do
        local vppx = "32px"
        local fontpx = "43px"
        local extraclass = 'class=coin-icon'
        if horizontal then
            fontpx = "1em"
            extraclass = extraclass .. ' imageintext'
        end
        local noexclamation = "<span style='font-size:" ..
        fontpx .. "'>" .. mw.ustring.gsub(capture, "!", "") .. "</span>"
        result = mw.ustring.gsub(result, "{" .. escape(capture) .. "}",
            noexclamation .. "[[File:VP.png|" .. vppx .. "|" .. extraclass .. "]]")
    end
    for capture in mw.ustring.gmatch(result, "{([^}]+)}") do
        result = mw.ustring.gsub(result, "{" .. escape(capture) .. "}", capture .. "[[File:VP.png|class=coin-icon imageintext]]")
    end
    for capture in mw.ustring.gmatch(result, "{}") do
        result = mw.ustring.gsub(result, "{}", "[[File:VP.png|32px|class=coin-icon imageintext]]")
    end

    -- result = result .. "[].[2].[!2].[P].[D].[6D]"
    for capture in mw.ustring.gmatch(result, "%[(![0-9]+)%]") do
        local coinsize = mw.ustring.gsub(capture, "!", "")
        local coinpx = "32px"
        local extraclass = 'class=coin-icon'
        if horizontal then
            extraclass = extraclass .. ' imageintext'
        end
        result = mw.ustring.gsub(result, "%[" .. escape(capture) .. "%]",
            "[[File:Coin" .. coinsize .. ".png|" .. coinpx .. "|" .. extraclass .. "]]")
    end
    for capture in mw.ustring.gmatch(result, "%[([0-9]+)%]") do
        result = mw.ustring.gsub(result, "%[" .. escape(capture) .. "%]", "[[File:Coin" .. capture .. ".png|32px|class=coin-icon imageintext]]")
    end
    for capture in mw.ustring.gmatch(result, "%[([0-9]?D+)%]") do
        local debtnum = mw.ustring.gsub(capture, "D", "")
        result = mw.ustring.gsub(result, "%[" .. escape(capture) .. "%]", "[[File:Debt" .. debtnum .. ".png|32px|class=debt-icon imageintext]]")
    end
    for capture in mw.ustring.gmatch(result, "%[(P+)%]") do
        result = mw.ustring.gsub(result, "%[" .. escape(capture) .. "%]", "[[File:Potion.png|32px|class=coin-icon imageintext]]</span>")
    end
    for capture in mw.ustring.gmatch(result, "%[%]") do
        result = mw.ustring.gsub(result, "%[%]", "[[File:Coin.png|32px|class=coin-icon imageintext]]")
    end

    -- result = result .. "<>.<>"
    for capture in mw.ustring.gmatch(result, "<>") do
        result = mw.ustring.gsub(result, "<>", "[[File:Sun.png|32px|class=coin-icon imageintext]]")
    end
    return result
end

return p