Skip to content

Commit 4263af0

Browse files
committed
}Add code generation under EV3
1 parent ec1bef1 commit 4263af0

1 file changed

Lines changed: 20 additions & 4 deletions

File tree

src/pages/index.tsx

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,13 @@ class Run {
8080

8181
class SplanContent {
8282
name: string;
83+
hub_type: "Spike" | "EV3" | null;
8384
drive_base: DriveBase;
8485
runs: Run[];
8586

8687
constructor(data: any) {
8788
this.name = data.name;
89+
this.hub_type = null
8890
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);
8991
this.runs = data.runs.map((run: any) => new Run(run.name, run.points.map((point: any) => new Point(point[0], point[1])), run.actions.map((action: any) => new Action(new Point(action.point[0], action.point[1]), action.function, action.args))));
9092
}
@@ -323,11 +325,23 @@ export default function App() {
323325
)
324326
}
325327

326-
const GenerateCode = async () => {
328+
const GenerateCode = async (hub: "EV3" | "Spike") => {
329+
if (!pysplan_handler) { toast.error("No Splan to generate code from", {duration: 5000}); return; }
330+
if (pysplan_handler.runs.length === 0) { toast.error("No runs in Splan to generate code from", {duration: 5000}); return; }
327331
const github_url = "https://raw.githubusercontent.com/PySplanner/PySplanner/refs/heads/main/pysplanner.py"
328332
const response = await fetch(github_url);
329-
const code = await response.text();
330-
// TODO: Add the stuff to the code
333+
let code = await response.text();
334+
335+
pysplan_handler.hub_type = hub;
336+
code = code.replace(`"{INSERT_PATH_PLANNER_DATA}"`, JSON.stringify(pysplan_handler));
337+
338+
const blob = new Blob([code], { type: "text/plain" });
339+
const url = URL.createObjectURL(blob);
340+
const link = document.createElement("a");
341+
link.href = url;
342+
link.download = `${pysplan_handler.name}.py`;
343+
link.click();
344+
URL.revokeObjectURL(url);
331345
}
332346

333347
const AddPoint = (e: React.MouseEvent) => {
@@ -389,7 +403,9 @@ export default function App() {
389403
<AccordionItem value="EV3">
390404
<AccordionTrigger>EV3</AccordionTrigger>
391405
<AccordionContent>
392-
EV3 is not yet supported.
406+
<div className="flex flex-col gap-2">
407+
<Button variant="secondary" className="w-full" onClick = { () => GenerateCode("EV3") }>Download Code</Button>
408+
</div>
393409
</AccordionContent>
394410
</AccordionItem>
395411
<AccordionItem value="Splans">

0 commit comments

Comments
 (0)