-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
442 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
[package] | ||
name = "bevy_proto_aseprite" | ||
name = "bevy_asefile" | ||
version = "0.1.0" | ||
authors = ["alpine_alpaca <[email protected]>"] | ||
authors = ["alpine_alpaca <[email protected]>", "B-Reif"] | ||
edition = "2018" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
bevy = "0.5" | ||
asefile = "0.2" | ||
asefile = { git = "https://github.com/B-Reif/asefile", branch = "main" } | ||
anyhow = "1.0" | ||
|
||
[dev-dependencies] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
use asefile::{AsepriteFile, Tag}; | ||
use std::path::PathBuf; | ||
|
||
#[derive(Debug)] | ||
pub(crate) struct Animation { | ||
pub(crate) file: PathBuf, | ||
pub(crate) tag: Option<String>, | ||
pub(crate) sprites: Vec<usize>, | ||
} | ||
impl Animation { | ||
pub(crate) fn new(name: &PathBuf, ase: &AsepriteFile, sprite_offset: usize) -> Self { | ||
Self { | ||
file: name.clone(), | ||
tag: None, | ||
sprites: (0..ase.num_frames()) | ||
.map(|f| sprite_offset + f as usize) | ||
.collect(), | ||
} | ||
} | ||
pub(crate) fn from_tag(name: &PathBuf, sprite_offset: usize, tag: &Tag) -> Self { | ||
Animation { | ||
file: name.clone(), | ||
tag: Some(tag.name().to_owned()), | ||
sprites: (tag.from_frame()..tag.to_frame() + 1) | ||
.map(|f| sprite_offset + f as usize) | ||
.collect(), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
use std::{fmt, path::PathBuf}; | ||
|
||
use asefile::AsepriteFile; | ||
use bevy::utils::HashMap; | ||
|
||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | ||
pub struct AseId(u32); | ||
impl AseId { | ||
pub fn new(inner: u32) -> Self { | ||
Self(inner) | ||
} | ||
pub fn inner(&self) -> &u32 { | ||
&self.0 | ||
} | ||
} | ||
impl fmt::Display for AseId { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
write!(f, "AseId({})", self.0) | ||
} | ||
} | ||
|
||
pub(crate) struct AseKeyed { | ||
pub(crate) id: AseId, | ||
pub(crate) path: PathBuf, | ||
pub(crate) file: AsepriteFile, | ||
} | ||
|
||
pub(crate) struct AsesById(HashMap<AseId, AseKeyed>); | ||
impl AsesById { | ||
pub(crate) fn inner(&self) -> &HashMap<AseId, AseKeyed> { | ||
&self.0 | ||
} | ||
pub fn iter(&self) -> std::collections::hash_map::Iter<'_, AseId, AseKeyed> { | ||
self.0.iter() | ||
} | ||
} | ||
impl From<Vec<(PathBuf, AsepriteFile)>> for AsesById { | ||
fn from(vec: Vec<(PathBuf, AsepriteFile)>) -> Self { | ||
Self( | ||
vec.into_iter() | ||
.enumerate() | ||
.map(|(idx, (path, file))| { | ||
let id = AseId::new(idx as u32); | ||
let value = AseKeyed { id, path, file }; | ||
(id, value) | ||
}) | ||
.collect(), | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.