104 lines
2.1 KiB
Go
104 lines
2.1 KiB
Go
|
package main
|
||
|
|
||
|
import (
|
||
|
"strconv"
|
||
|
"strings"
|
||
|
)
|
||
|
|
||
|
type jsonSet struct {
|
||
|
Name string
|
||
|
Cards []jsonCard
|
||
|
}
|
||
|
|
||
|
type jsonCard struct {
|
||
|
ID string
|
||
|
Name string
|
||
|
Element string
|
||
|
Keywords []string
|
||
|
Cost int
|
||
|
Power int
|
||
|
Type string
|
||
|
Text string
|
||
|
}
|
||
|
|
||
|
func convert(xmlset xmlSet) (s jsonSet) {
|
||
|
s.Name = xmlset.Name
|
||
|
for _, xmlcard := range xmlset.Cards {
|
||
|
jsoncard := jsonCard{
|
||
|
Name: xmlcard.Name,
|
||
|
}
|
||
|
for _, property := range xmlcard.Properties {
|
||
|
switch property.Name {
|
||
|
case "Cost":
|
||
|
if property.Value != "" {
|
||
|
jsoncard.Cost, _ = strconv.Atoi(property.Value)
|
||
|
}
|
||
|
case "Element":
|
||
|
if property.Value != "" {
|
||
|
jsoncard.Element = property.Value
|
||
|
}
|
||
|
case "Keywords":
|
||
|
if property.Value != "" {
|
||
|
jsoncard.Keywords = strings.Split(strings.TrimRight(property.Value, "."), ", ")
|
||
|
}
|
||
|
case "MultiPrimaryElement":
|
||
|
//todo
|
||
|
case "MultiSecondaryElement":
|
||
|
//todo
|
||
|
case "Number":
|
||
|
jsoncard.ID = strings.ToLower(property.Value)
|
||
|
case "PlayRequiredElement":
|
||
|
//todo
|
||
|
case "PlayRequiredPower":
|
||
|
//todo
|
||
|
case "Power":
|
||
|
if property.Value != "" {
|
||
|
jsoncard.Cost, _ = strconv.Atoi(property.Value)
|
||
|
}
|
||
|
case "ProblemBonus":
|
||
|
//todo
|
||
|
case "ProblemOpponentPower":
|
||
|
//todo
|
||
|
case "ProblemPlayerElement1":
|
||
|
//todo
|
||
|
case "ProblemPlayerElement1Power":
|
||
|
//todo
|
||
|
case "ProblemPlayerElement2":
|
||
|
//todo
|
||
|
case "ProblemPlayerElement2Power":
|
||
|
//todo
|
||
|
case "Rarity":
|
||
|
//todo
|
||
|
case "SecondaryPlayRequiredElement":
|
||
|
//todo
|
||
|
case "SecondaryPlayRequiredPower":
|
||
|
//todo
|
||
|
case "Subname":
|
||
|
//todo
|
||
|
case "TertiaryPlayRequiredElement":
|
||
|
//todo
|
||
|
case "TertiaryPlayRequiredPower":
|
||
|
//todo
|
||
|
case "Text":
|
||
|
jsoncard.Text = property.Value
|
||
|
case "Traits":
|
||
|
//todo
|
||
|
case "TriElement":
|
||
|
//todo
|
||
|
case "TriPrimaryElement":
|
||
|
//todo
|
||
|
case "TriSecondaryElement":
|
||
|
//todo
|
||
|
case "Type":
|
||
|
jsoncard.Type = property.Value
|
||
|
}
|
||
|
}
|
||
|
// Don't let empty arrays be null
|
||
|
if jsoncard.Keywords == nil {
|
||
|
jsoncard.Keywords = []string{}
|
||
|
}
|
||
|
s.Cards = append(s.Cards, jsoncard)
|
||
|
}
|
||
|
return
|
||
|
}
|