2022-02-24 05:05:48 +11:00
|
|
|
use std::path::Path;
|
2022-02-23 07:16:34 +11:00
|
|
|
|
2022-02-24 05:05:48 +11:00
|
|
|
use asefile::{AsepriteFile, Tag};
|
2022-02-23 07:16:34 +11:00
|
|
|
use image::DynamicImage;
|
2022-02-16 08:28:21 +11:00
|
|
|
|
2022-02-24 05:05:48 +11: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-23 07:16:34 +11:00
|
|
|
|
2022-02-24 05:05:48 +11:00
|
|
|
let mut images = Vec::new();
|
|
|
|
let mut tags = Vec::new();
|
2022-02-23 07:24:32 +11:00
|
|
|
|
2022-02-24 05:05:48 +11:00
|
|
|
for frame in 0..ase.num_frames() {
|
|
|
|
let image = ase.frame(frame).image();
|
2022-02-23 07:16:34 +11:00
|
|
|
|
2022-02-24 05:05:48 +11:00
|
|
|
images.push(DynamicImage::ImageRgba8(image))
|
|
|
|
}
|
2022-02-23 07:16:34 +11:00
|
|
|
|
2022-02-24 05:05:48 +11:00
|
|
|
for tag in 0..ase.num_tags() {
|
|
|
|
tags.push(ase.tag(tag).clone())
|
|
|
|
}
|
2022-02-23 07:16:34 +11:00
|
|
|
|
2022-02-24 05:05:48 +11:00
|
|
|
(images, tags)
|
2022-02-23 07:16:34 +11:00
|
|
|
}
|