Skip to content

Commit 7e91496

Browse files
committed
removed document file generation
1 parent 2dc8c3a commit 7e91496

4 files changed

Lines changed: 12 additions & 89 deletions

File tree

src/codegen/genConstsFile.ts

Lines changed: 0 additions & 67 deletions
This file was deleted.

src/codegen/genVarsFile.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,13 @@ import { Project } from "../document/2025/DocumentTypes";
22
import { round, writeConst } from "./internals";
33

44
export function genVarsFile(project: Project, packageName: string): string {
5-
const expressions = project.variables.expressions;
6-
const poses = project.variables.poses;
75
const out: string[] = [];
8-
out.push(`package ${packageName};\n`);
6+
out.push(`package ${packageName};`);
97
out.push(`
108
import edu.wpi.first.math.geometry.Pose2d;
119
import edu.wpi.first.math.geometry.Rotation2d;
1210
import edu.wpi.first.units.measure.*;
11+
1312
import static edu.wpi.first.units.Units.*;
1413
1514
/**
@@ -18,22 +17,20 @@ import static edu.wpi.first.units.Units.*;
1817
* in the choreo GUI.
1918
*/
2019
public final class ChoreoVars {`);
21-
for (const varName in project.variables.expressions) {
22-
const data = expressions[varName];
20+
for (const [varName, data] of Object.entries(project.variables.expressions)) {
2321
out.push(writeConst(data.var, varName, data.dimension));
2422
}
2523
out.push("");
2624
out.push(" public static final class Poses {");
27-
for (const poseName in poses) {
28-
const pose = poses[poseName];
25+
for (const [varName, pose] of Object.entries(project.variables.poses)) {
2926
const heading =
3027
Math.abs(pose.heading.val) < 1e-5
3128
? "Rotation2d.kZero"
3229
: `Rotation2d.fromRadians(${round(pose.heading.val, 3)})`;
3330
const x = round(pose.x.val, 3);
3431
const y = round(pose.y.val, 3);
3532
out.push(
36-
` public static final Pose2d ${poseName} = new Pose2d(${x}, ${y}, ${heading});`
33+
` public static final Pose2d ${varName} = new Pose2d(${x}, ${y}, ${heading});`
3734
);
3835
}
3936
out.push("");

src/codegen/internals.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ export function writeConst(
4646
variableName: string,
4747
dimension: DimensionName
4848
): string {
49+
variableName = variableName.replace(/\b(\w)/g, (char) => char.toLowerCase());
4950
const unitData = unitDataFrom(dimension);
5051
let val = typeof expr === "number" ? expr : expr.val;
5152
val = round(val, dimension === "MoI" ? 5 : 3);
@@ -55,10 +56,6 @@ export function writeConst(
5556
return ` public static final ${unitData.type} ${variableName} = ${unitData.baseUnit}.of(${val});`;
5657
}
5758

58-
export function writeVar(variable: Variable, name: string): string {
59-
return writeConst(variable.var, name, variable.dimension);
60-
}
61-
6259
export function round(val: number, digits: number) {
6360
const roundingFactor = Math.pow(10, digits);
6461
return Math.round(val * roundingFactor) / roundingFactor;

src/document/DocumentManager.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ import { SavingState, UIStateStore } from "./UIStateStore";
6464
import { findUUIDIndex } from "./path/utils";
6565
import { ChoreoError, Commands } from "./tauriCommands";
6666
import { tracing } from "./tauriTracing";
67-
import { genConstsFile } from "../codegen/genConstsFile";
6867
import { genVarsFile } from "../codegen/genVarsFile";
6968

7069
export type OpenFilePayload = {
@@ -716,8 +715,7 @@ export async function newProject(promptForCodegen: boolean = true) {
716715
(Do this if you're switching to a new codebase)
717716
`
718717
: `
719-
Choreo can now output Java files
720-
containing variables and constants defined in the GUI.
718+
Choreo can generate a java file with variables defined in the GUI.
721719
Select a folder to enable this feature?
722720
`;
723721
if (await ask(msg, { title: "Choreo", kind: "warning" })) {
@@ -808,16 +806,13 @@ export async function saveProject() {
808806
);
809807
let tasks = [Commands.writeProject(data)];
810808
if (javaRoot && packageName) {
811-
const constsFile = genConstsFile(data, packageName);
812-
const varsFile = genVarsFile(data, packageName);
813809
tasks = [
814810
...tasks,
815811
Commands.writeRawFile(
816-
constsFile,
817-
javaRoot + packageName + "/ChoreoConsts.java"
818-
),
819-
Commands.writeRawFile(
820-
varsFile,
812+
genVarsFile(
813+
data,
814+
packageName.replaceAll("/", ".").replaceAll("\\", ".")
815+
),
821816
javaRoot + packageName + "/ChoreoVars.java"
822817
)
823818
];
@@ -851,6 +846,7 @@ export async function codeGenDialog() {
851846
}
852847
localStorage.setItem(LocalStorageKeys.JAVA_ROOT, splitPath[0] + "/java/");
853848
localStorage.setItem(LocalStorageKeys.CODE_GEN_PACKAGE, splitPath[1]);
849+
await saveProject();
854850
}
855851

856852
export async function disableCodegen() {

0 commit comments

Comments
 (0)