pub fn load_svg_map<T: StyleStrategy>(
    mut commands: Commands,
    mut materials: ResMut<Assets<ColorMaterial>>,
    mut meshes: ResMut<Assets<Mesh>>,
    svg_map: &str,
    strategy: T,
) {
    let (x_max, y_max) = max_coords(svg_map);
    let (x_max, y_max) = (x_max as f32, y_max as f32);

    for StyleSegment { style, traces } in tokenize_svg(svg_map).unwrap().iter() {
        let color_handle = materials.add(strategy.color_decider(style).into());
        // TODO: this transformation are a joke...
        let builder = lyon::path::Path::builder().with_svg().transformed(
            Transform2D::translation(x_max + x_max / 2f32, y_max / 2f32) // translate to bevy coordinates
                .pre_rotate(euclid::Angle::radians(std::f32::consts::PI / 2.)) // rotate 180º for some reason
                .then(&Transform2D::new(0f32, 1f32, 1f32, 0f32, 0f32, 0f32)) // mirror for some reason
                .then_translate(euclid::Vector2D::new(0., -y_max)), // translate again to bevy coordinates
        );
        let path = build_path(builder, traces).unwrap();
        if matches!(style.stroke(), Some(_)) {
            strategy.component_decider(
                &style,
                commands.spawn().insert_bundle(lyon_utils::stroke(
                    path.clone(),
                    color_handle.clone(),
                    &mut meshes,
                    Vec3::new(-x_max, -y_max, 0.0),
                    &StrokeOptions::default()
                        .with_line_width(strategy.width_decider(style))
                        .with_line_cap(strategy.linecap_decider(style))
                        .with_line_join(strategy.linejoin_decider(style)),
                )),
            )
        }
        if matches!(style.fill(), Some(_)) {
            strategy.component_decider(
                &style,
                commands.spawn().insert_bundle(lyon_utils::fill(
                    path,
                    color_handle,
                    &mut meshes,
                    Vec3::new(-x_max, -y_max, 0.0),
                    &FillOptions::default(),
                )),
            )
        }
    }
}
/// For each of the paths in a SVG file, apply a StyleStrategy to translate them into entities with
/// functionality added to them, dependent of the SVG properties of the path (stroke, fill...)
For each of the paths in a SVG file, apply a StyleStrategy to translate them into entities with
functionality added to them, dependent of the SVG properties of the path (stroke, fill...)
For each of the paths in a SVG file apply a StyleStrategy to translate them into entities with functionality added to them dependent of the SVG properties of the path ( stroke fill ... )
pub fn load_svg_map<T: StyleStrategy>(
    mut commands: Commands,
    mut materials: ResMut<Assets<ColorMaterial>>,
    mut meshes: ResMut<Assets<Mesh>>,
    svg_map: &str,
    strategy: T,
) {
    let (x_max, y_max) = max_coords(svg_map);
    let (x_max, y_max) = (x_max as f32, y_max as f32);
    for StyleSegment { style, traces } in tokenize_svg(svg_map).unwrap().iter() {
        let color_handle = materials.add(strategy.color_decider(style).into());
        // TODO: this transformation are a joke...
        let builder = lyon::path::Path::builder().with_svg().transformed(
            Transform2D::translation(x_max + x_max / 2f32, y_max / 2f32) // translate to bevy coordinates
                .pre_rotate(euclid::Angle::radians(std::f32::consts::PI / 2.)) // rotate 180º for some reason
                .then(&Transform2D::new(0f32, 1f32, 1f32, 0f32, 0f32, 0f32)) // mirror for some reason
                .then_translate(euclid::Vector2D::new(0., -y_max)), // translate again to bevy coordinates
        );
        let path = build_path(builder, traces).unwrap();
        if matches!(style.stroke(), Some(_)) {
            strategy.component_decider(
                &style,
                commands.spawn().insert_bundle(lyon_utils::stroke(
                    path.clone(),
                    color_handle.clone(),
                    &mut meshes,
                    Vec3::new(-x_max, -y_max, 0.0),
                    &StrokeOptions::default()
                        .with_line_width(strategy.width_decider(style))
                        .with_line_cap(strategy.linecap_decider(style))
                        .with_line_join(strategy.linejoin_decider(style)),
                )),
            )
        }
        if matches!(style.fill(), Some(_)) {
            strategy.component_decider(
                &style,
                commands.spawn().insert_bundle(lyon_utils::fill(
                    path,
                    color_handle,
                    &mut meshes,
                    Vec3::new(-x_max, -y_max, 0.0),
                    &FillOptions::default(),
                )),
            )
        }
    }
}
pub fn load_svg_map < T : StyleStrategy > ( mut commands : Commands , mut materials : ResMut < Assets < ColorMaterial > > , mut meshes : ResMut < Assets < Mesh > > , svg_map : & str , strategy : T , ) { let ( x_max , y_max ) = max_coords ( svg_map ) ; let ( x_max , y_max ) = ( x_max as f32 , y_max as f32 ) ; for StyleSegment { style , traces } in tokenize_svg ( svg_map ) . unwrap ( ) . iter ( ) { let color_handle = materials . add ( strategy . color_decider ( style ) . into ( ) ) ; // TODO: this transformation are a joke... let builder = lyon :: path :: Path :: builder ( ) . with_svg ( ) . transformed ( Transform2D :: translation ( x_max + x_max / 2f32 , y_max / 2f32 ) // translate to bevy coordinates . pre_rotate ( euclid :: Angle :: radians ( std :: f32 :: consts :: PI / 2. ) ) // rotate 180º for some reason . then ( & Transform2D :: new ( 0f32 , 1f32 , 1f32 , 0f32 , 0f32 , 0f32 ) ) // mirror for some reason . then_translate ( euclid :: Vector2D :: new ( 0. , - y_max ) ) , // translate again to bevy coordinates ) ; let path = build_path ( builder , traces ) . unwrap ( ) ; if matches ! ( style stroke ( ) Some ( ) ) { strategy . component_decider ( & style , commands . spawn ( ) . insert_bundle ( lyon_utils :: stroke ( path . clone ( ) , color_handle . clone ( ) , & mut meshes , Vec3 :: new ( - x_max , - y_max , 0.0 ) , & StrokeOptions :: default ( ) . with_line_width ( strategy . width_decider ( style ) ) . with_line_cap ( strategy . linecap_decider ( style ) ) . with_line_join ( strategy . linejoin_decider ( style ) ) , ) ) , ) } if matches ! ( style fill ( ) Some ( ) ) { strategy . component_decider ( & style , commands . spawn ( ) . insert_bundle ( lyon_utils :: fill ( path , color_handle , & mut meshes , Vec3 :: new ( - x_max , - y_max , 0.0 ) , & FillOptions :: default ( ) , ) ) , ) } } }
For each of the paths in a SVG file, apply a StyleStrategy to translate them into entities with
functionality added to them, dependent of the SVG properties of the path (stroke, fill...)
For each of the paths in a SVG file apply a StyleStrategy to translate them into entities with functionality added to them dependent of the SVG properties of the path ( stroke fill ... )
commands
Commands
materials
ResMut<Assets<ColorMaterial>>
meshes
ResMut<Assets<Mesh>>
svg_map
&str
strategy
T
commands
Commands
materials
ResMut<Assets<ColorMaterial>>
meshes
ResMut<Assets<Mesh>>
svg_map
&str
strategy
T