Skip to content

Commit 7d860a6

Browse files
committed
Add classes for paths
1 parent 7c5a38a commit 7d860a6

1 file changed

Lines changed: 72 additions & 0 deletions

File tree

src/pages/index.tsx

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,78 @@ motor = Motor(Port.A)
2121
motor.run_time(100, 2000)
2222
`
2323

24+
class DriveBase {
25+
left_motor: "A" | "B" | "C" | "D";
26+
right_motor: "A" | "B" | "C" | "D";
27+
wheel_diameter: number;
28+
axle_track: number;
29+
30+
constructor(left_motor: "A" | "B" | "C" | "D", right_motor: "A" | "B" | "C" | "D", wheel_diameter: number, axle_track: number) {
31+
if (left_motor === right_motor) {
32+
throw new Error("Left and right motors must be different");
33+
}
34+
35+
this.left_motor = left_motor;
36+
this.right_motor = right_motor;
37+
this.wheel_diameter = wheel_diameter;
38+
this.axle_track = axle_track;
39+
}
40+
}
41+
42+
class Action {
43+
function: string;
44+
args: any[];
45+
46+
constructor(function_name: string, args: any[] = []) {
47+
this.function = function_name;
48+
this.args = args;
49+
}
50+
}
51+
52+
class Point {
53+
x: number;
54+
y: number;
55+
actions: Action[];
56+
actions_are_blocking: boolean
57+
58+
constructor(x: number, y: number, actions: Action[] = [], actions_are_blocking: boolean = false) {
59+
this.x = x;
60+
this.y = y;
61+
this.actions = actions;
62+
this.actions_are_blocking = actions_are_blocking;
63+
}
64+
}
65+
66+
class PySplanContent {
67+
name: string;
68+
drive_base: DriveBase;
69+
runs: Point[][];
70+
71+
constructor(data: any) {
72+
this.name = data.name;
73+
this.drive_base = new DriveBase(data.drive_base.left_motor, data.drive_base.right_motor, data.drive_base.wheel_diameter, data.drive_base.axle_track);
74+
this.runs = data.runs;
75+
}
76+
77+
save_file() {
78+
const data = JSON.stringify(this);
79+
const blob = new Blob([data], { type: "application/json" });
80+
const url = URL.createObjectURL(blob);
81+
const link = document.createElement("a");
82+
link.href = url;
83+
link.download = "py_splan.json";
84+
link.click();
85+
URL.revokeObjectURL(url);
86+
}
87+
88+
async generate_code() {
89+
const github_url = "https://raw.githubusercontent.com/PySplanner/PySplanner/refs/heads/main/pysplanner.py"
90+
const response = await fetch(github_url);
91+
const code = await response.text();
92+
// TODO: Add the stuff to the code
93+
}
94+
}
95+
2496
export default function App() {
2597
const { theme } = useTheme()
2698
const mat_img = `./game_board_${theme ? theme : "dark"}.png`

0 commit comments

Comments
 (0)