+65
Diff
round #1
+61
config.go
+61
config.go
···
109
109
type HoldBlockConfig struct {
110
110
Color ff.Color
111
111
}
112
+
113
+
const configVersion = 1
114
+
115
+
// Save serialises the user-configurable settings to the stash,
116
+
// making it available in both single-player and multiplayer.
117
+
func (c *Config) Save() {
118
+
data := []byte{
119
+
configVersion,
120
+
uint8(c.Level),
121
+
boolByte(c.DropShadow.Enabled),
122
+
boolByte(c.HardDropEnabled),
123
+
boolByte(c.HardDropPointsEnabled),
124
+
boolByte(c.SoftDropPointsEnabled),
125
+
uint8(c.BlockBag),
126
+
uint8(c.NextBlock.Count),
127
+
uint8(c.Background),
128
+
uint8(c.Block.LBlock.Color),
129
+
uint8(c.Block.JBlock.Color),
130
+
uint8(c.Block.IBlock.Color),
131
+
uint8(c.Block.OBlock.Color),
132
+
uint8(c.Block.SBlock.Color),
133
+
uint8(c.Block.TBlock.Color),
134
+
uint8(c.Block.ZBlock.Color),
135
+
}
136
+
ff.SaveStash(ff.GetMe(), data)
137
+
}
138
+
139
+
// Load reads previously saved settings from the stash and applies them
140
+
// to the config. If no stash exists or the version does not match,
141
+
// the defaults already set in config.go are kept unchanged.
142
+
func (c *Config) Load() {
143
+
data := ff.LoadStash(ff.GetMe(), nil)
144
+
if data == nil {
145
+
return
146
+
}
147
+
if len(data) < 16 || data[0] != configVersion {
148
+
return
149
+
}
150
+
c.Level = int(data[1])
151
+
c.DropShadow.Enabled = data[2] != 0
152
+
c.HardDropEnabled = data[3] != 0
153
+
c.HardDropPointsEnabled = data[4] != 0
154
+
c.SoftDropPointsEnabled = data[5] != 0
155
+
c.BlockBag = BlockBagType(data[6])
156
+
c.NextBlock.Count = int(data[7])
157
+
c.Background = ff.Color(data[8])
158
+
c.Block.LBlock.Color = ff.Color(data[9])
159
+
c.Block.JBlock.Color = ff.Color(data[10])
160
+
c.Block.IBlock.Color = ff.Color(data[11])
161
+
c.Block.OBlock.Color = ff.Color(data[12])
162
+
c.Block.SBlock.Color = ff.Color(data[13])
163
+
c.Block.TBlock.Color = ff.Color(data[14])
164
+
c.Block.ZBlock.Color = ff.Color(data[15])
165
+
}
166
+
167
+
func boolByte(b bool) byte {
168
+
if b {
169
+
return 1
170
+
}
171
+
return 0
172
+
}
+2
game.go
+2
game.go
+1
main.go
+1
main.go
History
2 rounds
0 comments
voigt.tngl.sh
submitted
#1
1 commit
expand
collapse
add persistent configuration
expand 0 comments
pull request successfully merged
voigt.tngl.sh
submitted
#0
1 commit
expand
collapse
add persistent configuration