Skip to content

Commit 31b19c2

Browse files
committed
MM conversions
1 parent 4263af0 commit 31b19c2

1 file changed

Lines changed: 24 additions & 3 deletions

File tree

src/pages/index.tsx

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ from pybricks.parameters import Port
1818
motor = Motor(Port.A)
1919
motor.run_time(100, 2000)
2020
`
21-
const motor_options = ["A", "B", "C", "D"]
2221
const game_board_width = 2362.2 // mm
2322
const game_board_height = 1143.0 // mm
2423

@@ -148,15 +147,33 @@ export default function App() {
148147
const [run_creator_open, SetRunCreatorOpen] = useState(false)
149148
const [splan_creator_open, SetSplanCreatorOpen] = useState(false)
150149

151-
useEffect(() => {
150+
function UpdateImgDimensions () {
152151
if (img_size_ref.current) {
153152
// @ts-ignore | Fix getBoundingClient due to initial 'null' value
154153
const { width, height } = img_size_ref.current.getBoundingClientRect();
155154
SetImageDimensions({ width, height });
156155
console.log(img_dimensions.width, img_dimensions.height);
157156
}
157+
}
158+
159+
useEffect(() => {
160+
UpdateImgDimensions();
158161
}, [pysplan_handler]);
159162

163+
function RunMM(run: Run) {
164+
if (img_dimensions.width === 0 || img_dimensions.height === 0) UpdateImgDimensions();
165+
166+
const convertedPoints = run.points.map((point) => {
167+
return new Point((point.x / img_dimensions.width) * game_board_width, (point.y / img_dimensions.height) * game_board_height);
168+
});
169+
170+
const convertedActions = run.actions.map((action) => {
171+
return new Action(new Point((action.point.x / img_dimensions.width) * game_board_width, (action.point.y / img_dimensions.height) * game_board_height), action.function, action.args);
172+
});
173+
174+
return new Run(run.name, convertedPoints, convertedActions);
175+
}
176+
160177
const HandleLoadSplan = () => {
161178
const input = document.createElement('input');
162179
input.type = 'file';
@@ -331,8 +348,12 @@ export default function App() {
331348
const github_url = "https://raw.githubusercontent.com/PySplanner/PySplanner/refs/heads/main/pysplanner.py"
332349
const response = await fetch(github_url);
333350
let code = await response.text();
334-
351+
352+
pysplan_handler.runs.forEach((run) => {
353+
return RunMM(run);
354+
})
335355
pysplan_handler.hub_type = hub;
356+
336357
code = code.replace(`"{INSERT_PATH_PLANNER_DATA}"`, JSON.stringify(pysplan_handler));
337358

338359
const blob = new Blob([code], { type: "text/plain" });

0 commit comments

Comments
 (0)