0.0.5 Parsing xml pallette. /JL
This commit is contained in:
93
pallette.go
Normal file
93
pallette.go
Normal file
@@ -0,0 +1,93 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/xml"
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
)
|
||||
|
||||
type (
|
||||
Pallette struct {
|
||||
XMLName xml.Name `xml:"pallette"`
|
||||
Brands Brandsstruct `xml:"brands"`
|
||||
}
|
||||
|
||||
Brandsstruct struct {
|
||||
XMLName xml.Name `xml:"brands"`
|
||||
Brand []Brandstruct `xml:"brand"`
|
||||
}
|
||||
|
||||
Brandstruct struct {
|
||||
XMLName xml.Name `xml:"brand"`
|
||||
BrandName string `xml:"brandname"`
|
||||
Series Seriesstruct `xml:"series"`
|
||||
}
|
||||
|
||||
Seriesstruct struct {
|
||||
XMLName xml.Name `xml:"series"`
|
||||
Serie []Seriestruct `xml:"serie"`
|
||||
}
|
||||
|
||||
Seriestruct struct {
|
||||
XMLName xml.Name `xml:"serie"`
|
||||
SerieName string `xml:"seriename"`
|
||||
Pegboards Pegboardsstruct `xml:"pegboards"`
|
||||
Beads Beadsstruct `xml:"beads"`
|
||||
}
|
||||
|
||||
Pegboardsstruct struct {
|
||||
XMLName xml.Name `xml:"pegboards"`
|
||||
Pegboard []Pegboardstruct `xml:"pegboard"`
|
||||
}
|
||||
|
||||
Pegboardstruct struct {
|
||||
XMLName xml.Name `xml:"pegboard"`
|
||||
Type string `xml:"type"`
|
||||
Width string `xml:"width"`
|
||||
Height string `xml:"height"`
|
||||
}
|
||||
|
||||
Beadsstruct struct {
|
||||
XMLName xml.Name `xml:"beads"`
|
||||
Color []Colorstruct `xml:"color"`
|
||||
}
|
||||
|
||||
Colorstruct struct {
|
||||
XMLName xml.Name `xml:"color"`
|
||||
ColorIndex int `xml:"colorIndex,attr"`
|
||||
ColorName string `xml:"colorname"`
|
||||
ProductCode string `xml:"productCode"`
|
||||
Brand string `xml:"brand"`
|
||||
Red byte `xml:"red"`
|
||||
Green byte `xml:"green"`
|
||||
Blue byte `xml:"blue"`
|
||||
IsPearl bool `xml:"isPearl"`
|
||||
IsTranslucent bool `xml:"isTranslucent"`
|
||||
IsNeutral bool `xml:"isNeutral"`
|
||||
IsGrayscale bool `xml:"isGrayscale"`
|
||||
Disabled bool `xml:"disabled"`
|
||||
}
|
||||
)
|
||||
|
||||
func CreatePallette(mw *MyMainWindow) {
|
||||
// Open our xmlFile
|
||||
XMLFile, err := os.Open("pallettes\\pallette.xml")
|
||||
// if we os.Open returns an error then handle it
|
||||
if err != nil {
|
||||
log.Print("Failed to open pallette.xml")
|
||||
log.Panic(err)
|
||||
}
|
||||
|
||||
log.Println("Successfully Opened pallette.xml")
|
||||
// defer the closing of our xmlFile so that we can parse it later on
|
||||
defer XMLFile.Close()
|
||||
|
||||
// read our opened xmlFile as a byte array.
|
||||
byteValue, _ := io.ReadAll(XMLFile)
|
||||
|
||||
er := xml.Unmarshal(byteValue, &mw.pallette)
|
||||
if er != nil {
|
||||
log.Printf("Failed to unmarshal: %v", er)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user