package main import ( "fmt" "strings" ) type Gun struct { node *Node Pos Vec2 Mount string // might be empty for no mount Over bool // false=under, true=over } func (g *Gun) Parse(node *Node) error { if node.Key() != "gun" { return fmt.Errorf("not a gun") } g.node = node g.Pos.Parse(node.Line) work := strings.Split(node.Value(), " ") if len(work) >= 3 { g.Mount = strings.Join(work[3:], " ") } if node.Len() != 0 { for _, kid := range node.Children { switch kid.Key() { case "over": g.Over = true } } } return nil } type Turret struct { node *Node Pos Vec2 Mount string // might be empty for no mount Over bool // false=under, true=over } func (t *Turret) Parse(node *Node) error { if node.Key() != "turret" { return fmt.Errorf("not a turret") } t.node = node t.Pos.Parse(node.Line) work := strings.Split(node.Value(), " ") if len(work) >= 3 { t.Mount = strings.Join(work[3:], " ") } if node.Len() != 0 { for _, kid := range node.Children { switch kid.Key() { case "over": t.Over = true } } } return nil }