engines.go 1015 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package main
  2. import (
  3. "fmt"
  4. "strings"
  5. )
  6. type Engine struct {
  7. node *Node // Ref
  8. Kind string // engine, reverse engine, steering
  9. Sides string // L = Left, R = Right
  10. Pos Vec2
  11. Zoom float64
  12. Angle float64
  13. Over bool // false=under, true=over
  14. }
  15. func (e *Engine) Parse(node *Node) error {
  16. if !strings.Contains(node.Key(), "engine") {
  17. return fmt.Errorf("not a engine")
  18. }
  19. e.node = node
  20. if strings.Contains(node.Key(), "reverse") {
  21. e.Kind = "reverse engine"
  22. } else if strings.Contains(node.Key(), "steering") {
  23. e.Kind = "steering engine"
  24. } else {
  25. e.Kind = "engine"
  26. }
  27. e.Pos.Parse(node.Line)
  28. if node.Len() == 0 {
  29. return nil
  30. }
  31. for _, kid := range node.Children {
  32. switch kid.Key() {
  33. case "zoom":
  34. e.Zoom = kid.ValueFloat64()
  35. case "angle":
  36. e.Angle = kid.ValueFloat64()
  37. case "over":
  38. e.Over = true
  39. case "left":
  40. if !strings.Contains(e.Sides, "L") {
  41. e.Sides += "L"
  42. }
  43. case "right":
  44. if !strings.Contains(e.Sides, "R") {
  45. e.Sides += "R"
  46. }
  47. }
  48. }
  49. return nil
  50. }