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

Making tile.type and layer.class_ compatible with Tiled 1.9's new Unified Custom Types ("class") #50

Merged
merged 11 commits into from
Jul 18, 2022
6 changes: 3 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
## 0.8.4
* Adding support for `tile.type` using the "class" attribute for Tiled 1.9's Unified Custom Types

## 0.8.3
* Downgrade meta dependency

## 0.8.2
* Add support for class, which is replacing type in tiled 1.9
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should never remove entries from the changelog, if the entry was wrong it should be explained in the new entry.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my bad, I got the versions mixed up because when I forked this wasn't here, I'll undelete this


## 0.8.1
* Possibility to parse string content of a tilemap in `TiledMap`

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Include the following in your `pubspec.yaml`:

```yaml
dependencies:
tiled: 0.8.1
tiled: 0.8.4
```

## Usage
Expand Down
5 changes: 4 additions & 1 deletion lib/src/tileset/tile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ class Tile {
static Tile parse(Parser parser) {
return Tile(
localId: parser.getInt('id'),
type: parser.getStringOrNull('type'),

/// Tiled 1.9 "type" has been moved to "class"
type: parser.getStringOrNull('type') ?? parser.getStringOrNull('class'),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to make it consistent with #48, you can make it check for class first, and then type. As more and more people will migrate to Tiled 1.9, chances of finding class property instead of type are more likely.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed the ordering.

I think with Tiled 1.9 you can add class to nearly anything, which is why they did the rename. We'd probably need to got through and test this for a bunch of other objects, but Layers for one could be useful. Although it raises the question, should we add a tiledClass attribute or keep calling them type even though they property in the new Tiled UI is "Class", I guess they named it that because layers already have a "type" which means something else.

In addition, the “Type” property previously available only for objects and tiles is now available for all data types as the new “Class” property. For consistency, this value is written out as “class” also for objects and tiles, but a project-wide compatibility option is provided to make it still write out as “type”

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For TiledObject class I kept type attribute as it was and just added a getter called class_ which returns type. That way it won't break anyone's existing code and if someone using tiled with newer map files, tries to find class attribute, class_ will pop-up in auto-complete list.


probability: parser.getDouble('probability', defaults: 0),
terrain: parser
.getStringOrNull('terrain')
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: tiled
version: 0.8.3
version: 0.8.4
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should normally not be bumped in this PR, but since I'll do a release after this is merged it doesn't matter this time.

description: A Dart Tiled library. Parse your TMX files into useful representations. Compatible with Flame.
homepage: https://github.com/flame-engine/tiled.dart

Expand Down