1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- package main
- import (
- "fmt"
- "strings"
- )
- type Engine struct {
- node *Node // Ref
- Kind string // engine, reverse engine, steering
- Sides string // L = Left, R = Right
- Pos Vec2
- Zoom float64
- Angle float64
- Over bool // false=under, true=over
- }
- func (e *Engine) Parse(node *Node) error {
- if !strings.Contains(node.Key(), "engine") {
- return fmt.Errorf("not a engine")
- }
- e.node = node
- if strings.Contains(node.Key(), "reverse") {
- e.Kind = "reverse engine"
- } else if strings.Contains(node.Key(), "steering") {
- e.Kind = "steering engine"
- } else {
- e.Kind = "engine"
- }
- e.Pos.Parse(node.Line)
- if node.Len() == 0 {
- return nil
- }
- for _, kid := range node.Children {
- switch kid.Key() {
- case "zoom":
- e.Zoom = kid.ValueFloat64()
- case "angle":
- e.Angle = kid.ValueFloat64()
- case "over":
- e.Over = true
- case "left":
- if !strings.Contains(e.Sides, "L") {
- e.Sides += "L"
- }
- case "right":
- if !strings.Contains(e.Sides, "R") {
- e.Sides += "R"
- }
- }
- }
- return nil
- }
|