123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- package main
- import (
- "fmt"
- "log"
- "os"
- "path/filepath"
- "strings"
- "time"
- )
- func main() {
- c := &Catalog{}
- _, err := os.Stat("content")
- if err != nil {
- os.Mkdir("content", 0775)
- _, err = os.Stat(filepath.Join("content", "tiles"))
- if err != nil {
- os.Mkdir(filepath.Join("content", "tiles"), 0775)
- }
- err = c.MakeTemplate(filepath.Join("content", "tiles", "0_template.json"))
- if err != nil {
- log.Printf("MakeTemplate: %v", err)
- return
- }
- }
- err = c.LoadTiles(filepath.Join("content", "tiles"))
- if err != nil {
- log.Printf("LoadTiles: %v", err)
- return
- }
- fmt.Printf("Tiles: %d\n", len(c.Tiles))
- for idx, t := range c.Tiles {
- switch t.Type() {
- case BasicTile:
- fmt.Printf(" %3d %-30s (1) %s\n", idx, t.Name(), t.Symbol())
- case AnimatedTile:
- symbols := ""
- for range make([]byte, t.Len()) {
- if symbols == "" || symbols != t.Symbol() {
- symbols += t.Symbol()
- }
- t.Next()
- }
- timed := time.Duration(0)
- for _, u := range t.Update() {
- if strings.HasPrefix(u, "time ") {
- part := strings.ReplaceAll(u, "time ", "")
- work, err := time.ParseDuration(part)
- if err != nil {
- continue
- }
- timed += work
- }
- }
- if timed != time.Duration(0) {
- fmt.Printf("A %3d %-30s (%d) %s %s\n", idx, t.Name(), t.Len(), symbols, timed)
- continue
- }
- fmt.Printf("A %3d %-30s (%d) %s\n", idx, t.Name(), t.Len(), symbols)
- }
- }
- }
|