Skip to content

Commit

Permalink
[Infrastructure] Added some sanity checks
Browse files Browse the repository at this point in the history
  • Loading branch information
Wolfteam committed Jul 22, 2021
1 parent 5c72d83 commit 0189609
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions lib/infrastructure/genshin_service.dart
Expand Up @@ -44,27 +44,43 @@ class GenshinServiceImpl implements GenshinService {
final jsonStr = await rootBundle.loadString(Assets.charactersDbPath);
final json = jsonDecode(jsonStr) as Map<String, dynamic>;
_charactersFile = CharactersFile.fromJson(json);
assert(
_charactersFile.characters.map((e) => e.key).toSet().length == _charactersFile.characters.length,
'All the character keys must be unique',
);
}

@override
Future<void> initWeapons() async {
final jsonStr = await rootBundle.loadString(Assets.weaponsDbPath);
final json = jsonDecode(jsonStr) as Map<String, dynamic>;
_weaponsFile = WeaponsFile.fromJson(json);
assert(
_weaponsFile.weapons.map((e) => e.key).toSet().length == _weaponsFile.weapons.length,
'All the weapon keys must be unique',
);
}

@override
Future<void> initArtifacts() async {
final jsonStr = await rootBundle.loadString(Assets.artifactsDbPath);
final json = jsonDecode(jsonStr) as Map<String, dynamic>;
_artifactsFile = ArtifactsFile.fromJson(json);
assert(
_artifactsFile.artifacts.map((e) => e.key).toSet().length == _artifactsFile.artifacts.length,
'All the artifact keys must be unique',
);
}

@override
Future<void> initMaterials() async {
final jsonStr = await rootBundle.loadString(Assets.materialsDbPath);
final json = jsonDecode(jsonStr) as Map<String, dynamic>;
_materialsFile = MaterialsFile.fromJson(json);
assert(
_materialsFile.materials.map((e) => e.key).toSet().length == _materialsFile.materials.length,
'All the material keys must be unique',
);
}

@override
Expand All @@ -79,20 +95,32 @@ class GenshinServiceImpl implements GenshinService {
final jsonStr = await rootBundle.loadString(Assets.monstersDbPath);
final json = jsonDecode(jsonStr) as Map<String, dynamic>;
_monstersFile = MonstersFile.fromJson(json);
assert(
_monstersFile.monsters.map((e) => e.key).toSet().length == _monstersFile.monsters.length,
'All the monster keys must be unique',
);
}

@override
Future<void> initGadgets() async {
final jsonStr = await rootBundle.loadString(Assets.gadgetsDbPath);
final json = jsonDecode(jsonStr) as Map<String, dynamic>;
_gadgetsFile = GadgetsFile.fromJson(json);
assert(
_gadgetsFile.gadgets.map((e) => e.key).toSet().length == _gadgetsFile.gadgets.length,
'All the gadgets keys must be unique',
);
}

@override
Future<void> initFurniture() async {
final jsonStr = await rootBundle.loadString(Assets.furnitureDbPath);
final json = jsonDecode(jsonStr) as Map<String, dynamic>;
_furnitureFile = FurnitureFile.fromJson(json);
assert(
_furnitureFile.furniture.map((e) => e.key).toSet().length == _furnitureFile.furniture.length,
'All the furniture keys must be unique',
);
}

@override
Expand Down

0 comments on commit 0189609

Please sign in to comment.