pub fn from_string(layout: String, path_to_img: String) -> Result<Self, EngineError> {
        // Deserialize the layout
        let mut sheet = ron::from_str::<SpriteSheet>(&layout)?;
        // Store the img path
        sheet.path = path_to_img;
        if sheet.sheet_width / sheet.tile_width > 255 {
            return Err(EngineError::SheetSizeError("Maximum tiles per row is 255".into()));
        }
        Ok(sheet)   
    }
/// Takes a spritesheet layout in Rusty Object Notation, as well as a path to 
/// the image that the layout describes.
/// 
/// The path to the image is not tested and will result in a read error on shader
/// compilation if an invalid path is used.
///
/// Note: the max sheet resolution is 255 tiles x 255 tiles
///
/// # Example 
/// ```
/// # use stoneng::sprite::*;
/// let layout = r#"
/// SpriteSheet ( 
///     sheet_width:    256,
///     tile_width:     32,
///
///     // Note that sprites is a map (curly braces, string keys)
///     sprites: {
///         // Each sprite is a struct, root is required, other params
///         // use defaults. Additional parameters can be found under
///         // the struct SpriteSchema
///         "grass": (
///             root: 0,
///         ),
///         "arch": (
///             root: 9,
///             dimensions: (2,2),
///         ),
///         "water": (
///             root: 3,
///             // Note that animations is a map
///             animations: {
///                 // Each animation is the struct AnimationSchema
///                 "idle": (
///                     root:       3,
///                     frames:     3,
///                     fps:        5,
///                     loops:    true,
///                     reverses:   true,
///                 ),
///             }
///         )
///     }
/// )
/// "#;
/// let sheet = SpriteSheet::from_string(
///                 layout.into(), 
///                 "path/to/img.png".into()
///             ).unwrap(); 
///
/// // Check the sheet contains valid entries
/// assert_eq!(sheet.sheet_width, 256);
/// assert_eq!(sheet.sprites["arch"].root, 9);
/// assert!(sheet.sprites["water"].animations.contains_key("idle"));
/// ```
Takes a spritesheet layout in Rusty Object Notation, as well as a path to
the image that the layout describes.

The path to the image is not tested and will result in a read error on shader
compilation if an invalid path is used.

the max sheet resolution is 255 tiles x 255 tiles
Takes a spritesheet layout in Rusty Object Notation as well as a path to the image that the layout describes . The path to the image is not tested and will result in a read error on shader compilation if an invalid path is used . the max sheet resolution is 255 tiles x 255 tiles
pub fn from_string(layout: String, path_to_img: String) -> Result<Self, EngineError> {
        // Deserialize the layout
        let mut sheet = ron::from_str::<SpriteSheet>(&layout)?;
        // Store the img path
        sheet.path = path_to_img;
        if sheet.sheet_width / sheet.tile_width > 255 {
            return Err(EngineError::SheetSizeError("Maximum tiles per row is 255".into()));
        }
        Ok(sheet)   
    }
pub fn from_string ( layout : String , path_to_img : String ) -> Result < Self , EngineError > { // Deserialize the layout let mut sheet = ron :: from_str :: < SpriteSheet > ( & layout ) ? ; // Store the img path sheet . path = path_to_img ; if sheet . sheet_width / sheet . tile_width > 255 { return Err ( EngineError :: SheetSizeError ( " " . into ( ) ) ) ; } Ok ( sheet ) }
Takes a spritesheet layout in Rusty Object Notation, as well as a path to
the image that the layout describes.
Takes a spritesheet layout in Rusty Object Notation as well as a path to the image that the layout describes .
layout
String
path_to_img
String
layout
String
path_to_img
String
example 
None
use stoneng::sprite::*;
let layout = r#"
SpriteSheet (
sheet_width:    256,
tile_width:     32.

Note that sprites is a map (curly braces, string keys)
sprites: {
Each sprite is a struct, root is required, other params
use defaults. Additional parameters can be found under
the struct SpriteSchema
"grass": (
root: 0,
),
"arch": (
root: 9,
dimensions: (2,2),
),
"water": (
root: 3,
Note that animations is a map
animations: {
Each animation is the struct AnimationSchema
"idle": (
root:       3,
frames:     3,
fps:        5,
loops:    true,
reverses:   true,
),
}
)
}
)
"#;
let sheet = SpriteSheet::from_string(
layout.into(),
"path/to/img.png".into()
).unwrap().

Check the sheet contains valid entries
assert_eq!(sheet.sheet_width, 256);
assert_eq!(sheet.sprites["arch"].root, 9);
assert!(sheet.sprites["water"].animations.contains_key("idle"));
```
let layout = r# " SpriteSheet ( sheet_width : 256 tile_width : 32 . Note that sprites is a map ( curly braces string keys ) sprites : { Each sprite is a struct root is required other params use defaults . Additional parameters can be found under the struct SpriteSchema " grass " : ( root : 0 ) " arch " : ( root : 9 dimensions : ( 2 2 ) ) " water " : ( root : 3 Note that animations is a map animations : { Each animation is the struct AnimationSchema " idle " : ( root : 3 frames : 3 fps : 5 loops : true reverses : true ) } ) } ) " # ; let sheet = SpriteSheet :: from_string ( layout . into () " path / to / img . png " . into () ) . unwrap () . Check the sheet contains valid entries assert_eq! ( sheet . sheet_width 256 ) ; assert_eq! ( sheet . sprites [ " arch " ] . root 9 ) ; assert! ( sheet . sprites [ " water " ] . animations . contains_key ( " idle " )) ; ` ` `