You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently I am in the process of building out useable items. Currently there is not really a process in the code that builds out useable items other than what is in the info node. For most useable items the important information is actually in spec which is not iterated over.
I am trying to figure out the best way to structure this. While we could always created a nested struct it does not seem necessary
type Item struct {
Info Info
Spec Spec
}
type Info struct {
// Everything in info
}
type Spec struct {
// Everything in spec
}
This seems like it would be rather tedious and not have any real advantages. The way I am currently experimenting with is by iterating over a slice of subSearches and creating items to map[int]Item . Once the iteration has finished the structs are merged.
for j := uint32(0); j < uint32(itemGroupNode.ChildCount); j++ {
itemNode := nodes[itemGroupNode.ChildID+j]
name := textLookup[itemNode.NameID]
var item Item
itemMap := make(map[int]Item)
subSearches := []string{"/info", "/spec"}
for i, subSrch := range subSearches {
subSearch := search + "/" + groupName + "/" + name + subSrch
valid := gonx.FindNode(subSearch, nodes, textLookup, func(node *gonx.Node) {
itemMap[i] = getItem(node, nodes, textLookup)
})
if !valid {
log.Println("Invalid node search:", subSearch)
}
}
item = itemMap[0]
mergo.Merge(&item, itemMap[1])
name = strings.TrimSuffix(name, filepath.Ext(name))
itemID, err := strconv.Atoi(name)
if err != nil {
log.Println(err)
continue
}
item.InvTabID = byte(itemID / 1e6)
items[int32(itemID)] = item
}
Currently I am in the process of building out useable items. Currently there is not really a process in the code that builds out useable items other than what is in the info node. For most useable items the important information is actually in spec which is not iterated over.
I am trying to figure out the best way to structure this. While we could always created a nested struct it does not seem necessary
This seems like it would be rather tedious and not have any real advantages. The way I am currently experimenting with is by iterating over a slice of subSearches and creating items to map[int]Item . Once the iteration has finished the structs are merged.
This method is using the following package at the cost of reflection:
https://github.com/imdario/mergo
Any ideas that might be more efficient or should this suffice?
The text was updated successfully, but these errors were encountered: