forked from RafaelBarbosatec/tiled_json_reader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tile_set_item.dart
61 lines (57 loc) · 1.7 KB
/
tile_set_item.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import 'package:tiledjsonreader/map/layer/objects.dart';
import 'package:tiledjsonreader/tile_set/frame_animation.dart';
import 'package:tiledjsonreader/tile_set/tile_set_object_group.dart';
class TileSetItem {
int? id;
String? type;
String? tileClass;
String? image;
int? imageHeight;
int? imageWidth;
double? probability;
List<int>? terrain;
List<FrameAnimation>? animation;
TileSetObjectGroup? objectGroup;
List<Property>? properties;
TileSetItem({this.id, this.objectGroup});
TileSetItem.fromJson(Map<String, dynamic> json) {
id = json['id'];
type = json['type'];
tileClass = json['class'];
image = json['image'];
imageHeight = json['imageheight'];
imageWidth = json['imagewidth'];
probability = json['probability']?.toDouble() ?? 0.0;
if (json['terrain'] != null) {
terrain = <int>[];
json['terrain'].forEach((v) {
terrain?.add(v);
});
}
objectGroup = json['objectgroup'] != null
? new TileSetObjectGroup.fromJson(json['objectgroup'])
: null;
if (json['animation'] != null) {
animation = <FrameAnimation>[];
json['animation'].forEach((v) {
animation?.add(new FrameAnimation.fromJson(v));
});
}
if (json['properties'] != null) {
properties = <Property>[];
json['properties'].forEach((v) {
properties?.add(new Property.fromJson(v));
});
}
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['id'] = this.id;
data['type'] = this.type;
data['class'] = this.tileClass;
if (this.objectGroup != null) {
data['objectgroup'] = this.objectGroup?.toJson();
}
return data;
}
}