Update convertset to add boosted manes
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
Hamcha 2019-08-27 11:59:07 +02:00
parent 643a86a604
commit a3db545be3
2 changed files with 155 additions and 142 deletions

View file

@ -28,6 +28,7 @@ type jsonCard struct {
ProblemBonus *int `json:",omitempty"` ProblemBonus *int `json:",omitempty"`
ProblemOpponentPower int `json:",omitempty"` ProblemOpponentPower int `json:",omitempty"`
ProblemRequirement jsonPowerRequirement `json:",omitempty"` ProblemRequirement jsonPowerRequirement `json:",omitempty"`
Boosted *jsonCard `json:",omitempty"`
} }
type jsonPowerRequirement map[string]int type jsonPowerRequirement map[string]int
@ -35,152 +36,163 @@ type jsonPowerRequirement map[string]int
func convert(xmlset xmlSet) (s jsonSet) { func convert(xmlset xmlSet) (s jsonSet) {
s.Name = xmlset.Name s.Name = xmlset.Name
for _, xmlcard := range xmlset.Cards { for _, xmlcard := range xmlset.Cards {
jsoncard := jsonCard{ jsoncard := decodeCard(xmlcard)
Name: xmlcard.Name,
Keywords: []string{},
Traits: []string{},
Element: []string{},
}
type reqUnit struct { if jsoncard.Type == "Mane Character" && xmlcard.Alternate != nil {
Element string boosted := decodeCard(*xmlcard.Alternate)
Count int jsoncard.Boosted = &boosted
}
requirements := make([]reqUnit, 3)
problemreq := make([]reqUnit, 2)
for _, property := range xmlcard.Properties {
switch property.Name {
case "Cost":
if property.Value != "" {
cost, _ := strconv.Atoi(property.Value)
jsoncard.Cost = &cost
}
case "Element":
if property.Value != "" && property.Value != "Multicolor" {
jsoncard.Element = append(jsoncard.Element, property.Value)
}
case "Keywords":
if property.Value != "" {
jsoncard.Keywords = strings.Split(strings.TrimRight(property.Value, "."), ", ")
}
case "Number":
jsoncard.ID = strings.ToLower(property.Value)
case "PlayRequiredElement":
if property.Value != "" {
requirements[0].Element = property.Value
}
case "PlayRequiredPower":
if property.Value != "" {
requirements[0].Count, _ = strconv.Atoi(property.Value)
}
case "Power":
if property.Value != "" {
power, _ := strconv.Atoi(property.Value)
jsoncard.Power = &power
}
case "ProblemBonus":
if property.Value != "" {
bonus, _ := strconv.Atoi(property.Value)
jsoncard.ProblemBonus = &bonus
}
case "ProblemOpponentPower":
if property.Value != "" {
jsoncard.ProblemOpponentPower, _ = strconv.Atoi(property.Value)
}
case "ProblemPlayerElement1":
if property.Value != "" {
problemreq[0].Element = property.Value
}
case "ProblemPlayerElement1Power":
if property.Value != "" {
problemreq[0].Count, _ = strconv.Atoi(property.Value)
}
case "ProblemPlayerElement2":
if property.Value != "" {
problemreq[1].Element = property.Value
}
case "ProblemPlayerElement2Power":
if property.Value != "" {
problemreq[1].Count, _ = strconv.Atoi(property.Value)
}
case "Rarity":
if property.Value != "" {
jsoncard.Rarity = property.Value
}
case "SecondaryPlayRequiredElement":
if property.Value != "" {
requirements[1].Element = property.Value
}
case "SecondaryPlayRequiredPower":
if property.Value != "" {
requirements[1].Count, _ = strconv.Atoi(property.Value)
}
case "Subname":
if property.Value != "" {
jsoncard.Subname = property.Value
}
case "TertiaryPlayRequiredElement":
if property.Value != "" {
requirements[2].Element = property.Value
}
case "TertiaryPlayRequiredPower":
if property.Value != "" {
requirements[2].Count, _ = strconv.Atoi(property.Value)
}
case "Text":
jsoncard.Text = property.Value
case "Traits":
if property.Value != "" {
jsoncard.Traits = strings.Split(property.Value, ", ")
}
case "TriElement",
"TriPrimaryElement",
"TriSecondaryElement",
"MultiPrimaryElement",
"MultiSecondaryElement":
if property.Value != "" {
jsoncard.Element = append(jsoncard.Element, property.Value)
}
case "Type":
jsoncard.Type = property.Value
}
}
// Fill card requirements
if requirements[0].Element != "" {
jsoncard.Requirement = make(jsonPowerRequirement)
}
for _, req := range requirements {
if req.Element != "" {
jsoncard.Requirement[req.Element] = req.Count
}
}
// Fill problem requirements (this is a bit more tricky)
if problemreq[0].Element != "" {
jsoncard.ProblemRequirement = make(jsonPowerRequirement)
jsoncard.ProblemRequirement[problemreq[0].Element] = problemreq[0].Count
/*
The way OCTGN problems are managed is like this (I think):
- If there are two problem requirements, then both are specified
- If there is one problem requirement and it's "WILD", then
there is just one problem requirement specified (which is colorless)
- If there are two problem requirements, one of which is colorless,
then there is JUST the colored requirement specified, and a
colorless extra requirement is assumed to exist with the same
non-wild requirement amount
*/
if problemreq[0].Element != "Wild" {
if problemreq[1].Element != "" {
jsoncard.ProblemRequirement[problemreq[1].Element] = problemreq[1].Count
} else {
jsoncard.ProblemRequirement["Wild"] = problemreq[0].Count
}
}
} }
s.Cards = append(s.Cards, jsoncard) s.Cards = append(s.Cards, jsoncard)
} }
return return
} }
func decodeCard(xmlcard xmlCard) jsonCard {
jsoncard := jsonCard{
Name: xmlcard.Name,
Keywords: []string{},
Traits: []string{},
Element: []string{},
}
type reqUnit struct {
Element string
Count int
}
requirements := make([]reqUnit, 3)
problemreq := make([]reqUnit, 2)
for _, property := range xmlcard.Properties {
switch property.Name {
case "Cost":
if property.Value != "" {
cost, _ := strconv.Atoi(property.Value)
jsoncard.Cost = &cost
}
case "Element":
if property.Value != "" && property.Value != "Multicolor" {
jsoncard.Element = append(jsoncard.Element, property.Value)
}
case "Keywords":
if property.Value != "" {
jsoncard.Keywords = strings.Split(strings.TrimRight(property.Value, "."), ", ")
}
case "Number":
jsoncard.ID = strings.ToLower(property.Value)
case "PlayRequiredElement":
if property.Value != "" {
requirements[0].Element = property.Value
}
case "PlayRequiredPower":
if property.Value != "" {
requirements[0].Count, _ = strconv.Atoi(property.Value)
}
case "Power":
if property.Value != "" {
power, _ := strconv.Atoi(property.Value)
jsoncard.Power = &power
}
case "ProblemBonus":
if property.Value != "" {
bonus, _ := strconv.Atoi(property.Value)
jsoncard.ProblemBonus = &bonus
}
case "ProblemOpponentPower":
if property.Value != "" {
jsoncard.ProblemOpponentPower, _ = strconv.Atoi(property.Value)
}
case "ProblemPlayerElement1":
if property.Value != "" {
problemreq[0].Element = property.Value
}
case "ProblemPlayerElement1Power":
if property.Value != "" {
problemreq[0].Count, _ = strconv.Atoi(property.Value)
}
case "ProblemPlayerElement2":
if property.Value != "" {
problemreq[1].Element = property.Value
}
case "ProblemPlayerElement2Power":
if property.Value != "" {
problemreq[1].Count, _ = strconv.Atoi(property.Value)
}
case "Rarity":
if property.Value != "" {
jsoncard.Rarity = property.Value
}
case "SecondaryPlayRequiredElement":
if property.Value != "" {
requirements[1].Element = property.Value
}
case "SecondaryPlayRequiredPower":
if property.Value != "" {
requirements[1].Count, _ = strconv.Atoi(property.Value)
}
case "Subname":
if property.Value != "" {
jsoncard.Subname = property.Value
}
case "TertiaryPlayRequiredElement":
if property.Value != "" {
requirements[2].Element = property.Value
}
case "TertiaryPlayRequiredPower":
if property.Value != "" {
requirements[2].Count, _ = strconv.Atoi(property.Value)
}
case "Text":
jsoncard.Text = property.Value
case "Traits":
if property.Value != "" {
jsoncard.Traits = strings.Split(property.Value, ", ")
}
case "TriElement",
"TriPrimaryElement",
"TriSecondaryElement",
"MultiPrimaryElement",
"MultiSecondaryElement":
if property.Value != "" {
jsoncard.Element = append(jsoncard.Element, property.Value)
}
case "Type":
jsoncard.Type = property.Value
}
}
// Fill card requirements
if requirements[0].Element != "" {
jsoncard.Requirement = make(jsonPowerRequirement)
}
for _, req := range requirements {
if req.Element != "" {
jsoncard.Requirement[req.Element] = req.Count
}
}
// Fill problem requirements (this is a bit more tricky)
if problemreq[0].Element != "" {
jsoncard.ProblemRequirement = make(jsonPowerRequirement)
jsoncard.ProblemRequirement[problemreq[0].Element] = problemreq[0].Count
/*
The way OCTGN problems are managed is like this (I think):
- If there are two problem requirements, then both are specified
- If there is one problem requirement and it's "WILD", then
there is just one problem requirement specified (which is colorless)
- If there are two problem requirements, one of which is colorless,
then there is JUST the colored requirement specified, and a
colorless extra requirement is assumed to exist with the same
non-wild requirement amount
*/
if problemreq[0].Element != "Wild" {
if problemreq[1].Element != "" {
jsoncard.ProblemRequirement[problemreq[1].Element] = problemreq[1].Count
} else {
jsoncard.ProblemRequirement["Wild"] = problemreq[0].Count
}
}
}
return jsoncard
}

View file

@ -16,6 +16,7 @@ type xmlCard struct {
ID string `xml:"id,attr"` ID string `xml:"id,attr"`
Name string `xml:"name,attr"` Name string `xml:"name,attr"`
Properties []xmlProperty `xml:"property"` Properties []xmlProperty `xml:"property"`
Alternate *xmlCard `xml:"alternate"`
} }
type xmlProperty struct { type xmlProperty struct {