Module:Card

From DominionStrategy Wiki
Revision as of 18:53, 26 September 2024 by 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...")
Jump to navigation Jump to search

Usage

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

Lua error at line 6: attempt to index global 'cards' (a nil value). Lua error at line 6: attempt to index global 'cards' (a nil value). Lua error at line 6: attempt to index global 'cards' (a nil value).

{{#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}}

Lua error at line 31: attempt to index global 'cards' (a nil value). Lua error at line 31: attempt to index global 'cards' (a nil value). Lua error at line 31: attempt to index global 'cards' (a nil value). Lua error at line 31: attempt to index global 'cards' (a nil value). Lua error at line 31: attempt to index global 'cards' (a nil value). Lua error at line 31: attempt to index global 'cards' (a nil value).

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

Lua error at line 64: attempt to index global 'cards' (a nil value). Lua error at line 64: attempt to index global 'cards' (a nil value).

{{#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
		return ""
	end
	local card = mw.loadJsonData(frame.args[1].."/json")
	return card[frame.args[2]]
end

return p