Skip to content
Snippets Groups Projects
Unverified Commit 4fc60693 authored by Matthew Hall's avatar Matthew Hall Committed by GitHub
Browse files

Merge pull request #44 from Jengamon/master

Add tile-flipping support
parents 2f484361 94a30de6
No related branches found
No related tags found
No related merge requests found
...@@ -437,19 +437,32 @@ impl Tileset { ...@@ -437,19 +437,32 @@ impl Tileset {
#[derive(Debug, PartialEq, Clone)] #[derive(Debug, PartialEq, Clone)]
pub struct Tile { pub struct Tile {
pub id: u32, pub id: u32,
pub flip_h: bool,
pub flip_v: bool,
pub images: Vec<Image>, pub images: Vec<Image>,
pub properties: Properties, pub properties: Properties,
pub objectgroup: Option<ObjectGroup>, pub objectgroup: Option<ObjectGroup>,
pub animation: Option<Vec<Frame>>, pub animation: Option<Vec<Frame>>,
} }
const FLIPPED_HORIZONTALLY_FLAG: u32 = 0x8;
const FLIPPED_VERTICALLY_FLAG: u32 = 0x4;
const FLIPPED_DIAGONALLY_FLAG: u32 = 0x2;
const ALL_FLIP_FLAGS: u32 = 0xE0000000;
impl Tile { impl Tile {
fn new<R: Read>(parser: &mut EventReader<R>, attrs: Vec<OwnedAttribute>) -> Result<Tile, TiledError> { fn new<R: Read>(parser: &mut EventReader<R>, attrs: Vec<OwnedAttribute>) -> Result<Tile, TiledError> {
let (_, i) = get_attrs!( let (_, i): (_, u32) = get_attrs!(
attrs, attrs,
optionals: [], optionals: [],
required: [("id", id, |v:String| v.parse().ok())], required: [("id", id, |v:String| v.parse().ok())],
TiledError::MalformedAttributes("tile must have an id with the correct type".to_string())); TiledError::MalformedAttributes("tile must have an id with the correct type".to_string()));
let flags = (i & ALL_FLIP_FLAGS) >> 28;
let i: u32 = i & 0x1FFFFFFF;
let diagon = flags & FLIPPED_DIAGONALLY_FLAG == FLIPPED_DIAGONALLY_FLAG;
let flip_h = (flags & FLIPPED_HORIZONTALLY_FLAG == FLIPPED_HORIZONTALLY_FLAG) ^ diagon;
let flip_v = (flags & FLIPPED_VERTICALLY_FLAG == FLIPPED_VERTICALLY_FLAG) ^ diagon;
let mut images = Vec::new(); let mut images = Vec::new();
let mut properties = HashMap::new(); let mut properties = HashMap::new();
...@@ -472,7 +485,7 @@ impl Tile { ...@@ -472,7 +485,7 @@ impl Tile {
animation = Some(parse_animation(parser)?); animation = Some(parse_animation(parser)?);
Ok(()) Ok(())
}); });
Ok(Tile {id: i, images: images, properties: properties, objectgroup: objectgroup, animation: animation}) Ok(Tile {id: i, flip_h, flip_v, images: images, properties: properties, objectgroup: objectgroup, animation: animation})
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment