/
preprocess.go
82 lines (71 loc) · 1.92 KB
/
preprocess.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package mythicmtg
import (
"errors"
"strings"
"github.com/mtgban/go-mtgban/mtgmatcher"
)
var cardTable = map[string]string{
"Archangel Avacyn | Avacyn, the Purifer": "Archangel Avacyn // Avacyn, the Purifier",
"Aberrant Researcher | Perfect Form": "Aberrant Researcher // Perfected Form",
"Duskwatch Recruiter | Krallenhorde Brawler": "Duskwatch Recruiter | Krallenhorde Howler",
"Golden Guardian | Gold-Forged Garrison": "Golden Guardian | Gold-Forge Garrison",
"Grizzled Angler | Grizzled Anglerfish": "Grizzled Angler // Grisly Anglerfish",
"Jushi Apprentice | Tomoya the Reveler": "Jushi Apprentice // Tomoya the Revealer",
"Wretched, The": "The Wretched",
"Finality": "Find // Finality",
}
func preprocess(cardName, edition string, foil bool) (*mtgmatcher.Card, error) {
variant := ""
variants := strings.Split(cardName, " - ")
cardName = variants[0]
if len(variants) > 1 {
variant = variants[1]
}
if strings.HasSuffix(edition, "En") {
edition = strings.TrimSuffix(edition, " En")
}
switch edition {
case "Kaldheim":
if variant == "Extended" {
switch cardName {
case "Alrund's Epiphany",
"Battle Mammoth",
"Haunting Voyage",
"Quakebringer",
"Starnheim Unleashed":
variant = "Borderless"
default:
variant = "Extended Art"
}
}
case "Double Masters":
if mtgmatcher.IsBasicLand(cardName) {
variant = "Unglued"
}
}
isFoil := foil
variants = mtgmatcher.SplitVariants(cardName)
cardName = variants[0]
if len(variants) > 1 {
if variant != "" {
variant += " "
}
variant += variants[1]
if strings.ToLower(variant) == "foil" {
isFoil = true
}
}
if isFoil && cardName == "Anje Falkenrath" {
return nil, errors.New("does not exist")
}
lutName, found := cardTable[cardName]
if found {
cardName = lutName
}
return &mtgmatcher.Card{
Name: cardName,
Edition: edition,
Variation: variant,
Foil: isFoil,
}, nil
}