fromJson static method
Returns a new CharacterSchema instance and imports its values from
value if it's a Map, null otherwise.
Implementation
// ignore: prefer_constructors_over_static_methods
static CharacterSchema? 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 "CharacterSchema[$key]" is missing from JSON.');
assert(json[key] != null,
'Required key "CharacterSchema[$key]" has a null value in JSON.');
});
return true;
}());
return CharacterSchema(
name: mapValueOfType<String>(json, r'name')!,
account: mapValueOfType<String>(json, r'account')!,
skin: CharacterSkin.fromJson(json[r'skin'])!,
level: mapValueOfType<int>(json, r'level')!,
xp: mapValueOfType<int>(json, r'xp')!,
maxXp: mapValueOfType<int>(json, r'max_xp')!,
gold: mapValueOfType<int>(json, r'gold')!,
speed: mapValueOfType<int>(json, r'speed')!,
miningLevel: mapValueOfType<int>(json, r'mining_level')!,
miningXp: mapValueOfType<int>(json, r'mining_xp')!,
miningMaxXp: mapValueOfType<int>(json, r'mining_max_xp')!,
woodcuttingLevel: mapValueOfType<int>(json, r'woodcutting_level')!,
woodcuttingXp: mapValueOfType<int>(json, r'woodcutting_xp')!,
woodcuttingMaxXp: mapValueOfType<int>(json, r'woodcutting_max_xp')!,
fishingLevel: mapValueOfType<int>(json, r'fishing_level')!,
fishingXp: mapValueOfType<int>(json, r'fishing_xp')!,
fishingMaxXp: mapValueOfType<int>(json, r'fishing_max_xp')!,
weaponcraftingLevel:
mapValueOfType<int>(json, r'weaponcrafting_level')!,
weaponcraftingXp: mapValueOfType<int>(json, r'weaponcrafting_xp')!,
weaponcraftingMaxXp:
mapValueOfType<int>(json, r'weaponcrafting_max_xp')!,
gearcraftingLevel: mapValueOfType<int>(json, r'gearcrafting_level')!,
gearcraftingXp: mapValueOfType<int>(json, r'gearcrafting_xp')!,
gearcraftingMaxXp: mapValueOfType<int>(json, r'gearcrafting_max_xp')!,
jewelrycraftingLevel:
mapValueOfType<int>(json, r'jewelrycrafting_level')!,
jewelrycraftingXp: mapValueOfType<int>(json, r'jewelrycrafting_xp')!,
jewelrycraftingMaxXp:
mapValueOfType<int>(json, r'jewelrycrafting_max_xp')!,
cookingLevel: mapValueOfType<int>(json, r'cooking_level')!,
cookingXp: mapValueOfType<int>(json, r'cooking_xp')!,
cookingMaxXp: mapValueOfType<int>(json, r'cooking_max_xp')!,
alchemyLevel: mapValueOfType<int>(json, r'alchemy_level')!,
alchemyXp: mapValueOfType<int>(json, r'alchemy_xp')!,
alchemyMaxXp: mapValueOfType<int>(json, r'alchemy_max_xp')!,
hp: mapValueOfType<int>(json, r'hp')!,
maxHp: mapValueOfType<int>(json, r'max_hp')!,
haste: mapValueOfType<int>(json, r'haste')!,
criticalStrike: mapValueOfType<int>(json, r'critical_strike')!,
wisdom: mapValueOfType<int>(json, r'wisdom')!,
prospecting: mapValueOfType<int>(json, r'prospecting')!,
initiative: mapValueOfType<int>(json, r'initiative')!,
threat: mapValueOfType<int>(json, r'threat')!,
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')!,
dmg: mapValueOfType<int>(json, r'dmg')!,
dmgFire: mapValueOfType<int>(json, r'dmg_fire')!,
dmgEarth: mapValueOfType<int>(json, r'dmg_earth')!,
dmgWater: mapValueOfType<int>(json, r'dmg_water')!,
dmgAir: mapValueOfType<int>(json, r'dmg_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')!,
effects: StorageEffectSchema.listFromJson(json[r'effects']),
x: mapValueOfType<int>(json, r'x')!,
y: mapValueOfType<int>(json, r'y')!,
layer: MapLayer.fromJson(json[r'layer'])!,
mapId: mapValueOfType<int>(json, r'map_id')!,
cooldown: mapValueOfType<int>(json, r'cooldown')!,
cooldownExpiration: mapDateTime(json, r'cooldown_expiration', r''),
weaponSlot: mapValueOfType<String>(json, r'weapon_slot')!,
runeSlot: mapValueOfType<String>(json, r'rune_slot')!,
shieldSlot: mapValueOfType<String>(json, r'shield_slot')!,
helmetSlot: mapValueOfType<String>(json, r'helmet_slot')!,
bodyArmorSlot: mapValueOfType<String>(json, r'body_armor_slot')!,
legArmorSlot: mapValueOfType<String>(json, r'leg_armor_slot')!,
bootsSlot: mapValueOfType<String>(json, r'boots_slot')!,
ring1Slot: mapValueOfType<String>(json, r'ring1_slot')!,
ring2Slot: mapValueOfType<String>(json, r'ring2_slot')!,
amuletSlot: mapValueOfType<String>(json, r'amulet_slot')!,
artifact1Slot: mapValueOfType<String>(json, r'artifact1_slot')!,
artifact2Slot: mapValueOfType<String>(json, r'artifact2_slot')!,
artifact3Slot: mapValueOfType<String>(json, r'artifact3_slot')!,
utility1Slot: mapValueOfType<String>(json, r'utility1_slot')!,
utility1SlotQuantity:
mapValueOfType<int>(json, r'utility1_slot_quantity')!,
utility2Slot: mapValueOfType<String>(json, r'utility2_slot')!,
utility2SlotQuantity:
mapValueOfType<int>(json, r'utility2_slot_quantity')!,
bagSlot: mapValueOfType<String>(json, r'bag_slot')!,
task: mapValueOfType<String>(json, r'task')!,
taskType: mapValueOfType<String>(json, r'task_type')!,
taskProgress: mapValueOfType<int>(json, r'task_progress')!,
taskTotal: mapValueOfType<int>(json, r'task_total')!,
inventoryMaxItems: mapValueOfType<int>(json, r'inventory_max_items')!,
inventory: InventorySlot.listFromJson(json[r'inventory']),
);
}
return null;
}