Skip to content

Commit

Permalink
[Infrastructure] Added a method to retrieve the characters by region …
Browse files Browse the repository at this point in the history
…& gender
  • Loading branch information
Wolfteam committed May 23, 2022
1 parent e3c58a3 commit 781c076
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions lib/infrastructure/genshin_service.dart
Expand Up @@ -1105,6 +1105,23 @@ class GenshinServiceImpl implements GenshinService {
..sort((x, y) => y.quantity.compareTo(x.quantity));
}

@override
List<ChartGenderModel> getCharacterGendersForCharts() =>
RegionType.values.where((el) => el != RegionType.anotherWorld).map((e) => getCharacterGendersByRegionForCharts(e)).toList()
..sort((x, y) => y.maxCount.compareTo(x.maxCount));

@override
ChartGenderModel getCharacterGendersByRegionForCharts(RegionType regionType) {
if (regionType == RegionType.anotherWorld) {
throw Exception('Another world is not supported');
}

final characters = _charactersFile.characters.where((el) => !el.isComingSoon && el.region == regionType).toList();
final maleCount = characters.where((el) => !el.isFemale).length;
final femaleCount = characters.where((el) => el.isFemale).length;
return ChartGenderModel(regionType: regionType, maleCount: maleCount, femaleCount: femaleCount, maxCount: max(maleCount, femaleCount));
}

@override
List<ItemCommonWithName> getCharactersForItemsByRegion(RegionType regionType) {
if (regionType == RegionType.anotherWorld) {
Expand All @@ -1118,6 +1135,19 @@ class GenshinServiceImpl implements GenshinService {
..sort((x, y) => x.name.compareTo(y.name));
}

@override
List<ItemCommonWithName> getCharactersForItemsByRegionAndGender(RegionType regionType, bool onlyFemales) {
if (regionType == RegionType.anotherWorld) {
throw Exception('Another world is not supported');
}

return _charactersFile.characters.where((el) => !el.isComingSoon && el.region == regionType && el.isFemale == onlyFemales).map((e) {
final char = getCharacterForCard(e.key);
return ItemCommonWithName(e.key, char.image, char.name);
}).toList()
..sort((x, y) => x.name.compareTo(y.name));
}

//TODO: CALL THIS METHOD IN THE MAIN PAGE
@override
List<CharacterBirthdayModel> getCharacterBirthdays({int? month, int? day}) {
Expand Down

0 comments on commit 781c076

Please sign in to comment.