-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathanimations.go
More file actions
284 lines (255 loc) · 12.1 KB
/
animations.go
File metadata and controls
284 lines (255 loc) · 12.1 KB
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
package main
import (
"bufio"
"errors"
"fmt"
"os"
"path/filepath"
"slices"
"strings"
)
func findManifest(hud string) string {
// Search for scripts folder
for _, scripts := range []string{"scripts", "Scripts"} {
_, err := os.Stat(filepath.Join(hud, scripts))
if err == nil { // Found scripts, now locate hudanimations_manifest.
scriptsPath := filepath.Join(hud, scripts)
for _, manifest := range []string{"hudanimations_manifest.txt", "HudAnimations_Manifest.txt"} {
_, er := os.Stat(filepath.Join(scriptsPath, manifest))
if er == nil { // Found hudanimations_manifest
return filepath.Join(scriptsPath, manifest)
}
}
}
}
fmt.Println("Did not find hudanimations_manifest.txt")
pressToExit()
return ""
}
func scanManifest(manifest string) ([]string, []string) {
// Get file names to search
input, err := os.Open(manifest)
if err != nil {
fmt.Printf("Error opening %v for reading: %v\n", manifest, err)
pressToExit()
}
defer input.Close()
// Create slice containing animation files
var files []string
var hudAnimationsManifest []string
scnr := bufio.NewScanner(input)
for scnr.Scan() {
line := scnr.Text()
// If line is a known PeachREC line
if strings.Contains(line, "peachrec") {
continue
}
hudAnimationsManifest = append(hudAnimationsManifest, line)
// Make a list of files to search for code
for _, token := range strings.Fields(line) {
// If line is commented or incompatible, skip
if strings.HasPrefix(token, "//") || strings.HasPrefix(token, "../") {
break
}
// If token is an animations file add it to slice
if strings.Contains(token, ".txt") {
files = append(files, token)
}
}
}
return hudAnimationsManifest, files
}
func insertPeachRecManifest(hudAnimationsManifest []string) []string {
var peachRecManifest []string
// Insert PeachREC file path to the top of the manifest
for f, line := range hudAnimationsManifest {
if strings.Contains(line, "{") {
peachRecManifest = slices.Insert(hudAnimationsManifest, f+1, "\tfile\thudanimations_peachrec.txt")
return peachRecManifest
}
}
return hudAnimationsManifest
}
func scanAnimations(hud string, files []string) ([]string, []string, []string, []string) {
// Go through each animation file and find the first instance of HintMessageHide and HudTournamentSetupPanelOpen/Close
var hintMessageHide []string
var hudTournamentSetupPanelOpen []string
var hudTournamentSetupPanelClose []string
var hudReadyPulseEnd []string
foundHintMessageHide := 0
foundHudTournamentSetupPanelOpen := 0
foundHudTournamentSetupPanelClose := 0
foundHudReadyPulseEnd := 0
for _, file := range files {
input, err := os.Open(filepath.Join(hud, strings.ReplaceAll(file, "\"", "")))
if err != nil && !errors.Is(err, os.ErrNotExist) {
fmt.Printf("Error opening %v to scan animations: %v", file, err)
pressToExit()
}
// Go through current file
scnr := bufio.NewScanner(input)
for scnr.Scan() {
line := scnr.Text()
nextLine: // We scan by tokens to identify the line, once identified we can add the whole line and proceed
for _, token := range strings.Fields(line) {
if strings.HasPrefix(token, "//") { // Ignore commented lines
break
} else if strings.Contains(line, "PeachRec") { // Skip known PeachREC lines
break
}
switch {
// Copy HintMessageHide
case (foundHintMessageHide < 2 && strings.Contains(line, "event HintMessageHide")) || foundHintMessageHide == 1:
// Found animation header, now copy subsequent lines
foundHintMessageHide = 1
hintMessageHide = append(hintMessageHide, line)
if strings.Contains(line, "}") { // Stop copying once a close brace is copies
foundHintMessageHide = 2
fmt.Println("Found custom HintMessageHide animation, using that")
}
break nextLine
// Copy HudTournamentSetupPanelOpen
case (foundHudTournamentSetupPanelOpen < 2 && strings.Contains(line, "event HudTournamentSetupPanelOpen")) || foundHudTournamentSetupPanelOpen == 1:
// Found animation header, now copy subsequent lines
foundHudTournamentSetupPanelOpen = 1
hudTournamentSetupPanelOpen = append(hudTournamentSetupPanelOpen, line)
if strings.Contains(line, "}") { // Stop copying once a close brace is copies
foundHudTournamentSetupPanelOpen = 2
fmt.Println("Found custom HudTournamentSetupPanelOpen animation, using that")
}
break nextLine
// Copy HudTournamentSetupPanelClose
case (foundHudTournamentSetupPanelClose < 2 && strings.Contains(line, "event HudTournamentSetupPanelClose")) || foundHudTournamentSetupPanelClose == 1:
// Found animation header, now copy subsequent lines
foundHudTournamentSetupPanelClose = 1
hudTournamentSetupPanelClose = append(hudTournamentSetupPanelClose, line)
if strings.Contains(line, "}") { // Stop copying once a close brace is copies
foundHudTournamentSetupPanelClose = 2
fmt.Println("Found custom HudTournamentSetupPanelClose animation, using that")
}
break nextLine
// Copy HudReadyPulseEnd
case (foundHudReadyPulseEnd < 2 && strings.Contains(line, "event HudReadyPulseEnd")) || foundHudReadyPulseEnd == 1:
// Found animation header, now copy subsequent lines
foundHudReadyPulseEnd = 1
hudReadyPulseEnd = append(hudReadyPulseEnd, line)
if strings.Contains(line, "}") { // Stop copying once a close brace is copies
foundHudReadyPulseEnd = 2
fmt.Println("Found custom HudReadyPulseEnd animation, using that")
}
break nextLine
}
}
// If all required animations are found
if foundHintMessageHide == 2 && foundHudTournamentSetupPanelOpen == 2 && foundHudTournamentSetupPanelClose == 2 && foundHudReadyPulseEnd == 2 {
return hintMessageHide, hudTournamentSetupPanelOpen, hudTournamentSetupPanelClose, hudReadyPulseEnd
}
}
input.Close()
}
// If no custom HintMessageHide animation is found, use default code
if foundHintMessageHide == 0 {
hintMessageHide = append(hintMessageHide, "event HintMessageHide")
hintMessageHide = append(hintMessageHide, "{")
hintMessageHide = append(hintMessageHide, "\tAnimate HudHintDisplay\tFgColor\t\"255 220 0 0\"\tLinear\t0.0\t0.2")
hintMessageHide = append(hintMessageHide, "\tAnimate HudHintDisplay\tHintSize\t\"0\"\tDeaccel 0.2\t0.3")
hintMessageHide = append(hintMessageHide, "}")
fmt.Println("Did not find custom HintMessageHide animation, using default")
} else if foundHintMessageHide == 1 {
fmt.Println("Error: Found HintMessageHide animation header, but did not close")
pressToExit()
}
// If no custom HudTournamentSetupPanelOpen animation is found, use default code
if foundHudTournamentSetupPanelOpen == 0 {
hudTournamentSetupPanelOpen = append(hudTournamentSetupPanelOpen, "event HudTournamentSetupPanelOpen")
hudTournamentSetupPanelOpen = append(hudTournamentSetupPanelOpen, "{")
hudTournamentSetupPanelOpen = append(hudTournamentSetupPanelOpen, "\tAnimate HudTournamentSetupt\tPosition\t\"c-90 -70\"\tLinear 0.0 0.001")
hudTournamentSetupPanelOpen = append(hudTournamentSetupPanelOpen, "\tAnimate HudTournamentSetup\tPosition\t\"c-90 70\"\tSpline 0.001 0.2")
hudTournamentSetupPanelOpen = append(hudTournamentSetupPanelOpen, "}")
fmt.Println("Did not find custom HudTournamentSetupPanelOpen animation, using default")
} else if foundHudTournamentSetupPanelOpen == 1 {
fmt.Println("Error: Found HudTournamentSetupPanelOpen animation header, but did not close")
pressToExit()
}
// If no custom HudTournamentSetupPanelClose animation is found, use default code
if foundHudTournamentSetupPanelClose == 0 {
hudTournamentSetupPanelClose = append(hudTournamentSetupPanelClose, "event HudTournamentSetupPanelClose")
hudTournamentSetupPanelClose = append(hudTournamentSetupPanelClose, "{")
hudTournamentSetupPanelClose = append(hudTournamentSetupPanelClose, "\tAnimate HudTournamentSetup\tPosition\t\"c-90 70\"\tLinear 0.0 0.001")
hudTournamentSetupPanelClose = append(hudTournamentSetupPanelClose, "\tAnimate HudTournamentSetup\tPosition\t\"c-90 -70\"\tSpline 0.001 0.2")
hudTournamentSetupPanelClose = append(hudTournamentSetupPanelClose, "}")
fmt.Println("Did not find custom HudTournamentSetupPanelClose animation, using default")
} else if foundHudTournamentSetupPanelClose == 1 {
fmt.Println("Error: Found HudTournamentSetupPanelClose animation header, but did not close")
pressToExit()
}
// If no custom HudReadyPulseEnd animation is found, use default code
if foundHudReadyPulseEnd == 0 {
hudReadyPulseEnd = append(hudReadyPulseEnd, "event HudReadyPulseEnd")
hudReadyPulseEnd = append(hudReadyPulseEnd, "{")
hudReadyPulseEnd = append(hudReadyPulseEnd, "\tAnimate TournamentInstructionsLabel\tFgColor\t\"TanLight\"\tLinear 0.0 0.1")
hudReadyPulseEnd = append(hudReadyPulseEnd, "\tStopEvent HudReadyPulse\t\t0.0")
hudReadyPulseEnd = append(hudReadyPulseEnd, "\tStopEvent HudReadyPulseLoop\t0.0")
hudReadyPulseEnd = append(hudReadyPulseEnd, "}")
fmt.Println("Did not find custom HudReadyPulseEnd animation, using default")
} else if foundHudReadyPulseEnd == 1 {
fmt.Println("Error: Found HudReadyPulseEnd animation header, but did not close")
pressToExit()
}
return hintMessageHide, hudTournamentSetupPanelOpen, hudTournamentSetupPanelClose, hudReadyPulseEnd
}
func insertPeachRecAnimations(hintMessageHide []string, hudTournamentSetupPanelOpen []string, hudTournamentSetupPanelClose []string, hudReadyPulseEnd []string) []string {
var peachRecAnimations []string
// Insert animations for HintMessageHide
for a, line := range hintMessageHide {
peachRecAnimations = append(peachRecAnimations, line)
// Add PeachREC line just before closing
if a == len(hintMessageHide)-2 {
peachRecAnimations = append(peachRecAnimations, "\n\tRunEventChild MainMenuOverride PeachRecSpawn 0.0")
}
}
// Insert animations for HudTournamentSetupPanelOpen
for a, line := range hudTournamentSetupPanelOpen {
peachRecAnimations = append(peachRecAnimations, line)
// Add PeachREC line just before closing
if a == len(hudTournamentSetupPanelOpen)-2 {
peachRecAnimations = append(peachRecAnimations, "\n\tRunEventChild MainMenuOverride PeachRecOpen 0.0")
}
}
// Insert animations for HudTournamentSetupPanelClose
for a, line := range hudTournamentSetupPanelClose {
peachRecAnimations = append(peachRecAnimations, line)
// Add PeachREC line just before closing
if a == len(hudTournamentSetupPanelClose)-2 {
peachRecAnimations = append(peachRecAnimations, "\n\tRunEventChild MainMenuOverride PeachRecClose 0.0")
}
}
// Insert animations for HudReadyPulseEnd
for a, line := range hudReadyPulseEnd {
peachRecAnimations = append(peachRecAnimations, line)
// Add PeachREC line just before closing
if a == len(hudReadyPulseEnd)-2 {
peachRecAnimations = append(peachRecAnimations, "\n\tRunEventChild MainMenuOverride PeachRecMvM 0.0 //Must run 3 times")
peachRecAnimations = append(peachRecAnimations, "\tRunEventChild MainMenuOverride PeachRecMvM 0.0")
peachRecAnimations = append(peachRecAnimations, "\tRunEventChild MainMenuOverride PeachRecMvM 0.0")
}
}
// Add custom PeachREC animation events
peachRecAnimations = append(peachRecAnimations, "event PeachRecSpawn")
peachRecAnimations = append(peachRecAnimations, "{")
peachRecAnimations = append(peachRecAnimations, "\tFireCommand 0.0 \"engine peachrec\"")
peachRecAnimations = append(peachRecAnimations, "}")
peachRecAnimations = append(peachRecAnimations, "event PeachRecOpen")
peachRecAnimations = append(peachRecAnimations, "{")
peachRecAnimations = append(peachRecAnimations, "\tFireCommand 0.001 \"engine pr_open\"")
peachRecAnimations = append(peachRecAnimations, "}")
peachRecAnimations = append(peachRecAnimations, "event PeachRecClose")
peachRecAnimations = append(peachRecAnimations, "{")
peachRecAnimations = append(peachRecAnimations, "\tFireCommand 0.0 \"engine pr_close\"")
peachRecAnimations = append(peachRecAnimations, "}")
peachRecAnimations = append(peachRecAnimations, "event PeachRecMvM")
peachRecAnimations = append(peachRecAnimations, "{")
peachRecAnimations = append(peachRecAnimations, "\tFireCommand 0.0 \"engine pr_mvm\"")
peachRecAnimations = append(peachRecAnimations, "}")
return peachRecAnimations
}