1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- package main
- import "log"
- type TileType uint8
- const (
- BasicTile TileType = iota
- AnimatedTile
- )
- type Tile interface {
- Name() string
- Type() TileType
- Symbol() string
- Color() string
- Next()
- Update() []string
- Len() int
- ToMap() map[string]any
- }
- func TileFromMap(m map[string]any) Tile {
- _, has := m["symbol"]
- _, has_s := m["symbols"]
- if !has_s && !has {
- log.Println("TileFromMap(m map[string]any) Missing 'symbol' or 'symbols'")
- return nil
- }
- _, has_u := m["update"]
- if has && !has_s {
- t := &TileBasic{
- name: m["name"].(string),
- symbol: m["symbol"].(string),
- color: m["color"].(string),
- }
- return t
- } else if has_s && !has && has_u {
- syms := []string{}
- for _, s := range m["symbols"].([]any) {
- syms = append(syms, s.(string))
- }
- cols := []string{}
- for _, c := range m["colors"].([]any) {
- cols = append(cols, c.(string))
- }
- ups := []string{}
- for _, u := range m["update"].([]any) {
- ups = append(ups, u.(string))
- }
- t := &TileAnimated{
- name: m["name"].(string),
- symbols: syms,
- colors: cols,
- update: ups,
- }
- return t
- } else {
- log.Printf("TileFromMap(m map[string]any) Unknown Tile Type")
- return nil
- }
- }
|