LoadBlocks.go 674 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. package solver
  2. import (
  3. "embed"
  4. "strings"
  5. "time"
  6. )
  7. // Dirty AF. Not happy with this. 😒
  8. //
  9. //go:embed blocks.csv
  10. var f embed.FS
  11. // Load all possible blocks from CSV in to memory
  12. func (solver *Solver) LoadBlocks() {
  13. defer solver.timeTrack(time.Now(), "Done!")
  14. solver.Outp.Printf("Loading blocks... ")
  15. var blocks []string
  16. file, err := f.ReadFile("blocks.csv")
  17. if err != nil {
  18. panic(err)
  19. }
  20. temp := strings.Split(string(file), "\n")
  21. for _, line := range temp {
  22. block := string(line)
  23. if block == "\n" || block == "" { // Ignore new-line at the end of the file.
  24. continue
  25. }
  26. blocks = append(blocks, block)
  27. }
  28. solver.Controller.Blocks = blocks
  29. }