refactor: unify ghost state management and animation handling, use integers for texture animation

This commit is contained in:
Ryan Walters
2025-09-01 14:27:48 -05:00
parent e1a2e6ab62
commit b53db3788d
13 changed files with 221 additions and 217 deletions

View File

@@ -18,46 +18,41 @@ fn test_animated_texture_creation_errors() {
let tiles = smallvec![mock_atlas_tile(1), mock_atlas_tile(2)];
assert!(matches!(
AnimatedTexture::new(tiles.clone(), 0.0).unwrap_err(),
GameError::Texture(TextureError::Animated(AnimatedTextureError::InvalidFrameDuration(0.0)))
));
assert!(matches!(
AnimatedTexture::new(tiles, -0.1).unwrap_err(),
GameError::Texture(TextureError::Animated(AnimatedTextureError::InvalidFrameDuration(-0.1)))
AnimatedTexture::new(tiles.clone(), 0).unwrap_err(),
GameError::Texture(TextureError::Animated(AnimatedTextureError::InvalidFrameDuration(0)))
));
}
#[test]
fn test_animated_texture_advancement() {
let tiles = smallvec![mock_atlas_tile(1), mock_atlas_tile(2), mock_atlas_tile(3)];
let mut texture = AnimatedTexture::new(tiles, 0.1).unwrap();
let mut texture = AnimatedTexture::new(tiles, 10).unwrap();
assert_eq!(texture.current_frame(), 0);
texture.tick(0.25);
texture.tick(25);
assert_eq!(texture.current_frame(), 2);
assert!((texture.time_bank() - 0.05).abs() < 0.001);
assert_eq!(texture.time_bank(), 5);
}
#[test]
fn test_animated_texture_wrap_around() {
let tiles = smallvec![mock_atlas_tile(1), mock_atlas_tile(2)];
let mut texture = AnimatedTexture::new(tiles, 0.1).unwrap();
let mut texture = AnimatedTexture::new(tiles, 10).unwrap();
texture.tick(0.1);
texture.tick(10);
assert_eq!(texture.current_frame(), 1);
texture.tick(0.1);
texture.tick(10);
assert_eq!(texture.current_frame(), 0);
}
#[test]
fn test_animated_texture_single_frame() {
let tiles = smallvec![mock_atlas_tile(1)];
let mut texture = AnimatedTexture::new(tiles, 0.1).unwrap();
let mut texture = AnimatedTexture::new(tiles, 10).unwrap();
texture.tick(0.1);
texture.tick(10);
assert_eq!(texture.current_frame(), 0);
assert_eq!(texture.current_tile().color.unwrap().r, 1);
}