mirror of
https://github.com/Xevion/Pac-Man.git
synced 2025-12-15 08:12:32 -06:00
refactor: unify ghost state management and animation handling, use integers for texture animation
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ fn test_game_error_from_io_error() {
|
||||
|
||||
#[test]
|
||||
fn test_texture_error_from_animated_error() {
|
||||
let animated_error = AnimatedTextureError::InvalidFrameDuration(-1.0);
|
||||
let animated_error = AnimatedTextureError::InvalidFrameDuration(0);
|
||||
let texture_error: TextureError = animated_error.into();
|
||||
assert!(matches!(texture_error, TextureError::Animated(_)));
|
||||
}
|
||||
@@ -80,7 +80,7 @@ fn test_entity_error_display() {
|
||||
|
||||
#[test]
|
||||
fn test_animated_texture_error_display() {
|
||||
let error = AnimatedTextureError::InvalidFrameDuration(0.0);
|
||||
let error = AnimatedTextureError::InvalidFrameDuration(0);
|
||||
assert_eq!(error.to_string(), "Frame duration must be positive, got 0");
|
||||
}
|
||||
|
||||
@@ -150,7 +150,7 @@ fn test_result_ext_error() {
|
||||
#[test]
|
||||
fn test_error_chain_conversions() {
|
||||
// Test that we can convert through multiple levels
|
||||
let animated_error = AnimatedTextureError::InvalidFrameDuration(-5.0);
|
||||
let animated_error = AnimatedTextureError::InvalidFrameDuration(0);
|
||||
let texture_error: TextureError = animated_error.into();
|
||||
let game_error: GameError = texture_error.into();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user