2022-02-23 18:05:48 +00:00
|
|
|
use std::path::Path;
|
2022-02-22 20:16:34 +00:00
|
|
|
|
2022-02-23 18:05:48 +00:00
|
|
|
use asefile::{AsepriteFile, Tag};
|
2022-02-22 20:16:34 +00:00
|
|
|
use image::DynamicImage;
|
2022-02-15 21:28:21 +00:00
|
|
|
|
2022-02-23 18:05:48 +00:00
|
|
|
pub fn generate_from_file(filename: &Path) -> (Vec<DynamicImage>, Vec<Tag>) {
|
|
|
|
let ase = AsepriteFile::read_file(filename).expect("Aseprite file should exist");
|
2022-02-22 20:16:34 +00:00
|
|
|
|
2022-02-23 18:05:48 +00:00
|
|
|
let mut images = Vec::new();
|
|
|
|
let mut tags = Vec::new();
|
2022-02-22 20:24:32 +00:00
|
|
|
|
2022-02-23 18:05:48 +00:00
|
|
|
for frame in 0..ase.num_frames() {
|
|
|
|
let image = ase.frame(frame).image();
|
2022-02-22 20:16:34 +00:00
|
|
|
|
2022-02-23 18:05:48 +00:00
|
|
|
images.push(DynamicImage::ImageRgba8(image))
|
|
|
|
}
|
2022-02-22 20:16:34 +00:00
|
|
|
|
2022-02-23 18:05:48 +00:00
|
|
|
for tag in 0..ase.num_tags() {
|
|
|
|
tags.push(ase.tag(tag).clone())
|
|
|
|
}
|
2022-02-22 20:16:34 +00:00
|
|
|
|
2022-02-23 18:05:48 +00:00
|
|
|
(images, tags)
|
2022-02-22 20:16:34 +00:00
|
|
|
}
|