66 lines
1.7 KiB
Dart
66 lines
1.7 KiB
Dart
|
import 'dart:collection';
|
||
|
|
||
|
import 'package:json_annotation/json_annotation.dart';
|
||
|
import 'package:yaml/yaml.dart';
|
||
|
|
||
|
part 'Warband.g.dart';
|
||
|
|
||
|
// flutter packages pub run build_runner build --delete-conflicting-outputs
|
||
|
|
||
|
@JsonSerializable(nullable: true, anyMap: true)
|
||
|
class Hero {
|
||
|
@JsonKey(name: 'hero')
|
||
|
final String name;
|
||
|
final String stats;
|
||
|
final String skilllists;
|
||
|
final String weapons;
|
||
|
final String amour;
|
||
|
final String rules;
|
||
|
final int warbandaddition;
|
||
|
|
||
|
Hero(this.stats, this.skilllists, this.weapons, this.amour, this.rules, this.warbandaddition, this.name);
|
||
|
|
||
|
factory Hero.fromJson(yaml) =>
|
||
|
_$HeroFromJson(yaml);
|
||
|
}
|
||
|
|
||
|
@JsonSerializable(nullable: true, anyMap: true)
|
||
|
class Warband {
|
||
|
@JsonKey(name: 'warband', fromJson: _warbandNameAndRace)
|
||
|
HashMap<String, String> nameAndRace;
|
||
|
@JsonKey(ignore: true)
|
||
|
String name;
|
||
|
@JsonKey(ignore: true)
|
||
|
String race;
|
||
|
|
||
|
@JsonKey(name: 'campaign')
|
||
|
final int campaignPoints;
|
||
|
|
||
|
final String objective;
|
||
|
final String alignment;
|
||
|
final String achievments;
|
||
|
final int gc;
|
||
|
final int shards;
|
||
|
final String equipment;
|
||
|
|
||
|
final List<Hero> heros;
|
||
|
|
||
|
Warband(this.nameAndRace, this.campaignPoints, this.objective, this.alignment, this.gc, this.shards, this.equipment, this.achievments, this.heros) {
|
||
|
this.race = this.nameAndRace['name'];
|
||
|
this.name = this.nameAndRace['race'];
|
||
|
}
|
||
|
|
||
|
static HashMap<String, String>_warbandNameAndRace(String nameAndRace) {
|
||
|
HashMap<String, String> nr = new HashMap();
|
||
|
RegExp re = new RegExp(r"(.*) \((.*)\)");
|
||
|
|
||
|
var matches = re.allMatches(nameAndRace);
|
||
|
nr['name'] = matches.toList().first.group(1).toString();
|
||
|
nr['race'] = matches.toList().first.group(2).toString();
|
||
|
|
||
|
return nr;
|
||
|
}
|
||
|
|
||
|
factory Warband.fromJson(YamlMap yaml) =>
|
||
|
_$WarbandFromJson(yaml);
|
||
|
}
|