main.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. package main
  2. import (
  3. "fmt"
  4. "log"
  5. "os"
  6. "path/filepath"
  7. "strings"
  8. "time"
  9. )
  10. func main() {
  11. c := &Catalog{}
  12. _, err := os.Stat("content")
  13. if err != nil {
  14. os.Mkdir("content", 0775)
  15. _, err = os.Stat(filepath.Join("content", "tiles"))
  16. if err != nil {
  17. os.Mkdir(filepath.Join("content", "tiles"), 0775)
  18. }
  19. err = c.MakeTemplate(filepath.Join("content", "tiles", "0_template.json"))
  20. if err != nil {
  21. log.Printf("MakeTemplate: %v", err)
  22. return
  23. }
  24. }
  25. err = c.LoadTiles(filepath.Join("content", "tiles"))
  26. if err != nil {
  27. log.Printf("LoadTiles: %v", err)
  28. return
  29. }
  30. fmt.Printf("Tiles: %d\n", len(c.Tiles))
  31. for idx, t := range c.Tiles {
  32. switch t.Type() {
  33. case BasicTile:
  34. fmt.Printf(" %3d %-30s (1) %s\n", idx, t.Name(), t.Symbol())
  35. case AnimatedTile:
  36. symbols := ""
  37. for range make([]byte, t.Len()) {
  38. if symbols == "" || symbols != t.Symbol() {
  39. symbols += t.Symbol()
  40. }
  41. t.Next()
  42. }
  43. timed := time.Duration(0)
  44. for _, u := range t.Update() {
  45. if strings.HasPrefix(u, "time ") {
  46. part := strings.ReplaceAll(u, "time ", "")
  47. work, err := time.ParseDuration(part)
  48. if err != nil {
  49. continue
  50. }
  51. timed += work
  52. }
  53. }
  54. if timed != time.Duration(0) {
  55. fmt.Printf("A %3d %-30s (%d) %s %s\n", idx, t.Name(), t.Len(), symbols, timed)
  56. continue
  57. }
  58. fmt.Printf("A %3d %-30s (%d) %s\n", idx, t.Name(), t.Len(), symbols)
  59. }
  60. }
  61. }