1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- package dmmo
- import (
- "encoding/json"
- "strings"
- )
- type Tile struct {
- Name string `json:"name"`
- Symbol string `json:"symbol"`
- Color string `json:"color"`
- AutoLight bool `json:"auto-light"`
- }
- func NewTile(name, sym, col string, auto bool) *Tile {
- return &Tile{Name: name, Symbol: sym, Color: col, AutoLight: auto}
- }
- func TileFromString(s string) *Tile {
- var t *Tile
- err := json.Unmarshal([]byte(s), t)
- if err != nil {
- return nil
- }
- return t
- }
- func (t *Tile) DarkColor() string {
- return t.Color
- }
- func (t *Tile) LitColor() string {
- if !t.AutoLight {
- return t.Color
- }
- return "BRI " + t.Color
- }
- func (t *Tile) InfraColor() string {
- if !t.AutoLight {
- return t.Color
- }
- parts := strings.Split(t.Color, " ")
- // BRI WHI ON BLA (4) | RED ON WHI (3)
- if len(parts) == 4 {
- return "WHI ON " + parts[3]
- } else {
- return "WHI ON " + parts[2]
- }
- }
|