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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
const int _kGraphicsIndex = 3;
class MonsterAbilityDeckModel {
// ignore: prefer-match-file-name, file contains multiple ability model types
final String name;
final String edition;
final List<MonsterAbilityCardModel> cards;
const MonsterAbilityDeckModel(this.name, this.edition, this.cards);
factory MonsterAbilityDeckModel.fromJson(
Map<String, dynamic> data,
String edition,
) {
final name = data['name'] as String;
final List<List<Object?>> dynamicCards =
(data['cards'] as List).cast<List<Object?>>();
final List<MonsterAbilityCardModel> cards = [];
for (final card in dynamicCards) {
String title = name;
if (card[0] is String) {
title = card[0] as String;
card.removeAt(0);
}
final int nr = card[0] as int;
///duplication check
if (cards.any((element) => element.nr == nr)) {
print("duplicate monster ability card nr: $nr for $name");
}
final bool shuffle = card[1] as bool;
final int initiative = card[2] as int;
final List<GraphicPositional> graphicPositionals = [];
if (card[3] is List) {
//handle the graphic extras
final List<dynamic> list = card[3] as List;
for (final Map<String, dynamic> item in list) {
double angle = 0;
double scale = 1;
if (item.containsKey('angle')) {
angle = item['angle'];
}
if (item.containsKey('scale')) {
scale = item['scale'];
}
final GraphicPositional pos = GraphicPositional(
item["gfx"],
item["x"],
item["y"],
scale,
angle,
);
graphicPositionals.add(pos);
}
card.removeAt(_kGraphicsIndex);
}
final List<String> lines = [];
for (int i = _kGraphicsIndex; i < card.length; i++) {
lines.add(card[i] as String);
}
cards.add(
MonsterAbilityCardModel(
title,
nr,
shuffle,
initiative,
lines,
name,
graphicPositionals,
),
);
}
return MonsterAbilityDeckModel(name, edition, cards);
}
}
class GraphicPositional {
final String gfx;
final double x;
final double y;
final double scale;
final double angle;
const GraphicPositional(this.gfx, this.x, this.y, this.scale, this.angle);
}
class MonsterAbilityCardModel {
final String deck;
final String title;
final int nr;
final bool shuffle;
final int initiative;
final List<String> lines;
final List<GraphicPositional> graphicPositional;
const MonsterAbilityCardModel(
this.title,
this.nr,
this.shuffle,
this.initiative,
this.lines,
this.deck,
this.graphicPositional,
);
Map<String, dynamic> toJson() => {'nr': nr, 'deck': deck};
@override
String toString() => '{"nr": $nr, "deck": "$deck" }';
}
|