tile.go 881 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package dmmo
  2. import (
  3. "encoding/json"
  4. "strings"
  5. )
  6. type Tile struct {
  7. Name string `json:"name"`
  8. Symbol string `json:"symbol"`
  9. Color string `json:"color"`
  10. AutoLight bool `json:"auto-light"`
  11. }
  12. func NewTile(name, sym, col string, auto bool) *Tile {
  13. return &Tile{Name: name, Symbol: sym, Color: col, AutoLight: auto}
  14. }
  15. func TileFromString(s string) *Tile {
  16. var t *Tile
  17. err := json.Unmarshal([]byte(s), t)
  18. if err != nil {
  19. return nil
  20. }
  21. return t
  22. }
  23. func (t *Tile) DarkColor() string {
  24. return t.Color
  25. }
  26. func (t *Tile) LitColor() string {
  27. if !t.AutoLight {
  28. return t.Color
  29. }
  30. return "BRI " + t.Color
  31. }
  32. func (t *Tile) InfraColor() string {
  33. if !t.AutoLight {
  34. return t.Color
  35. }
  36. parts := strings.Split(t.Color, " ")
  37. // BRI WHI ON BLA (4) | RED ON WHI (3)
  38. if len(parts) == 4 {
  39. return "WHI ON " + parts[3]
  40. } else {
  41. return "WHI ON " + parts[2]
  42. }
  43. }