Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,6 @@ tmp/
# moment the tool adds something new. Un-ignore a specific path with `!` if a
# file here ever becomes worth committing.
.claude/
__pycache__/
*.pyc
*.pyo
71 changes: 71 additions & 0 deletions crates/core/src/character.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1161,6 +1161,7 @@ fn loop_path(path: &[&str], closes_at: &str) -> String {
mod tests {
use super::*;
use crate::overlay::SpriteRect;
use std::path::Path;

/// A 2x2 RGBA PNG whose top-left pixel is transparent. Art a renderer can
/// open is all the loader asks of a frame.
Expand Down Expand Up @@ -2243,4 +2244,74 @@ mod tests {
writer.finish().expect("PNG is finishable");
bytes
}

#[test]
fn an_imported_petscodex_character_package_loads() {
use std::fs;

let fixture_dir = Path::new("tests/fixtures/imported-pet");
if !fixture_dir.exists() {
panic!(
"Fixture not found. Generate with: python3 -c \"...\"\n\
See test source for generation command."
);
}

let mut package = PackageBytes::new();
for entry in fs::read_dir(fixture_dir).expect("fixture dir is readable") {
let entry = entry.expect("entry is readable");
let path = entry.path();
if path.is_file() {
let key = path
.file_name()
.expect("has filename")
.to_string_lossy()
.to_string();
package.insert(key, fs::read(&path).expect("file is readable"));
}
}

let frames_dir = fixture_dir.join("frames");
if frames_dir.exists() {
for entry in fs::read_dir(&frames_dir).expect("frames dir is readable") {
let entry = entry.expect("entry is readable");
let path = entry.path();
if path.is_file() && path.extension().map_or(false, |e| e == "png") {
let key = path
.file_name()
.expect("has filename")
.to_string_lossy()
.to_string();
package.insert(key, fs::read(&path).expect("file is readable"));
}
}
}

let character = load(&package).expect("imported fixture loads");

assert_eq!(character.name, "Test Fixture");
for required in REQUIRED_ANIMATIONS {
assert!(
character.animations.contains_key(required),
"character has {required}"
);
}

assert!(
character.animations.contains_key("waiting"),
"waiting animation is present"
);
assert!(
character.animations["idle"]
.variants
.contains(&"waiting".to_string()),
"waiting is in idle's variant ring"
);

assert!(!character.animations["land"].looping, "land plays once");
assert!(!character.animations["react"].looping, "react plays once");

let drawn = character.draw("idle", 0).expect("idle draws");
assert!(drawn.frame_size.0 > 0 && drawn.frame_size.1 > 0);
}
}
49 changes: 49 additions & 0 deletions crates/core/tests/fixtures/imported-pet/character.manifest
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Imported from petscodex: test-fixture
# License: MIT

name = "Test Fixture"
render_mode = "pixelated"
scale = 4

[animations.idle]
frames = ["idle-0.png", "idle-1.png", "idle-2.png", "idle-3.png", "idle-4.png", "idle-5.png"]
fps = 5

[animations.waiting]
frames = ["waiting-0.png", "waiting-1.png", "waiting-2.png", "waiting-3.png", "waiting-4.png", "waiting-5.png"]
fps = 6
variant_of = "idle"

[animations.walk]
frames = ["walk-0.png", "walk-1.png", "walk-2.png", "walk-3.png", "walk-4.png", "walk-5.png", "walk-6.png", "walk-7.png"]
fps = 8

[animations.fall]
frames = ["fall-0.png", "fall-1.png"]
fps = 2

[animations.land]
frames = ["land-0.png", "land-1.png"]
fps = 2
loop = "once"

[animations.sit]
frames = ["sit-0.png", "sit-1.png", "sit-2.png", "sit-3.png", "sit-4.png", "sit-5.png"]
fps = 6

[animations.sleep]
frames = ["sleep-0.png"]
fps = 1

[animations.react]
frames = ["react-0.png", "react-1.png", "react-2.png", "react-3.png", "react-4.png", "react-5.png", "react-6.png", "react-7.png"]
fps = 7
loop = "once"

[animations.talk]
frames = ["talk-0.png", "talk-1.png", "talk-2.png", "talk-3.png"]
fps = 6

[animations.hold]
frames = ["hold-0.png", "hold-1.png"]
fps = 2
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading