dedupe animation frames handling
This commit is contained in:
parent
8d8515bb8a
commit
8bd323b8a0
|
@ -65,7 +65,7 @@ some more practical uses would be things like:
|
|||
* "unquote" function for dialogues, game title, anything else that supports """
|
||||
* add Bitsy HD and Bitsy 7.0 test data
|
||||
* fix variables/endings becoming "DLG DLG"?
|
||||
* dedupe "animation frames from string" functionality
|
||||
* replace Image with Vec<u8> or something. seems like a pointless abstraction
|
||||
|
||||
### tidy up
|
||||
|
||||
|
|
28
src/image.rs
28
src/image.rs
|
@ -45,13 +45,24 @@ impl ToString for Image {
|
|||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub(crate) fn animation_frames_from_string(string: String) -> Vec<Image> {
|
||||
print!("animation frames: \n{}", string);
|
||||
let frames: Vec<&str> = string.split(">").collect();
|
||||
|
||||
frames.iter().map(|&frame| Image::from(frame.to_string())).collect()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use crate::image::Image;
|
||||
use crate::image::{Image, animation_frames_from_string};
|
||||
use crate::mock;
|
||||
|
||||
#[test]
|
||||
fn test_image_from_string() {
|
||||
let output = Image::from(include_str!("test-resources/image").to_string());
|
||||
let output = Image::from(
|
||||
include_str!("test-resources/image").to_string()
|
||||
);
|
||||
|
||||
let expected = Image {
|
||||
pixels: vec![
|
||||
|
@ -71,8 +82,19 @@ mod test {
|
|||
|
||||
#[test]
|
||||
fn test_image_to_string() {
|
||||
let output = crate::mock::image::chequers_1().to_string();
|
||||
let output = mock::image::chequers_1().to_string();
|
||||
let expected = include_str!("test-resources/image-chequers-1").to_string();
|
||||
assert_eq!(output, expected);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_animation_frames_from_string() {
|
||||
let output = animation_frames_from_string(
|
||||
include_str!("test-resources/animation_frames").to_string()
|
||||
);
|
||||
|
||||
let expected = mock::image::animation_frames();
|
||||
|
||||
assert_eq!(output, expected);
|
||||
}
|
||||
}
|
||||
|
|
11
src/item.rs
11
src/item.rs
|
@ -1,4 +1,5 @@
|
|||
use crate::{from_base36, optional_data_line, AnimationFrames, Image, ToBase36};
|
||||
use crate::image::animation_frames_from_string;
|
||||
|
||||
#[derive(Debug, Eq, PartialEq)]
|
||||
pub struct Item {
|
||||
|
@ -51,13 +52,9 @@ impl From<String> for Item {
|
|||
}
|
||||
}
|
||||
|
||||
// todo dedupe
|
||||
let animation_frames = lines[1..].join("");
|
||||
let animation_frames: Vec<&str> = animation_frames.split(">").collect();
|
||||
let animation_frames: Vec<Image> = animation_frames
|
||||
.iter()
|
||||
.map(|&frame| Image::from(frame.to_string()))
|
||||
.collect();
|
||||
let animation_frames = animation_frames_from_string(
|
||||
lines[1..].join("\n")
|
||||
);
|
||||
|
||||
Item {
|
||||
id,
|
||||
|
|
54
src/mock.rs
54
src/mock.rs
|
@ -25,6 +25,60 @@ pub mod image {
|
|||
],
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn animation_frames() -> Vec<Image> {
|
||||
vec![
|
||||
Image {
|
||||
pixels: vec![
|
||||
1,0,0,1,1,0,0,1,
|
||||
0,0,1,1,0,0,1,1,
|
||||
0,1,1,0,0,1,1,0,
|
||||
1,1,0,0,1,1,0,0,
|
||||
1,0,0,1,1,0,0,1,
|
||||
0,0,1,1,0,0,1,1,
|
||||
0,1,1,0,0,1,1,0,
|
||||
1,1,0,0,1,1,0,0,
|
||||
]
|
||||
},
|
||||
Image {
|
||||
pixels: vec![
|
||||
1,1,0,0,1,1,0,0,
|
||||
1,0,0,1,1,0,0,1,
|
||||
0,0,1,1,0,0,1,1,
|
||||
0,1,1,0,0,1,1,0,
|
||||
1,1,0,0,1,1,0,0,
|
||||
1,0,0,1,1,0,0,1,
|
||||
0,0,1,1,0,0,1,1,
|
||||
0,1,1,0,0,1,1,0,
|
||||
]
|
||||
},
|
||||
Image {
|
||||
pixels: vec![
|
||||
0,1,1,0,0,1,1,0,
|
||||
1,1,0,0,1,1,0,0,
|
||||
1,0,0,1,1,0,0,1,
|
||||
0,0,1,1,0,0,1,1,
|
||||
0,1,1,0,0,1,1,0,
|
||||
1,1,0,0,1,1,0,0,
|
||||
1,0,0,1,1,0,0,1,
|
||||
0,0,1,1,0,0,1,1,
|
||||
]
|
||||
},
|
||||
Image {
|
||||
pixels: vec![
|
||||
0,0,1,1,0,0,1,1,
|
||||
0,1,1,0,0,1,1,0,
|
||||
1,1,0,0,1,1,0,0,
|
||||
1,0,0,1,1,0,0,1,
|
||||
0,0,1,1,0,0,1,1,
|
||||
0,1,1,0,0,1,1,0,
|
||||
1,1,0,0,1,1,0,0,
|
||||
1,0,0,1,1,0,0,1,
|
||||
]
|
||||
},
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
use crate::{from_base36, optional_data_line, AnimationFrames, Image, Position, ToBase36};
|
||||
use crate::image::animation_frames_from_string;
|
||||
|
||||
#[derive(Debug, Eq, PartialEq)]
|
||||
pub struct Sprite {
|
||||
|
@ -94,13 +95,9 @@ impl From<String> for Sprite {
|
|||
|
||||
items.reverse();
|
||||
|
||||
// todo dedupe
|
||||
let animation_frames = lines[1..].join("");
|
||||
let animation_frames: Vec<&str> = animation_frames.split(">").collect();
|
||||
let animation_frames: Vec<Image> = animation_frames
|
||||
.iter()
|
||||
.map(|&frame| Image::from(frame.to_string()))
|
||||
.collect();
|
||||
let animation_frames = animation_frames_from_string(
|
||||
lines[1..].join("\n")
|
||||
);
|
||||
|
||||
Sprite {
|
||||
id,
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
10011001
|
||||
00110011
|
||||
01100110
|
||||
11001100
|
||||
10011001
|
||||
00110011
|
||||
01100110
|
||||
11001100
|
||||
>
|
||||
11001100
|
||||
10011001
|
||||
00110011
|
||||
01100110
|
||||
11001100
|
||||
10011001
|
||||
00110011
|
||||
01100110
|
||||
>
|
||||
01100110
|
||||
11001100
|
||||
10011001
|
||||
00110011
|
||||
01100110
|
||||
11001100
|
||||
10011001
|
||||
00110011
|
||||
>
|
||||
00110011
|
||||
01100110
|
||||
11001100
|
||||
10011001
|
||||
00110011
|
||||
01100110
|
||||
11001100
|
||||
10011001
|
10
src/tile.rs
10
src/tile.rs
|
@ -1,4 +1,5 @@
|
|||
use crate::{from_base36, optional_data_line, AnimationFrames, Image, ToBase36};
|
||||
use crate::image::animation_frames_from_string;
|
||||
|
||||
#[derive(Debug, Eq, PartialEq)]
|
||||
pub struct Tile {
|
||||
|
@ -60,12 +61,9 @@ impl From<String> for Tile {
|
|||
}
|
||||
}
|
||||
|
||||
let animation_frames = lines[1..].join("");
|
||||
let animation_frames: Vec<&str> = animation_frames.split(">").collect();
|
||||
let animation_frames: Vec<Image> = animation_frames
|
||||
.iter()
|
||||
.map(|&frame| Image::from(frame.to_string()))
|
||||
.collect();
|
||||
let animation_frames = animation_frames_from_string(
|
||||
lines[1..].join("\n")
|
||||
);
|
||||
|
||||
Tile {
|
||||
id,
|
||||
|
|
Loading…
Reference in New Issue