Module:Card: Difference between revisions
Wikiwikiwiki (talk | contribs) Replaced content with "local p = {} --p stands for package -- 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 cards[frame.args[1]] or not cards[frame.args[1]]["cost"] then return "" end local card = mw.loadJsonData(frame.args[1].."/json") local cost = card["cost"] cost["coin"] = "$" .. string.format("%02d", cost["coin"]) if cost["debt"] == 0 then cost["debt"] = "" else cost["de..." Tag: Replaced |
Wikiwikiwiki (talk | contribs) No edit summary |
||
Line 4: | Line 4: | ||
-- 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 cards[frame.args[1]] or not cards[frame.args[1]]["cost"] then | -- if not cards[frame.args[1]] or not cards[frame.args[1]]["cost"] then | ||
-- return "" | |||
end | -- end | ||
local card = mw.loadJsonData(frame.args[1].."/json") | local card = mw.loadJsonData(frame.args[1].."/json") | ||
local cost = card["cost"] | local cost = card["cost"] | ||
Line 29: | Line 29: | ||
-- 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 cards[frame.args[1]] or not cards[frame.args[1]]["amount"] then | -- if not cards[frame.args[1]] or not cards[frame.args[1]]["amount"] then | ||
-- return "" | |||
end | -- end | ||
local card = mw.loadJsonData(frame.args[1].."/json") | local card = mw.loadJsonData(frame.args[1].."/json") | ||
local players = 2 | local players = 2 | ||
Line 62: | Line 62: | ||
-- 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] or not cards[frame.args[1]] or not cards[frame.args[1]][frame.args[2]] then | -- if not frame.args[1] or not frame.args[2] or not cards[frame.args[1]] or not cards[frame.args[1]][frame.args[2]] then | ||
if not frame.args[1] or not frame.args[2] then | |||
return "" | return "" | ||
end | end |
Revision as of 18:54, 26 September 2024
Usage
{{#invoke:card|cost|Donate}}
{{#invoke:card|cost|Possession}}
{{#invoke:card|cost|Wedding}}
Lua error at line 11: table from mw.loadJsonData is read-only. Lua error at line 11: table from mw.loadJsonData is read-only. Lua error at line 11: table from mw.loadJsonData is read-only.
{{#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}}
Script error: The function "text" does not exist.
{{#invoke:card|text|Abundance}}
Script error: The function "text" does not exist.
{{#invoke:card|text|Wedding|de}}
Script error: The function "text" does not exist.
{{#invoke:card|text|Abundance|de}}
Script error: The function "text" does not exist.
{{#invoke:card|text|Capital}}
Script error: The function "text" does not exist.
<span style='text-align:center; display:block; float:left;'>{{#invoke:card|text|Capital|en|vertical}}</span>{{clear|left}}
Script error: The function "text" does not exist.
{{#invoke:card|text|Cemetery}}
Script error: The function "text" does not exist.
<span style='text-align:center; display:block; float:left;'>{{#invoke:card|text|Cemetery|en|vertical}}</span>{{clear|left}}
Script error: The function "text" does not exist.
{{#invoke:card|text|Pooka}}
Script error: The function "text" does not exist.
{{#invoke:card|text|Miserable}}
Script error: The function "text" does not exist.
<span style='text-align:center; display:block; float:left;'>{{#invoke:card|text|Miserable|en|vertical}}</span>{{clear|left}}
Script error: The function "text" does not exist.
{{#invoke:card|text|Province}}
Script error: The function "text" does not exist.
<span style='text-align:center; display:block; float:left;'>{{#invoke:card|text|Province|en|vertical}}</span>{{clear|left}}
Script error: The function "text" does not exist.
{{#invoke:card|text|Gold}}
Script error: The function "text" does not exist.
<span style='text-align:center; display:block; float:left;'>{{#invoke:card|text|Gold|en|vertical}}</span>{{clear|left}}
Script error: The function "text" does not exist.
{{#invoke:card|text|Hunting Grounds|jp}}
Script error: The function "text" does not exist.
{{#invoke:card|text|Tea House}}
Script error: The function "text" does not exist.
{{#invoke:card|text|Tea House|jp}}
Script error: The function "text" does not exist.
{{#invoke:card|text|Apprentice}}
Script error: The function "text" does not exist.
local p = {} --p stands for package
-- 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 cards[frame.args[1]] or not cards[frame.args[1]]["cost"] then
-- return ""
-- end
local card = mw.loadJsonData(frame.args[1].."/json")
local cost = card["cost"]
cost["coin"] = "$" .. string.format("%02d", cost["coin"])
if cost["debt"] == 0 then
cost["debt"] = ""
else
cost["debt"] = string.format("%02d", cost["debt"]) .. "D"
end
if cost["potion"] == 0 then
cost["potion"] = ""
else
cost["potion"] = "P"
end
return cost["coin"] .. cost["extra"] .. cost["debt"] .. cost["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 cards[frame.args[1]] or not cards[frame.args[1]]["amount"] 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|text}} / {{#invoke:card|query|Wedding|illustrator}}
-- generic card data query
function p.query(frame)
-- if not frame.args[1] or not frame.args[2] or not cards[frame.args[1]] or not cards[frame.args[1]][frame.args[2]] then
if not frame.args[1] or not frame.args[2] then
return ""
end
local card = mw.loadJsonData(frame.args[1].."/json")
return card[frame.args[2]]
end
return p