@@ -68,13 +68,23 @@ class Point {
6868class Run {
6969 name : string ;
7070 points : Point [ ] ;
71+ spline_points : Point [ ] ;
7172 actions : Action [ ] ;
7273
73- constructor ( name : string , points : Point [ ] , actions : Action [ ] = [ ] ) {
74+ constructor ( name : string , points : Point [ ] , spline_points : Point [ ] = [ ] , actions : Action [ ] = [ ] ) {
7475 this . name = name ;
7576 this . points = points ;
77+ this . spline_points = spline_points ;
7678 this . actions = actions
7779 }
80+
81+ toJSON ( ) {
82+ return {
83+ name : this . name ,
84+ points : this . spline_points , // Replace placed points with spline points for navigation
85+ actions : this . actions
86+ }
87+ }
7888}
7989
8090class SplanContent {
@@ -167,11 +177,15 @@ export default function App() {
167177 return new Point ( ( point . x / img_dimensions . width ) * game_board_width , ( point . y / img_dimensions . height ) * game_board_height ) ;
168178 } ) ;
169179
180+ const convertedSplinePoints = run . spline_points . map ( ( point ) => {
181+ return new Point ( ( point . x / img_dimensions . width ) * game_board_width , ( point . y / img_dimensions . height ) * game_board_height ) ;
182+ } ) ;
183+
170184 const convertedActions = run . actions . map ( ( action ) => {
171185 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 ) ;
172186 } ) ;
173187
174- return new Run ( run . name , convertedPoints , convertedActions ) ;
188+ return new Run ( run . name , convertedPoints , convertedSplinePoints , convertedActions ) ;
175189 }
176190
177191 const HandleLoadSplan = ( ) => {
@@ -378,13 +392,11 @@ export default function App() {
378392 return
379393 }
380394
381- const new_run = new Run ( pysplan_handler . runs [ run_index ] . name , new_points , pysplan_handler . runs [ run_index ] . actions ) ;
395+ const new_spline = GetCurvePoints ( new_points . flatMap ( p => [ p . x , p . y ] ) ) . map ( p => new Point ( p . x , p . y ) )
396+ const new_run = new Run ( pysplan_handler . runs [ run_index ] . name , new_points , new_spline , pysplan_handler . runs [ run_index ] . actions ) ;
382397 SetPySplanHandler ( { ...pysplan_handler , runs : [ ...pysplan_handler . runs . slice ( 0 , run_index ) , new_run , ...pysplan_handler . runs . slice ( run_index + 1 ) ] } ) ;
383398 } ;
384399
385- const flat_points = pysplan_handler ?. runs [ run_index ] ?. points . flatMap ( p => [ p . x , p . y ] )
386- const spline_points = GetCurvePoints ( flat_points ?? [ ] ) ;
387-
388400 const GetSpikeServer = async ( ) => {
389401 toast . promise (
390402 async ( ) => { SetSpikeServer ( await connectToSpike ( ) ) } ,
@@ -416,8 +428,9 @@ export default function App() {
416428 < AccordionTrigger > Spike</ AccordionTrigger >
417429 < AccordionContent >
418430 < div className = "flex flex-col gap-2" >
419- < Button variant = "secondary" className = "w-full" onClick = { ( ) => GetSpikeServer ( ) } > Connect</ Button >
420- < Button variant = { spike_server ? "secondary" : "outline" } className = "w-full" onClick = { ( ) => { spike_server && sendCodeToSpike ( spike_server , sample_code ) } } > Download Code</ Button >
431+ { /* <Button variant="secondary" className="w-full" onClick = { () => GetSpikeServer() }>Connect</Button> */ }
432+ { /* <Button variant={spike_server ? "secondary" : "outline"} className="w-full" onClick = { () => { spike_server && sendCodeToSpike(spike_server, sample_code) } }>Download Code</Button> */ }
433+ < Button variant = "secondary" className = "w-full" onClick = { ( ) => GenerateCode ( "Spike" ) } > Generate Code</ Button >
421434 </ div >
422435 </ AccordionContent >
423436 </ AccordionItem >
@@ -490,7 +503,7 @@ export default function App() {
490503 { pysplan_handler . runs [ run_index ] . points . map ( ( p , idx ) => (
491504 < div key = { idx } className = "absolute bg-green-500 w-3 h-3 rounded-full" style = { { left : `${ p . x } px` , bottom : `${ p . y } px` } } />
492505 ) ) }
493- { spline_points . map ( ( p , idx ) => (
506+ { pysplan_handler . runs [ run_index ] . spline_points . map ( ( p , idx ) => (
494507 < div key = { idx } className = "absolute bg-green-400 w-2 h-2 rounded-full" style = { { left : `${ p . x } px` , bottom : `${ p . y } px` } } />
495508 ) ) }
496509 </ div >
0 commit comments