fromJson static method
Returns a new MonsterSchema instance and imports its values from
value if it's a Map, null otherwise.
Implementation
// ignore: prefer_constructors_over_static_methods
static MonsterSchema? fromJson(dynamic value) {
if (value is Map) {
final json = value.cast<String, dynamic>();
// Ensure that the map contains the required keys.
// Note 1: the values aren't checked for validity beyond being non-null.
// Note 2: this code is stripped in release mode!
assert(() {
requiredKeys.forEach((key) {
assert(json.containsKey(key),
'Required key "MonsterSchema[$key]" is missing from JSON.');
assert(json[key] != null,
'Required key "MonsterSchema[$key]" has a null value in JSON.');
});
return true;
}());
return MonsterSchema(
name: mapValueOfType<String>(json, r'name')!,
code: mapValueOfType<String>(json, r'code')!,
level: mapValueOfType<int>(json, r'level')!,
type: MonsterType.fromJson(json[r'type'])!,
hp: mapValueOfType<int>(json, r'hp')!,
attackFire: mapValueOfType<int>(json, r'attack_fire')!,
attackEarth: mapValueOfType<int>(json, r'attack_earth')!,
attackWater: mapValueOfType<int>(json, r'attack_water')!,
attackAir: mapValueOfType<int>(json, r'attack_air')!,
resFire: mapValueOfType<int>(json, r'res_fire')!,
resEarth: mapValueOfType<int>(json, r'res_earth')!,
resWater: mapValueOfType<int>(json, r'res_water')!,
resAir: mapValueOfType<int>(json, r'res_air')!,
criticalStrike: mapValueOfType<int>(json, r'critical_strike')!,
initiative: mapValueOfType<int>(json, r'initiative')!,
effects: SimpleEffectSchema.listFromJson(json[r'effects']),
minGold: mapValueOfType<int>(json, r'min_gold')!,
maxGold: mapValueOfType<int>(json, r'max_gold')!,
drops: DropRateSchema.listFromJson(json[r'drops']),
);
}
return null;
}