LoadBlocks.go 678 B

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