line.go 673 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package door
  2. // This was the way I did it in door++...
  3. // Don't
  4. /*
  5. type RenderOutput struct {
  6. Color string
  7. Pos int
  8. Len int
  9. }
  10. type Render struct {
  11. Text string
  12. Outputs []RenderOutput
  13. }
  14. */
  15. type Line struct {
  16. Text string
  17. DefaultColor string
  18. RenderF func(string) string
  19. UpdateF func() string
  20. }
  21. func (l *Line) Update() bool {
  22. if l.UpdateF == nil {
  23. return false
  24. }
  25. NewText := l.UpdateF()
  26. if NewText != l.Text {
  27. l.Text = NewText
  28. return true
  29. }
  30. return false
  31. }
  32. func (l *Line) Output(d *Door) {
  33. if l.RenderF == nil {
  34. output := l.DefaultColor + l.Text
  35. d.Write(output)
  36. } else {
  37. output := l.RenderF(l.Text)
  38. d.Write(output)
  39. }
  40. }