package main import "log" type TileType uint8 const ( BasicTile TileType = iota AnimatedTile ) type Tile interface { Name() string Type() TileType Symbol() string Color() string Next() 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 } 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 { 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)) } t := &TileAnimated{ name: m["name"].(string), symbols: syms, colors: cols, } return t } else { log.Printf("TileFromMap(m map[string]any) Unknown Tile Type") return nil } }