Skip to content

Category specific template text

Joe Miragliuolo edited this page May 1, 2024 · 2 revisions

Category-specific template text

Let's say you have a deck with cards that are categorized by a column Type, and you have per-type "flavor text" you'd like to include without repeating it in your source spreadsheet. You can create a Hash of your flavor texts, like so:

flavortext = {
	"creeper" => "You cannot hold this card, but must place it face up in front of you as soon as you get it.\nIf you drew it, immediately draw another card to replace it.",
	"keeper" => "To play this card, place it face up on the table in front of you.",
	"goal" => "To play this card, place it face up in the center of the table. Discard previous Goal, if any.",
	"surprise" => "This card can be played at any time, for one of the functions described below, or to cancel a Surprise which another player has just played",
	"action" => "To play this card, do whatever it says, then place it on the discard pile.",
	"newrule" => "To play this card, place it face up in the center of the table. New rules take effect instantly."
}

Then, add an empty array to the data hash in the Deck block to hold the "flavor text", loop through the Types for each card, and push the matching flavor text into that empty array. Note, in this example, each card's Type is converted to a slug by stripping spaces and lower-casing the text. If your Hash keys match the card's Type, you don't need to do that, and can just replace the fetch with flavortext.fetch(thetype).

data['FlavorText'] = []
data['Type'].each do |thetype|
	data['FlavorText'].push flavortext.fetch(thetype.downcase.sub(/\s/,''))
end

Now your data hash includes an array of FlavorText strings to match each card.

Clone this wiki locally