Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge branch 'current' into next #246

Merged
merged 5 commits into from
Feb 13, 2023
Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ jobs:
run: sudo apt-get update

- name: Install dependencies
run: sudo apt-get install -y libasound2-dev libudev-dev
run: sudo apt-get install -y libsfml-dev libcsfml-dev libasound2-dev libudev-dev

- name: Get stable Rust toolchain with clippy
uses: actions-rs/toolchain@v1
Expand Down
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@ objects. As such, `ResourceCache` has now methods for both getting and inserting
## [Unreleased]
### Added
- Support for Wang sets.
- Support for Tiled 1.9 `Class` property. Maps, tilesets and layers now have a `user_type` property.
- Support for tile offsets. Tilesets now have an `offset_x` and `offset_y` property.

### Deprecated
- `Tile::tile_type`: Use `Tile::user_type` instead.
- `Object::obj_type` Use `Object::user_type` instead.

### Changed
- Update `zstd` to `0.12.0`.
- Update `sfml` dev dependency to `0.19.0`.

## [0.10.2]
### Added
Expand Down
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ path = "examples/ggez/main.rs"
base64 = "0.13.0"
xml-rs = "0.8.4"
libflate = "1.1.2"
zstd = { version = "0.11.0", optional = true }
zstd = { version = "0.12.0", optional = true }

[dev-dependencies.sfml]
version = "0.16"
version = "0.19.0"
features = ["graphics"]

[dev-dependencies.ggez]
Expand Down
6 changes: 4 additions & 2 deletions examples/sfml/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,10 @@ fn main() {

/// Creates the window of the application
fn create_window() -> RenderWindow {
let mut context_settings = ContextSettings::default();
context_settings.set_antialiasing_level(2);
let context_settings = ContextSettings {
antialiasing_level: 2,
..Default::default()
};
let mut window = RenderWindow::new(
(1080, 720),
"rs-tiled demo",
Expand Down
21 changes: 19 additions & 2 deletions src/layers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ pub struct LayerData {
pub tint_color: Option<Color>,
/// The layer's custom properties, as arbitrarily set by the user.
pub properties: Properties,
/// The layer's type, which is arbitrarily setby the user.
pub user_type: Option<String>,
layer_type: LayerDataType,
}

Expand All @@ -76,7 +78,19 @@ impl LayerData {
reader: &mut impl ResourceReader,
cache: &mut impl ResourceCache,
) -> Result<Self> {
let (opacity, tint_color, visible, offset_x, offset_y, parallax_x, parallax_y, name, id) = get_attrs!(
let (
opacity,
tint_color,
visible,
offset_x,
offset_y,
parallax_x,
parallax_y,
name,
id,
user_type,
user_class,
) = get_attrs!(
for v in attrs {
Some("opacity") => opacity ?= v.parse(),
Some("tintcolor") => tint_color ?= v.parse(),
Expand All @@ -87,8 +101,10 @@ impl LayerData {
Some("parallaxy") => parallax_y ?= v.parse(),
Some("name") => name = v,
Some("id") => id ?= v.parse(),
Some("type") => user_type ?= v.parse(),
Some("class") => user_class ?= v.parse(),
}
(opacity, tint_color, visible, offset_x, offset_y, parallax_x, parallax_y, name, id)
(opacity, tint_color, visible, offset_x, offset_y, parallax_x, parallax_y, name, id, user_type, user_class)
);

let (ty, properties) = match tag {
Expand Down Expand Up @@ -136,6 +152,7 @@ impl LayerData {
tint_color,
name: name.unwrap_or_default(),
id: id.unwrap_or(0),
user_type: user_type.or(user_class),
properties,
layer_type: ty,
})
Expand Down
10 changes: 8 additions & 2 deletions src/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ pub struct Map {
/// The background color of this map, if any.
pub background_color: Option<Color>,
infinite: bool,
/// The type of the map, which is arbitrary and set by the user.
pub user_type: Option<String>,
}

impl Map {
Expand Down Expand Up @@ -126,21 +128,24 @@ impl Map {
reader: &mut impl ResourceReader,
cache: &mut impl ResourceCache,
) -> Result<Map> {
let ((c, infinite), (v, o, w, h, tw, th)) = get_attrs!(
let ((c, infinite, user_type, user_class), (v, o, w, h, tw, th)) = get_attrs!(
for v in attrs {
Some("backgroundcolor") => colour ?= v.parse(),
Some("infinite") => infinite = v == "1",
Some("type") => user_type ?= v.parse(),
Some("class") => user_class ?= v.parse(),
"version" => version = v,
"orientation" => orientation ?= v.parse::<Orientation>(),
"width" => width ?= v.parse::<u32>(),
"height" => height ?= v.parse::<u32>(),
"tilewidth" => tile_width ?= v.parse::<u32>(),
"tileheight" => tile_height ?= v.parse::<u32>(),
}
((colour, infinite), (version, orientation, width, height, tile_width, tile_height))
((colour, infinite, user_type, user_class), (version, orientation, width, height, tile_width, tile_height))
);

let infinite = infinite.unwrap_or(false);
let user_type = user_type.or(user_class);

// We can only parse sequentally, but tilesets are guaranteed to appear before layers.
// So we can pass in tileset data to layer construction without worrying about unfinished
Expand Down Expand Up @@ -247,6 +252,7 @@ impl Map {
properties,
background_color: c,
infinite,
user_type,
})
}
}
Expand Down
17 changes: 11 additions & 6 deletions src/objects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,9 @@ pub struct ObjectData {
/// The name of the object, which is arbitrary and set by the user.
pub name: String,
/// The type of the object, which is arbitrary and set by the user.
pub user_type: String,
/// This property has been renamed to `user_type`.
#[deprecated(since = "0.10.3", note = "Use [`ObjectData::user_type`] instead")]
pub obj_type: String,
/// The width of the object, if applicable. This refers to the attribute in `object`.
/// Since it is duplicate or irrelevant information in all cases, use the equivalent
Expand Down Expand Up @@ -235,12 +238,13 @@ impl ObjectData {
reader: &mut impl ResourceReader,
cache: &mut impl ResourceCache,
) -> Result<ObjectData> {
let (id, tile, mut n, mut t, mut w, mut h, mut v, mut r, template, x, y) = get_attrs!(
let (id, tile, mut n, mut t, c, mut w, mut h, mut v, mut r, template, x, y) = get_attrs!(
for v in attrs {
Some("id") => id ?= v.parse(),
Some("gid") => tile ?= v.parse::<u32>(),
Some("name") => name ?= v.parse(),
Some("type") => obj_type ?= v.parse(),
Some("type") => user_type ?= v.parse(),
Some("class") => user_class ?= v.parse(),
Some("width") => width ?= v.parse(),
Some("height") => height ?= v.parse(),
Some("visible") => visible ?= v.parse().map(|x:i32| x == 1),
Expand All @@ -249,7 +253,7 @@ impl ObjectData {
Some("x") => x ?= v.parse::<f32>(),
Some("y") => y ?= v.parse::<f32>(),
}
(id, tile, name, obj_type, width, height, visible, rotation, template, x, y)
(id, tile, name, user_type, user_class, width, height, visible, rotation, template, x, y)
);
let x = x.unwrap_or(0.);
let y = y.unwrap_or(0.);
Expand Down Expand Up @@ -280,7 +284,7 @@ impl ObjectData {
h.get_or_insert(obj.height);
r.get_or_insert(obj.rotation);
n.get_or_insert_with(|| obj.name.clone());
t.get_or_insert_with(|| obj.obj_type.clone());
t.get_or_insert_with(|| obj.user_type.clone());
if let Some(templ_tile) = &obj.tile {
tile.get_or_insert_with(|| templ_tile.clone());
}
Expand All @@ -294,7 +298,7 @@ impl ObjectData {
let rotation = r.unwrap_or(0f32);
let id = id.unwrap_or(0u32);
let name = n.unwrap_or_default();
let obj_type = t.unwrap_or_default();
let user_type: String = t.or(c).unwrap_or_default();
let mut shape = None;
let mut properties = HashMap::new();

Expand Down Expand Up @@ -347,7 +351,8 @@ impl ObjectData {
id,
tile,
name,
obj_type,
obj_type: user_type.clone(),
user_type,
width,
height,
x,
Expand Down
16 changes: 11 additions & 5 deletions src/tile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ pub struct TileData {
/// The animation frames of this tile.
pub animation: Option<Vec<Frame>>,
/// The type of this tile.
pub user_type: Option<String>,
/// This property has been renamed to `user_type`.
#[deprecated(since = "0.10.3", note = "Use [`TileData::user_type`] instead")]
pub tile_type: Option<String>,
/// The probability of this tile.
pub probability: f32,
Expand Down Expand Up @@ -67,15 +70,16 @@ impl TileData {
reader: &mut impl ResourceReader,
cache: &mut impl ResourceCache,
) -> Result<(TileId, TileData)> {
let ((tile_type, probability), id) = get_attrs!(
let ((user_type, user_class, probability), id) = get_attrs!(
for v in attrs {
Some("type") => tile_type ?= v.parse(),
Some("type") => user_type ?= v.parse(),
Some("class") => user_class ?= v.parse(),
Some("probability") => probability ?= v.parse(),
"id" => id ?= v.parse::<u32>(),
}
((tile_type, probability), id)
((user_type, user_class, probability), id)
);

let user_type = user_type.or(user_class);
let mut image = Option::None;
let mut properties = HashMap::new();
let mut objectgroup = None;
Expand All @@ -102,12 +106,14 @@ impl TileData {
});
Ok((
id,
#[allow(deprecated)]
TileData {
image,
properties,
collision: objectgroup,
animation,
tile_type,
tile_type: user_type.clone(),
user_type,
probability: probability.unwrap_or(1.0),
},
))
Expand Down
Loading