-
Notifications
You must be signed in to change notification settings - Fork 51
/
Copy pathupdate_field_dimensions.py
85 lines (67 loc) · 2.52 KB
/
update_field_dimensions.py
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
#!/usr/bin/env python3
"""
A utility script to update the field dimensions in multiple files.
simply run `python update_field_dimensions.py <length_meters> <width_meters>` to update the dimensions in the files.
"""
from dataclasses import dataclass
from pathlib import Path
from typing import Callable
@dataclass(frozen=True, slots=True)
class Location:
relative_path: Path
# length, width
template: Callable[[float, float], str]
LOCATIONS: list[Location] = [
# Choreo GUI
Location(
relative_path=Path("src/components/field/svg/fields/FieldDimensions.tsx"),
template=lambda length, width: f"""// Auto-generated by update_field_dimensions.py
export const FIELD_LENGTH = {length};
export const FIELD_WIDTH = {width};""",
),
# Java ChoreoLib
Location(
relative_path=Path("choreolib/src/main/java/choreo/util/FieldDimensions.java"),
template=lambda length, width: f"""// Copyright (c) Choreo contributors
// Auto-generated by update_field_dimensions.py
package choreo.util;
class FieldDimensions {{
static final double FIELD_LENGTH = {length};
static final double FIELD_WIDTH = {width};
}}""",
),
# Python ChoreoLib
Location(
relative_path=Path("choreolib/py/choreo/util/field_dimensions.py"),
template=lambda length, width: f"""# Auto-generated by update_field_dimensions.py
FIELD_LENGTH = {length}
FIELD_WIDTH = {width}""",
),
# C++ ChoreoLib
Location(
relative_path=Path(
"choreolib/src/main/native/include/choreo/util/FieldDimensions.h"
),
template=lambda length, width: f"""// Copyright (c) Choreo contributors
// Auto-generated by update_field_dimensions.py
#pragma once
#include <units/length.h>
namespace choreo::util {{
static constexpr units::meter_t fieldLength = {length}_m;
static constexpr units::meter_t fieldWidth = {width}_m;
}} // namespace choreo::util""",
),
]
def update_version(length: float, width: float) -> None:
for location in LOCATIONS:
file_path = Path(__file__).parent / location.relative_path
with open(file_path, "w") as f:
f.write(location.template(length, width))
f.write("\n")
if __name__ == "__main__":
import argparse
parser = argparse.ArgumentParser(description="Update version in files")
parser.add_argument("length_m", type=float, help="Field length in meters")
parser.add_argument("width_m", type=float, help="Field width in meters")
args = parser.parse_args()
update_version(args.length_m, args.width_m)