-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathoptions.go
300 lines (218 loc) · 6.1 KB
/
options.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
package fnf
import (
rl "github.com/gen2brain/raylib-go/raylib"
"time"
)
type FnfBinding int
const (
NoteKeyLeft0 FnfBinding = iota
NoteKeyLeft1
NoteKeyDown0
NoteKeyDown1
NoteKeyUp0
NoteKeyUp1
NoteKeyRight0
NoteKeyRight1
SelectKey
PauseKey
EscapeKey
SongResetKey
NoteScrollUpKey
NoteScrollDownKey
AudioSpeedUpKey
AudioSpeedDownKey
AudioOffsetUpKey
AudioOffsetDownKey
SetBookMarkKey
JumpToBookMarkKey
ZoomOutKey
ZoomInKey
ScreenshotKey
ToggleDebugMsg
ToggleLogNoteEvent
ToggleDebugGraphics
ReloadAssetsKey
FnfBindingSize
)
var (
// default key map
DefaultKM [FnfBindingSize]int32
// key bindings game will use
TheKM [FnfBindingSize]int32
)
var KeyHumanName [FnfBindingSize]string
func init() {
// set default key bindings
DefaultKM[NoteKeyLeft0] = rl.KeyLeft
DefaultKM[NoteKeyLeft1] = rl.KeyA
DefaultKM[NoteKeyDown0] = rl.KeyDown
DefaultKM[NoteKeyDown1] = rl.KeyS
DefaultKM[NoteKeyUp0] = rl.KeyUp
DefaultKM[NoteKeyUp1] = rl.KeyW
DefaultKM[NoteKeyRight0] = rl.KeyRight
DefaultKM[NoteKeyRight1] = rl.KeyD
DefaultKM[SelectKey] = rl.KeyEnter
DefaultKM[PauseKey] = rl.KeySpace
DefaultKM[EscapeKey] = rl.KeyEscape
DefaultKM[NoteScrollUpKey] = rl.KeyPageUp
DefaultKM[NoteScrollDownKey] = rl.KeyPageDown
DefaultKM[AudioSpeedUpKey] = rl.KeyEqual
DefaultKM[AudioSpeedDownKey] = rl.KeyMinus
DefaultKM[AudioOffsetUpKey] = rl.KeyNine
DefaultKM[AudioOffsetDownKey] = rl.KeyEight
DefaultKM[SongResetKey] = rl.KeyR
DefaultKM[SetBookMarkKey] = rl.KeyB
DefaultKM[JumpToBookMarkKey] = rl.KeyBackspace
DefaultKM[ZoomOutKey] = rl.KeyLeftBracket
DefaultKM[ZoomInKey] = rl.KeyRightBracket
DefaultKM[ScreenshotKey] = rl.KeyF12
DefaultKM[ToggleDebugMsg] = rl.KeyF1
DefaultKM[ToggleLogNoteEvent] = rl.KeyF2
DefaultKM[ToggleDebugGraphics] = rl.KeyF3
DefaultKM[ReloadAssetsKey] = rl.KeyF5
for i := range FnfBindingSize {
if DefaultKM[i] == 0 {
ErrorLogger.Fatalf("default key binding for \"%v\" is omitted", i.String())
}
}
// set TheKM to DefaultKM
TheKM = DefaultKM
// assign names for humans
KeyHumanName[NoteKeyLeft0] = "left 0"
KeyHumanName[NoteKeyLeft1] = "left 1"
KeyHumanName[NoteKeyDown0] = "down 0"
KeyHumanName[NoteKeyDown1] = "down 1"
KeyHumanName[NoteKeyUp0] = "up 0"
KeyHumanName[NoteKeyUp1] = "up 1"
KeyHumanName[NoteKeyRight0] = "right 0"
KeyHumanName[NoteKeyRight1] = "right 1"
KeyHumanName[SelectKey] = "select"
KeyHumanName[PauseKey] = "pause"
KeyHumanName[EscapeKey] = "escape"
KeyHumanName[NoteScrollUpKey] = "scroll up"
KeyHumanName[NoteScrollDownKey] = "scroll down"
KeyHumanName[AudioSpeedUpKey] = "speed up"
KeyHumanName[AudioSpeedDownKey] = "speed down"
KeyHumanName[AudioOffsetUpKey] = "audio offset up"
KeyHumanName[AudioOffsetDownKey] = "audio offset down"
KeyHumanName[SongResetKey] = "reset"
KeyHumanName[SetBookMarkKey] = "bookmark"
KeyHumanName[JumpToBookMarkKey] = "jump to bookmark"
KeyHumanName[ZoomOutKey] = "note spacing up"
KeyHumanName[ZoomInKey] = "note spacing down"
KeyHumanName[ScreenshotKey] = "screenshot"
KeyHumanName[ToggleDebugMsg] = "toggle debug message"
KeyHumanName[ToggleLogNoteEvent] = "toggle note event"
KeyHumanName[ToggleDebugGraphics] = "toggle debug graphics"
KeyHumanName[ReloadAssetsKey] = "reload assets"
for i := range FnfBindingSize {
if KeyHumanName[i] == "" {
ErrorLogger.Fatalf("human name for \"%v\" is omitted", i.String())
}
}
}
func NoteKeys(dir NoteDir) []int32 {
switch dir {
case NoteDirLeft:
return []int32{TheKM[NoteKeyLeft0], TheKM[NoteKeyLeft1]}
case NoteDirDown:
return []int32{TheKM[NoteKeyDown0], TheKM[NoteKeyDown1]}
case NoteDirUp:
return []int32{TheKM[NoteKeyUp0], TheKM[NoteKeyUp1]}
case NoteDirRight:
return []int32{TheKM[NoteKeyRight0], TheKM[NoteKeyRight1]}
default:
ErrorLogger.Fatalf("invalid direction %v", dir)
return []int32{}
}
}
func NoteDirAndIndexToBinding(dir NoteDir, index int) FnfBinding {
if !(0 <= dir && dir < NoteDirSize) {
ErrorLogger.Fatalf("invalid dir \"%v\"", dir)
}
if !(0 <= index && index <= 1) {
ErrorLogger.Fatalf("invalid index \"%v\"", index)
}
switch dir {
case NoteDirLeft:
if index == 0 {
return NoteKeyLeft0
} else {
return NoteKeyLeft1
}
case NoteDirDown:
if index == 0 {
return NoteKeyDown0
} else {
return NoteKeyDown1
}
case NoteDirUp:
if index == 0 {
return NoteKeyUp0
} else {
return NoteKeyUp1
}
case NoteDirRight:
if index == 0 {
return NoteKeyRight0
} else {
return NoteKeyRight1
}
}
ErrorLogger.Fatal("UNREACHABLE")
return 0
}
func SetNoteKeys(dir NoteDir, index int, key int32) {
TheKM[NoteDirAndIndexToBinding(dir, index)] = key
}
func NoteKeysArr() [NoteDirSize][]int32 {
return [NoteDirSize][]int32{
{TheKM[NoteKeyLeft0], TheKM[NoteKeyLeft1]},
{TheKM[NoteKeyDown0], TheKM[NoteKeyDown1]},
{TheKM[NoteKeyUp0], TheKM[NoteKeyUp1]},
{TheKM[NoteKeyRight0], TheKM[NoteKeyRight1]},
}
}
type Options struct {
TargetFPS int32
DisplayFPS bool
Volume float64
DownScroll bool
HitWindows [HitRatingSize]time.Duration
LoadAudioDuringGamePlay bool
GhostTapping bool
MiddleScroll bool
HitSoundVolume float64
DisplayHitMs bool
NoteSplash bool
AudioOffset time.Duration
}
const AudioOffsetMax time.Duration = 500 * time.Millisecond
var DefaultOptions Options
var TheOptions Options
func init() {
// set default option values
DefaultOptions.TargetFPS = 60
DefaultOptions.DisplayFPS = true
DefaultOptions.Volume = 1.0
DefaultOptions.HitWindows[HitRatingBad] = time.Millisecond * 135
DefaultOptions.HitWindows[HitRatingGood] = time.Millisecond * 90
DefaultOptions.HitWindows[HitRatingSick] = time.Millisecond * 45
DefaultOptions.DownScroll = false
DefaultOptions.LoadAudioDuringGamePlay = false
DefaultOptions.GhostTapping = false
DefaultOptions.MiddleScroll = false
DefaultOptions.HitSoundVolume = 0
DefaultOptions.DisplayHitMs = false
DefaultOptions.NoteSplash = true
DefaultOptions.AudioOffset = 0
// set TheOptions to DefaultOptions
TheOptions = DefaultOptions
}
func HitWindow() time.Duration {
return max(
TheOptions.HitWindows[HitRatingBad],
TheOptions.HitWindows[HitRatingGood],
TheOptions.HitWindows[HitRatingSick],
) * 2
}