-
Notifications
You must be signed in to change notification settings - Fork 0
/
update_traj.gradle
55 lines (46 loc) · 1.6 KB
/
update_traj.gradle
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
// This script will update the markers in the .traj files in the src/main/deploy/choreo directory,
// it will take any toplevel named commands in the current event markers and clone themo over to events
// with the same name and timestamp
// make a gradle task to run this script
task updateTrajectories() {
doLast {
def deploy_directory = file('src/main/deploy/choreo')
println "Updating markers in $deploy_directory"
def slurper = new groovy.json.JsonSlurper()
deploy_directory.eachFile { file ->
println " Updating $file"
if (file.isFile() && file.name.endsWith('.traj')) {
def data = slurper.parse(file)
data['name'] = file.name - '.traj'
if (data.containsKey('eventMarkers')) {
data['events'] = makeNewMarkers(data['eventMarkers'])
} else {
data['events'] = []
}
file.text = new groovy.json.JsonBuilder(data).toPrettyString()
}
}
}
}
def makeNewMarkers(oldMarkers) {
def newMarkers = []
oldMarkers.each { marker ->
if (!marker.containsKey('command')) {
return
}
def command = marker['command']
if (!command.containsKey('type')) {
return
}
if (command['type'] != 'named') {
return
}
def newMarker = [
timestamp: marker['timestamp'],
event: command['data']['name']
]
newMarkers << newMarker
}
return newMarkers
}
build.dependsOn updateTrajectories