Skip to content

Commit 305418d

Browse files
fix: Object layer parsing for JSON format (#88)
# Description When loading and parsing JSON Format, `objectGroup` layers wheren't parsed correctly, which resulted in empty entry. The main problem was that in JSON Format it is called "objects" instead of "object" like in XML. Here is a snippet of a JSON file exported with Tiled 1.8.2: ```json "draworder":"topdown", "id":8, "name":"obj", "objects":[ { "height":8, "id":1, "name":"start", "rotation":0, "type":"", "visible":true, "width":8, "x":64, "y":160 }, { "height":8, "id":2, "name":"gem", "rotation":0, "type":"", "visible":true, "width":8, "x":96, "y":40 }, ``` ## Breaking Change - [ ] Yes, this is a breaking change. - [X] No, this is *not* a breaking change. --------- Co-authored-by: Lukas Klingsbo <[email protected]>
1 parent 4a664be commit 305418d

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

packages/tiled/lib/src/layer.dart

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,12 @@ abstract class Layer {
194194
parser.getString('color', defaults: ObjectGroup.defaultColorHex);
195195
final color =
196196
parser.getColor('color', defaults: ObjectGroup.defaultColor);
197-
final objects = parser.getChildrenAs('object', TiledObject.parse);
197+
198+
final objects = parser.formatSpecificParsing(
199+
(json) => json.getChildrenAs('objects', TiledObject.parse),
200+
(xml) => xml.getChildrenAs('object', TiledObject.parse),
201+
);
202+
198203
layer = ObjectGroup(
199204
id: id,
200205
name: name,

packages/tiled/lib/src/objects/tiled_object.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,11 @@ class TiledObject {
118118
);
119119

120120
final ellipse = parser.formatSpecificParsing(
121-
(json) => json.getBool('ellipse'),
121+
(json) => json.getBool('ellipse', defaults: false),
122122
(xml) => xml.getChildren('ellipse').isNotEmpty,
123123
);
124124
final point = parser.formatSpecificParsing(
125-
(json) => json.getBool('point'),
125+
(json) => json.getBool('point', defaults: false),
126126
(xml) => xml.getChildren('point').isNotEmpty,
127127
);
128128
final text = parser.getSingleChildOrNullAs('text', Text.parse);

0 commit comments

Comments
 (0)