what part of this task is blocking you?
path2d curve is fairly easy to fill with new points using add_points()
, you can add a new point each time a new "piece" of track is laid down.
and for the "magnetized" part: for each piece of the track you could specify some points around them to use as snapping point, when a new piece of track is close enough to one of this points, you could move it using a Tween (and you could link the tween completed signal to the add_points()
)