-
Notifications
You must be signed in to change notification settings - Fork 106
/
Copy pathmain.rs
48 lines (43 loc) · 1.67 KB
/
main.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
use std::path::PathBuf;
use tiled::Loader;
fn main() {
let mut loader = Loader::new();
let map_path = PathBuf::from(std::env::var("CARGO_MANIFEST_DIR").unwrap())
.join("assets/tiled_base64_zlib.tmx");
let map = loader.load_tmx_map(map_path).unwrap();
for layer in map.layers() {
print!("Layer \"{}\":\n\t", layer.name);
match layer.layer_type() {
tiled::LayerType::Tiles(layer) => match layer {
tiled::TileLayer::Finite(data) => println!(
"Finite tile layer with width = {} and height = {}; ID of tile @ (0,0): {}",
data.width(),
data.height(),
data.get_tile(0, 0).unwrap().id()
),
tiled::TileLayer::Infinite(data) => {
println!(
"Infinite tile layer; Tile @ (-5, 0) = {:?}",
data.get_tile(-5, 0)
)
}
},
tiled::LayerType::Objects(layer) => {
println!("Object layer with {} objects", layer.objects().len())
}
tiled::LayerType::Image(layer) => {
println!(
"Image layer with {}",
match &layer.image {
Some(img) =>
format!("an image with source = {}", img.source.to_string_lossy()),
None => "no image".to_owned(),
}
)
}
tiled::LayerType::Group(layer) => {
println!("Group layer with {} sublayers", layer.layers().len())
}
}
}
}