Module:Card: Difference between revisions
Jump to navigation
Jump to search
Wikiwikiwiki (talk | contribs) No edit summary |
Wikiwikiwiki (talk | contribs) No edit summary |
||
Line 9: | Line 9: | ||
-- returns the cost of the card with a specific format (e.g. $0008D $06P $0403D) | -- returns the cost of the card with a specific format (e.g. $0008D $06P $0403D) | ||
function p.cost(frame) | 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 | end | ||
Line 31: | Line 31: | ||
-- mostly just meant as an example of what kind of functions can be written | -- mostly just meant as an example of what kind of functions can be written | ||
function p.amount(frame) | 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 | end | ||
Line 64: | Line 64: | ||
-- generic card data query | -- generic card data query | ||
function p.query(frame) | 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 | end | ||
Line 93: | Line 93: | ||
horizontal = false | horizontal = false | ||
end | end | ||
-- local result = "A line////break" | -- local result = "A line////break" | ||
-- Note: had to put this first to get it to work | -- Note: had to put this first to get it to work | ||
Line 101: | Line 101: | ||
result = mw.ustring.gsub(result, "////", "<br>") | result = mw.ustring.gsub(result, "////", "<br>") | ||
end | end | ||
-- result = result .. "Not bold or italics.%|Bold and italics.|%Not.|%%(Also bold and italics.)%%|" | -- 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 | -- Note: for some reason the double escaped percent (%%%%) must be replaced before the others | ||
Line 145: | Line 145: | ||
-- result = result .. "[].[2].[!2].[P].[D].[6D]" | -- result = result .. "[].[2].[!2].[P].[D].[6D]" | ||
for capture in mw.ustring.gmatch(result, "%[(![0-9]+)%]") do | for capture in mw.ustring.gmatch(result, "%[(![0-9]+)%]") do | ||
local coinsize = mw.ustring.gsub(capture, "!", "") | |||
result = mw.ustring.gsub(result, "%[" .. escape(capture) .. "%]", "[[File:Coin" .. coinsize .. ".png|19px]]") | result = mw.ustring.gsub(result, "%[" .. escape(capture) .. "%]", "[[File:Coin" .. coinsize .. ".png|19px]]") | ||
end | end | ||
Line 152: | Line 152: | ||
end | end | ||
for capture in mw.ustring.gmatch(result, "%[([0-9]?D+)%]") do | 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|19px]]") | result = mw.ustring.gsub(result, "%[" .. escape(capture) .. "%]", "[[File:Debt" .. debtnum .. ".png|19px]]") | ||
end | end |
Revision as of 17:15, 27 September 2024
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}}
{{#invoke:card|text|Abundance}}
The next time you gain an Action card, +1 Buy and +.
{{#invoke:card|text|Wedding|de}}
{{#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}}
<span style='text-align:center; display:block; float:left;'>{{#invoke:card|text|Miserable|en|vertical}}</span>{{clear|left}}
{{#invoke:card|text|Province}}
<span style='text-align:center; display:block; float:left;'>{{#invoke:card|text|Province|en|vertical}}</span>{{clear|left}}
{{#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}}
{{#invoke:card|text|Tea House|jp}}
{{#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
-- (curses (and possibly other cards) not implemented properly)
-- mostly just meant as an example of what kind of functions can be written
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
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
-- 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
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
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, "//---//", "|")
else
result = mw.ustring.gsub(result, "//---//", "<br>-<br>")
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}"
for capture in mw.ustring.gmatch(result, "{([^}]+)}") do
result = mw.ustring.gsub(result, "{" .. escape(capture) .. "}", capture .. "[[File:VP.png|19px]]")
end
for capture in mw.ustring.gmatch(result, "{}") do
local shieldsize = "19px"
-- Are there any cases where {} should produce a larger shield?
-- if reasonForLargerShield then
-- shieldsize = "30px"
-- end
result = mw.ustring.gsub(result, "{}", "[[File:VP.png|" .. shieldsize .. "]]")
end
-- result = result .. "[].[2].[!2].[P].[D].[6D]"
for capture in mw.ustring.gmatch(result, "%[(![0-9]+)%]") do
local coinsize = mw.ustring.gsub(capture, "!", "")
result = mw.ustring.gsub(result, "%[" .. escape(capture) .. "%]", "[[File:Coin" .. coinsize .. ".png|19px]]")
end
for capture in mw.ustring.gmatch(result, "%[([0-9]+)%]") do
result = mw.ustring.gsub(result, "%[" .. escape(capture) .. "%]", "[[File:Coin" .. capture .. ".png|19px]]")
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|19px]]")
end
for capture in mw.ustring.gmatch(result, "%[(P+)%]") do
result = mw.ustring.gsub(result, "%[" .. escape(capture) .. "%]", "[[File:Potion.png|10px]]")
end
for capture in mw.ustring.gmatch(result, "%[%]") do
result = mw.ustring.gsub(result, "%[%]", "[[File:Coin.png|19px]]")
end
-- result = result .. "<>.<>"
for capture in mw.ustring.gmatch(result, "<>") do
result = mw.ustring.gsub(result, "<>", "[[File:Sun.png|19px]]")
end
return result
end
return p