-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmirror.pl
More file actions
80 lines (59 loc) · 1.46 KB
/
mirror.pl
File metadata and controls
80 lines (59 loc) · 1.46 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
use strict;
sub translatename
{
my $original = $_[0];
my $newname;
if ($original =~ m/Left(.*)/)
{
$newname = "Right$1";
}
elsif ($original =~ m/L(.*)/)
{
$newname = "R$1";
}
elsif ($original =~ m/Right(.*)/)
{
$newname = "Left$1";
}
elsif ($original =~ m/R(.*)/)
{
$newname = "L$1";
}
else
{
$newname = "Mirrored$original"
}
return $newname;
}
my $autoname = @ARGV[0];
my $dirname = "./src/main/deploy/pathplanner";
open (my $auto, "<", "$dirname/autos/$autoname.auto") or die $!;
my $text = do {local $/; <$auto> };
close $auto;
#print $text;
my @relevantpaths;
while ($text =~ /"pathName": "(.*)"/g)
{
push @relevantpaths, $1;
}
print join ", ", @relevantpaths;
print "\n";
my $newname = translatename $autoname;
$text =~ s/"pathName": "(.*)"/"\"pathName\": \"" . translatename $1 . "\""/ge;
print $newname;
open (my $newauto, ">", "$dirname/autos/$newname.auto") or die $!;
print $newauto $text;
foreach my $path (@relevantpaths)
{
open my $in, "<", "$dirname/paths/$path.path";
my $newpathname = translatename $path;
open my $out, ">", "$dirname/paths/$newpathname.path";
my $contents = do {local $/; <$in>};
close $in;
$contents =~ s/"y": (.*)/"\"y\": " . (8.069326 - $1)/ge;
$contents =~ s/"rotation": (.*)/"\"rotation\": " . (-$1)/ge;
$contents =~ s/"rotationDegrees": (.*)/"\"rotationDegrees\": " . (-$1)/ge;
$contents =~ s/"folder": "(.*)"/"\"folder\": \"" . translatename $1 . "\""/ge;
print $out $contents;
close $out;
}