Skip to content

Commit 195a4eb

Browse files
committed
correctly loading the texts
1 parent db7c561 commit 195a4eb

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

game/game.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,24 @@ import (
55
"io/ioutil"
66
"math/rand"
77
"os"
8-
"path"
98
"strings"
9+
"time"
1010

1111
"github.com/shilangyu/typer-go/settings"
12-
"github.com/shilangyu/typer-go/utils"
1312
)
1413

1514
// ChooseText randomly chooses a text from the dataset
1615
func ChooseText() (string, error) {
1716
if _, err := os.Stat(settings.I.TextsPath); os.IsNotExist(err) {
1817
return "", errors.New("Didnt find typer texts, make sure your path is correct")
1918
}
19+
rand.Seed(time.Now().UTC().UnixNano())
2020

21-
bytes, err := ioutil.ReadFile(path.Join(utils.Root(), "texts.txt"))
21+
bytes, err := ioutil.ReadFile(settings.I.TextsPath)
2222
if err != nil {
23-
return "", nil
23+
return "", errors.New("Couldnt load the typer texts, make sure the permission are correct")
2424
}
25-
content := string(bytes)
26-
texts := strings.Split(content, "\n")
25+
texts := strings.Split(string(bytes), "\n")
2726
texts = texts[:len(texts)-1]
2827

2928
return texts[rand.Intn(len(texts))], nil

0 commit comments

Comments
 (0)