-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtest.rs
123 lines (109 loc) · 4.68 KB
/
test.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
use std::sync::Arc;
// tests
#[cfg(test)]
use crate::{AnimationState, AnimationStateData, Atlas, Skeleton, SkeletonData, SkeletonJson};
// doc tests
#[cfg(not(test))]
use rusty_spine::{
AnimationState, AnimationStateData, Atlas, Skeleton, SkeletonData, SkeletonJson,
};
/*pub const TEST_SPINEBOY_ATLAS_FILE: &'static str = "assets/spineboy/export/spineboy.atlas";
pub const TEST_SPINEBOY_ATLAS_BYTES: &'static [u8] =
include_bytes!("../assets/spineboy/export/spineboy.atlas");
pub const TEST_SPINEBOY_JSON_BYTES: &'static [u8] =
include_bytes!("../assets/spineboy/export/spineboy-pro.json");*/
pub struct TestAsset {
pub atlas_file: &'static str,
pub atlas_data: &'static [u8],
pub json_data: &'static [u8],
}
impl TestAsset {
pub fn all() -> &'static [Self; 8] {
&[
Self {
atlas_file: "assets/spineboy/export/spineboy.atlas",
atlas_data: include_bytes!("../assets/spineboy/export/spineboy.atlas"),
json_data: include_bytes!("../assets/spineboy/export/spineboy-pro.json"),
},
Self {
atlas_file: "assets/alien/export/alien.atlas",
atlas_data: include_bytes!("../assets/alien/export/alien.atlas"),
json_data: include_bytes!("../assets/alien/export/alien-pro.json"),
},
Self {
atlas_file: "assets/coin/export/coin.atlas",
atlas_data: include_bytes!("../assets/coin/export/coin.atlas"),
json_data: include_bytes!("../assets/coin/export/coin-pro.json"),
},
Self {
atlas_file: "assets/dragon/export/dragon.atlas",
atlas_data: include_bytes!("../assets/dragon/export/dragon.atlas"),
json_data: include_bytes!("../assets/dragon/export/dragon-ess.json"),
},
Self {
atlas_file: "assets/goblins/export/goblins.atlas",
atlas_data: include_bytes!("../assets/goblins/export/goblins.atlas"),
json_data: include_bytes!("../assets/goblins/export/goblins-pro.json"),
},
Self {
atlas_file: "assets/stretchyman/export/stretchyman.atlas",
atlas_data: include_bytes!("../assets/stretchyman/export/stretchyman.atlas"),
json_data: include_bytes!("../assets/stretchyman/export/stretchyman-pro.json"),
},
Self {
atlas_file: "assets/tank/export/tank.atlas",
atlas_data: include_bytes!("../assets/tank/export/tank.atlas"),
json_data: include_bytes!("../assets/tank/export/tank-pro.json"),
},
Self {
atlas_file: "assets/windmill/export/windmill.atlas",
atlas_data: include_bytes!("../assets/windmill/export/windmill.atlas"),
json_data: include_bytes!("../assets/windmill/export/windmill-ess.json"),
},
]
}
pub fn spineboy() -> &'static Self {
&Self::all()[0]
}
pub fn atlas(&self) -> Atlas {
Atlas::new(&self.atlas_data, "").unwrap()
}
pub fn skeleton_json(&self) -> SkeletonJson {
SkeletonJson::new(Arc::new(self.atlas()))
}
pub fn skeleton_data(&self) -> SkeletonData {
self.skeleton_json()
.read_skeleton_data(&self.json_data)
.unwrap()
}
pub fn animation_state_data(&self) -> AnimationStateData {
AnimationStateData::new(Arc::new(self.skeleton_data()))
}
pub fn instance_data(&self) -> (Arc<SkeletonData>, Arc<AnimationStateData>) {
let skeleton_data = Arc::new(self.skeleton_data());
let animation_state_data = Arc::new(AnimationStateData::new(skeleton_data.clone()));
(skeleton_data, animation_state_data)
}
pub fn instance(&self) -> (Skeleton, AnimationState) {
let (skeleton_data, animation_state_data) = self.instance_data();
let skeleton = Skeleton::new(skeleton_data);
let animation_state = AnimationState::new(animation_state_data);
(skeleton, animation_state)
}
}
/// Ensure all the example assets load without error.
#[test]
fn load_example_assets() {
for example_asset in TestAsset::all().iter() {
let atlas = Arc::new(Atlas::new(&example_asset.atlas_data, "").unwrap());
let skeleton_json = SkeletonJson::new(atlas);
let skeleton_data = Arc::new(
skeleton_json
.read_skeleton_data(&example_asset.json_data)
.unwrap(),
);
let animation_state_data = AnimationStateData::new(skeleton_data.clone());
Skeleton::new(skeleton_data);
AnimationState::new(Arc::new(animation_state_data));
}
}