-
Notifications
You must be signed in to change notification settings - Fork 1
/
reels.go
104 lines (84 loc) · 2.09 KB
/
reels.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package mathtoolset2
import (
"io"
"log/slog"
"strings"
"github.com/zhs007/goutils"
sgc7game "github.com/zhs007/slotsgamecore7/game"
)
func LoadReels(reader io.Reader) ([][]string, error) {
reels := [][]string{}
// x -> ri
mapri := make(map[int]int)
maxri := 0
isend := []bool{}
isfirst := true
err := sgc7game.LoadExcelWithReader(reader, "", func(x int, str string) string {
header := strings.ToLower(strings.TrimSpace(str))
if header[0] == 'r' {
iv, err := goutils.String2Int64(header[1:])
if err != nil {
goutils.Error("LoadReels:LoadExcelWithReader:String2Int64",
slog.String("header", header),
goutils.Err(err))
return ""
}
if iv <= 0 {
goutils.Error("LoadReels:LoadExcelWithReader",
slog.String("info", "check iv"),
slog.String("header", header),
goutils.Err(sgc7game.ErrInvalidReelsExcelFile))
return ""
}
mapri[x] = int(iv) - 1
if int(iv) > maxri {
maxri = int(iv)
}
}
return header
}, func(x int, y int, header string, data string) error {
if isfirst {
isfirst = false
if maxri != len(mapri) {
goutils.Error("LoadReels:LoadExcelWithReader",
slog.String("info", "check len"),
slog.Int("maxri", maxri),
slog.Any("mapri", mapri),
goutils.Err(sgc7game.ErrInvalidReelsExcelFile))
return sgc7game.ErrInvalidReelsExcelFile
}
if maxri <= 0 {
goutils.Error("LoadReels:LoadExcelWithReader",
slog.String("info", "check empty"),
slog.Int("maxri", maxri),
slog.Any("mapri", mapri),
goutils.Err(sgc7game.ErrInvalidReelsExcelFile))
return sgc7game.ErrInvalidReelsExcelFile
}
for i := 0; i < maxri; i++ {
reels = append(reels, []string{})
isend = append(isend, false)
}
}
ri, isok := mapri[x]
if isok {
data = strings.TrimSpace(data)
if len(data) > 0 {
if isok {
reels[ri] = append(reels[ri], data)
} else {
isend[ri] = true
}
} else {
isend[ri] = true
}
}
return nil
})
if err != nil {
goutils.Error("LoadReels:LoadExcelWithReader",
goutils.Err(err))
return nil, err
}
return reels, nil
}