Skip to content

Commit

Permalink
[Infrastructure] Added some methods to retrieve the monsters from db
Browse files Browse the repository at this point in the history
  • Loading branch information
Wolfteam committed Mar 28, 2021
1 parent 3a1c065 commit bf595e1
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions lib/infrastructure/genshin_service.dart
Expand Up @@ -18,6 +18,7 @@ class GenshinServiceImpl implements GenshinService {
MaterialsFile _materialsFile;
ElementsFile _elementsFile;
GameCodesFile _gameCodesFile;
MonstersFile _monstersFile;

GenshinServiceImpl(this._localeService);

Expand All @@ -30,6 +31,7 @@ class GenshinServiceImpl implements GenshinService {
initMaterials(),
initElements(),
initGameCodes(),
initMonsters(),
initTranslations(languageType),
]);
}
Expand Down Expand Up @@ -76,6 +78,13 @@ class GenshinServiceImpl implements GenshinService {
_gameCodesFile = GameCodesFile.fromJson(json);
}

@override
Future<void> initMonsters() async {
final jsonStr = await rootBundle.loadString(Assets.monstersDbPath);
final json = jsonDecode(jsonStr) as Map<String, dynamic>;
_monstersFile = MonstersFile.fromJson(json);
}

@override
Future<void> initTranslations(AppLanguageType languageType) async {
final transJsonStr = await rootBundle.loadString(Assets.getTranslationPath(languageType));
Expand Down Expand Up @@ -498,6 +507,27 @@ class GenshinServiceImpl implements GenshinService {
@override
List<String> getUpcomingKeys() => getUpcomingCharactersKeys() + getUpcomingWeaponsKeys();

@override
MonsterFileModel getMonster(String key) {
return _monstersFile.monsters.firstWhere((el) => el.key == key);
}

@override
MonsterFileModel getMonsterByImg(String image) {
return _monstersFile.monsters.firstWhere((el) => el.fullImagePath == image);
}

@override
List<MonsterCardModel> getAllMonstersForCard() {
return _monstersFile.monsters.map((e) => _toMonsterForCard(e)).toList();
}

@override
MonsterCardModel getMonsterForCardByImg(String image) {
final monster = _monstersFile.monsters.firstWhere((el) => el.fullImagePath == image);
return _toMonsterForCard(monster);
}

List<ItemAscensionMaterialModel> _getMaterialsToUse(
List<ItemAscensionMaterialModel> materials, {
List<MaterialType> ignore = const [MaterialType.currency],
Expand Down Expand Up @@ -589,4 +619,15 @@ class GenshinServiceImpl implements GenshinService {
hasSiblings: material.hasSiblings,
);
}

MonsterCardModel _toMonsterForCard(MonsterFileModel monster) {
final translation = _translationFile.monsters.firstWhere((el) => el.key == monster.key);
return MonsterCardModel(
key: monster.key,
image: monster.fullImagePath,
name: translation.name,
type: monster.type,
isComingSoon: monster.isComingSoon,
);
}
}

0 comments on commit bf595e1

Please sign in to comment.