animation frames to string; sprite to string
This commit is contained in:
parent
6d8f8fa9b4
commit
7f6fa9df82
39
src/main.rs
39
src/main.rs
|
@ -172,6 +172,21 @@ fn test_image_to_string() {
|
||||||
assert_eq!(output, expected);
|
assert_eq!(output, expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn animation_frames_to_string(animation_frames: Vec<Image>) -> String {
|
||||||
|
let mut string = String::new();
|
||||||
|
let last_frame = animation_frames.len() - 1;
|
||||||
|
|
||||||
|
for (i, frame) in animation_frames.into_iter().enumerate() {
|
||||||
|
string.push_str(&image_to_string(frame));
|
||||||
|
|
||||||
|
if i < last_frame {
|
||||||
|
string.push_str(&"\n>\n".to_string());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
string
|
||||||
|
}
|
||||||
|
|
||||||
fn tile_from_string(string: String) -> Tile {
|
fn tile_from_string(string: String) -> Tile {
|
||||||
let mut lines: Vec<&str> = string.split("\n").collect();
|
let mut lines: Vec<&str> = string.split("\n").collect();
|
||||||
|
|
||||||
|
@ -223,21 +238,10 @@ fn test_tile_from_string() {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn tile_to_string(tile: Tile) -> String {
|
fn tile_to_string(tile: Tile) -> String {
|
||||||
let mut animation_frames = String::new();
|
|
||||||
let last_frame = tile.animation_frames.len() - 1;
|
|
||||||
|
|
||||||
for (i, frame) in tile.animation_frames.into_iter().enumerate() {
|
|
||||||
animation_frames.push_str(&image_to_string(frame));
|
|
||||||
|
|
||||||
if i < last_frame {
|
|
||||||
animation_frames.push_str(&"\n>\n".to_string());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
format!(
|
format!(
|
||||||
"TIL {}\n{}{}{}",
|
"TIL {}\n{}{}{}",
|
||||||
tile.id,
|
tile.id,
|
||||||
animation_frames,
|
animation_frames_to_string(tile.animation_frames),
|
||||||
if tile.name.is_some() {format!("\nNAME {}", tile.name.unwrap())} else {"".to_string()},
|
if tile.name.is_some() {format!("\nNAME {}", tile.name.unwrap())} else {"".to_string()},
|
||||||
if tile.wall {"\nWAL true"} else {""}
|
if tile.wall {"\nWAL true"} else {""}
|
||||||
)
|
)
|
||||||
|
@ -464,6 +468,17 @@ fn test_sprite_from_string() {
|
||||||
assert_eq!(output, expected);
|
assert_eq!(output, expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn sprite_to_string(sprite: Sprite) -> String {
|
||||||
|
format!(
|
||||||
|
"SPR {}\n{}\n{}{}\nPOS {}",
|
||||||
|
sprite.id,
|
||||||
|
animation_frames_to_string(sprite.animation_frames),
|
||||||
|
if sprite.name.is_some() {format!("NAME {}", sprite.name.unwrap())} else {"".to_string()},
|
||||||
|
if sprite.dialogue.is_some() {format!("DLG {}", sprite.dialogue.unwrap())} else {"".to_string()},
|
||||||
|
position_to_string(sprite.position),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
// fn game_from_string(game: String ) -> Game {
|
// fn game_from_string(game: String ) -> Game {
|
||||||
// // probably needs to split the game data into different segments starting from the end
|
// // probably needs to split the game data into different segments starting from the end
|
||||||
// // e.g. VAR... then END... then DLG...
|
// // e.g. VAR... then END... then DLG...
|
||||||
|
|
Loading…
Reference in New Issue