-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2fd9532
commit 884eb7d
Showing
18 changed files
with
844 additions
and
915 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,57 @@ | ||
use tiled::Map; | ||
use std::path::PathBuf; | ||
|
||
use tiled::{FilesystemResourceCache, Map}; | ||
|
||
fn main() { | ||
let map = Map::parse_file("assets/tiled_base64_zlib.tmx").unwrap(); | ||
println!("{:?}", map); | ||
println!("{:?}", map.tileset_by_gid(22)); | ||
// Create a new resource cache. This is a structure that holds references to loaded | ||
// assets such as tilesets so that they only get loaded once. | ||
// [`FilesystemResourceCache`] is a implementation of [`tiled::ResourceCache`] that | ||
// identifies resources by their path in the filesystem. | ||
let mut cache = FilesystemResourceCache::new(); | ||
|
||
let map_path = PathBuf::from(std::env::var("CARGO_MANIFEST_DIR").unwrap()) | ||
.join("assets/tiled_base64_zlib.tmx"); | ||
let map = Map::parse_file(map_path, &mut cache).unwrap(); | ||
|
||
for layer in map.layers() { | ||
print!("Layer \"{}\":\n\t", layer.data().name); | ||
|
||
match layer.layer_type() { | ||
tiled::LayerType::TileLayer(layer) => match layer.data() { | ||
tiled::TileLayerData::Finite(data) => println!( | ||
"Finite tile layer with width = {} and height = {}; ID of tile @ (0,0): {}", | ||
data.width(), | ||
data.height(), | ||
layer.get_tile(0, 0).unwrap().id | ||
), | ||
tiled::TileLayerData::Infinite(data) => { | ||
// This is prone to change! Infinite layers will be refactored before 0.10.0 | ||
// releases. | ||
println!("Infinite tile layer with {} chunks", data.chunks.len()) | ||
} | ||
}, | ||
|
||
tiled::LayerType::ObjectLayer(layer) => { | ||
println!("Object layer with {} objects", layer.data().objects.len()) | ||
}, | ||
|
||
tiled::LayerType::ImageLayer(layer) => { | ||
println!( | ||
"Image layer with {}", | ||
match &layer.data().image { | ||
Some(img) => | ||
format!("an image with source = {}", img.source.to_string_lossy()), | ||
None => "no image".to_owned(), | ||
} | ||
) | ||
}, | ||
|
||
tiled::LayerType::GroupLayer(layer) => { | ||
println!( | ||
"Group layer with {} sublayers", | ||
layer.layers().len() | ||
) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.