Skip to content

Commit

Permalink
Add new card symbol fields added by Scryfall
Browse files Browse the repository at this point in the history
Thank you tencorvids for pointing these out!
  • Loading branch information
BlueMonday committed Jan 10, 2025
1 parent 4da07f0 commit 5c592ed
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 10 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 0.9.0
* Add missing object, mana_value, hybrid, phyrexian, gatherer_alternates, and svg_uri card symbol fields
* Deprecate cmc card symbol field, has been replaced by mana_value

## 0.8.0
* Add missing supertypes, card-types, battle-types, keyword-abilities, keyword-actions, ability-words, and flavor-words catalog API calls

Expand Down
2 changes: 1 addition & 1 deletion scryfall.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
)

const (
Version = "0.8.0"
Version = "0.9.0"

defaultBaseURL = "https://api.scryfall.com"
defaultUserAgent = "go-scryfall/" + Version
Expand Down
4 changes: 4 additions & 0 deletions scryfall_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ func intPointer(v int) *int {
return &v
}

func float64Pointer(v float64) *float64 {
return &v
}

func setupTestServer(pattern string, handler func(http.ResponseWriter, *http.Request), clientOptions ...ClientOption) (*Client, *httptest.Server, error) {
mux := http.NewServeMux()
mux.HandleFunc(pattern, handler)
Expand Down
26 changes: 26 additions & 0 deletions symbol.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ import (
// For more information about how the Scryfall API represents mana and costs, see
// the colors and costs overview: https://scryfall.com/docs/api/colors.
type CardSymbol struct {
// Object is the content type for this object, always card_symbol.
Object string `json:"object"`

// Symbol is the plaintext symbol. Often surrounded with curly braces
// {}. Note that not all symbols are ASCII text (for example, {∞}).
Symbol string `json:"symbol"`
Expand All @@ -38,8 +41,15 @@ type CardSymbol struct {
// CMC is a decimal number representing this symbol's converted mana
// cost. Note that mana symbols from funny sets can have fractional
// converted mana costs.
//
// Deprecated: Use ManaValue instead.
CMC float64 `json:"cmc"`

// ManaValue is a decimal number representing this symbol’s mana value
// (also knowns as the converted mana cost). Note that mana symbols
// from funny sets can have fractional mana values.
ManaValue *float64 `json:"mana_value"`

// AppearsInManaCosts is true if this symbol appears in a mana cost on
// any Magic card. For example {20} has this field set to false because
// {20} only appears in Oracle text, not mana costs.
Expand All @@ -50,6 +60,22 @@ type CardSymbol struct {

// Color is an array of colors that this symbol represents.
Colors []Color `json:"colors"`

// Hybrid is true if the symbol is a hybrid mana symbol. Note that
// monocolor Phyrexian symbols aren’t considered hybrid.
Hybrid bool `json:"hybrid"`

// Phyrexian is true if the symbol is a Phyrexian mana symbol, i.e. it
// can be paid with 2 life.
Phyrexian bool `json:"phyrexian"`

// GathererAlternates is an array of plaintext versions of this symbol
// that Gatherer uses on old cards to describe original printed
// text. For example: {W} has ["oW", "ooW"] as alternates.
GathererAlternates []string `json:"gatherer_alternates"`

// SVGURI is a URI to an SVG image of this symbol on Scryfall’s CDNs.
SVGURI *string `json:"svg_uri"`
}

// ManaCost is Scryfall's interpretation of a mana cost.
Expand Down
36 changes: 27 additions & 9 deletions symbol_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

func TestListCardSymbols(t *testing.T) {
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, `{"object": "list", "has_more": false, "data": [{"object": "card_symbol", "symbol": "{T}", "loose_variant": null, "english": "tap this permanent", "transposable": false, "represents_mana": false, "appears_in_mana_costs": false, "cmc": 0, "funny": false, "colors": []}, {"object": "card_symbol", "symbol": "{Q}", "loose_variant": null, "english": "untap this permanent", "transposable": false, "represents_mana": false, "appears_in_mana_costs": false, "cmc": 0, "funny": false, "colors": []}, {"object": "card_symbol", "symbol": "{W/U}", "loose_variant": null, "english": "one white or blue mana", "transposable": true, "represents_mana": true, "appears_in_mana_costs": true, "cmc": 1, "funny": false, "colors": ["W", "U"]}]}`)
fmt.Fprintln(w, `{"object": "list", "has_more": false, "data": [{"object": "card_symbol", "symbol": "{T}", "svg_uri": "https://svgs.scryfall.io/card-symbols/T.svg", "loose_variant": null, "english": "tap this permanent", "transposable": false, "represents_mana": false, "appears_in_mana_costs": false, "mana_value": 0, "hybrid": false, "phyrexian": false, "cmc": 0, "funny": false, "colors": [], "gatherer_alternates": ["ocT", "oT"]}, {"object": "card_symbol", "symbol": "{Q}", "svg_uri": "https://svgs.scryfall.io/card-symbols/Q.svg", "loose_variant": null, "english": "untap this permanent", "transposable": false, "represents_mana": false, "appears_in_mana_costs": false, "mana_value": 0, "hybrid": false, "phyrexian": false, "cmc": 0, "funny": false, "colors": [], "gatherer_alternates": null}, {"object": "card_symbol", "symbol": "{W}", "svg_uri": "https://svgs.scryfall.io/card-symbols/W.svg", "loose_variant": "W", "english": "one white mana", "transposable": false, "represents_mana": true, "appears_in_mana_costs": true, "mana_value": 1, "hybrid": false, "phyrexian": false, "cmc": 1, "funny": false, "colors": ["W"], "gatherer_alternates": ["oW", "ooW"]}]}`)
})
client, ts, err := setupTestServer("/symbology", handler)
if err != nil {
Expand All @@ -26,37 +26,55 @@ func TestListCardSymbols(t *testing.T) {

want := []CardSymbol{
{
Object: "card_symbol",
Symbol: "{T}",
SVGURI: stringPointer("https://svgs.scryfall.io/card-symbols/T.svg"),
LooseVariant: nil,
English: "tap this permanent",
Transposable: false,
RepresentsMana: false,
CMC: 0,
AppearsInManaCosts: false,
ManaValue: float64Pointer(0),
Hybrid: false,
Phyrexian: false,
CMC: 0,
Funny: false,
Colors: []Color{},
GathererAlternates: []string{"ocT", "oT"},
},
{
Object: "card_symbol",
Symbol: "{Q}",
SVGURI: stringPointer("https://svgs.scryfall.io/card-symbols/Q.svg"),
LooseVariant: nil,
English: "untap this permanent",
Transposable: false,
AppearsInManaCosts: false,
RepresentsMana: false,
ManaValue: float64Pointer(0),
Hybrid: false,
Phyrexian: false,
CMC: 0,
AppearsInManaCosts: false,
Funny: false,
Colors: []Color{},
GathererAlternates: nil,
},
{
Symbol: "{W/U}",
LooseVariant: nil,
English: "one white or blue mana",
Transposable: true,
Object: "card_symbol",
Symbol: "{W}",
SVGURI: stringPointer("https://svgs.scryfall.io/card-symbols/W.svg"),
LooseVariant: stringPointer("W"),
English: "one white mana",
Transposable: false,
AppearsInManaCosts: true,
RepresentsMana: true,
ManaValue: float64Pointer(1),
Hybrid: false,
Phyrexian: false,
CMC: 1,
AppearsInManaCosts: true,
Funny: false,
Colors: []Color{ColorWhite, ColorBlue},
Colors: []Color{ColorWhite},
GathererAlternates: []string{"oW", "ooW"},
},
}
if !reflect.DeepEqual(cardSymbols, want) {
Expand Down

0 comments on commit 5c592ed

Please sign in to comment.