@@ -18,7 +18,6 @@ from pybricks.parameters import Port
1818motor = Motor(Port.A)
1919motor.run_time(100, 2000)
2020`
21- const motor_options = [ "A" , "B" , "C" , "D" ]
2221const game_board_width = 2362.2 // mm
2322const 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