Skip to content

Commit

Permalink
[Infrastructure] Bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Wolfteam committed May 27, 2022
1 parent e2fc9ba commit 05119f9
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 44 deletions.
7 changes: 3 additions & 4 deletions lib/application/home/home_bloc.dart
Expand Up @@ -34,13 +34,12 @@ class HomeBloc extends Bloc<HomeEvent, HomeState> {
}

HomeState _buildInitialState(int day) {
final now = DateTime.now();
final charMaterials = _genshinService.getCharacterAscensionMaterials(day);
final weaponMaterials = _genshinService.getWeaponAscensionMaterials(day);
final charsForBirthday = _genshinService
.getCharactersForBirthday(DateTime.now())
.map(
(e) => ItemCommon(e.key, Assets.getCharacterPath(e.image)),
)
.getCharacterBirthdays(month: now.month, day: now.day)
.map((e) => ItemCommon(e.key, Assets.getCharacterPath(e.image)))
.toList();
final dayName = _localeService.getDayNameFromDay(day);

Expand Down
1 change: 1 addition & 0 deletions lib/domain/models/characters/character_card_model.dart
Expand Up @@ -17,5 +17,6 @@ class CharacterCardModel with _$CharacterCardModel {
required List<String> materials,
required CharacterRoleType roleType,
required RegionType regionType,
required StatType subStatType,
}) = _CharacterCardModel;
}
1 change: 0 additions & 1 deletion lib/domain/services/genshin_service.dart
Expand Up @@ -17,7 +17,6 @@ abstract class GenshinService {
List<CharacterCardModel> getCharactersForCard();
CharacterCardModel getCharacterForCard(String key);
CharacterFileModel getCharacter(String key);
List<CharacterFileModel> getCharactersForBirthday(DateTime date);
List<TierListRowModel> getDefaultCharacterTierList(List<int> colors);
List<String> getUpcomingCharactersKeys();
List<CharacterSkillStatModel> getCharacterSkillStats(List<CharacterFileSkillStatModel> skillStats, List<String> statsTranslations);
Expand Down
72 changes: 36 additions & 36 deletions lib/infrastructure/genshin_service.dart
Expand Up @@ -133,22 +133,6 @@ class GenshinServiceImpl implements GenshinService {
return _charactersFile.characters.firstWhere((element) => element.key == key);
}

@override
List<CharacterFileModel> getCharactersForBirthday(DateTime date) {
return _charactersFile.characters.where((char) {
if (char.isComingSoon) {
return false;
}

if (char.birthday.isNullEmptyOrWhitespace) {
return false;
}

final charBirthday = _localeService.getCharBirthDate(char.birthday);
return charBirthday.day == date.day && charBirthday.month == date.month;
}).toList();
}

@override
List<TierListRowModel> getDefaultCharacterTierList(List<int> colors) {
assert(colors.length == 7);
Expand Down Expand Up @@ -887,6 +871,9 @@ class GenshinServiceImpl implements GenshinService {

@override
List<BannerHistoryPeriodModel> getBanners(double version) {
if (version < getBannerHistoryVersions(SortDirectionType.asc).first) {
throw Exception('Version = $version is not valid');
}
final banners = _bannerHistoryFile.banners
.where((el) => el.version == version)
.map(
Expand Down Expand Up @@ -922,10 +909,6 @@ class GenshinServiceImpl implements GenshinService {
.toList()
..sort((x, y) => x.from.compareTo(y.from));

if (banners.isEmpty) {
throw Exception('Banners associated to version = $version were not found');
}

return banners;
}

Expand Down Expand Up @@ -1015,6 +998,19 @@ class GenshinServiceImpl implements GenshinService {

@override
List<ChartElementItemModel> getElementsForCharts(double fromVersion, double untilVersion) {
final allVersions = getBannerHistoryVersions(SortDirectionType.asc);
if (fromVersion < allVersions.first) {
throw Exception('The fromVersion = $fromVersion is not valid');
}

if (untilVersion > allVersions.last) {
throw Exception('The untilVersion = $untilVersion is not valid');
}

if (fromVersion > untilVersion) {
throw Exception('The fromVersion = $fromVersion cannot be greater than untilVersion = $untilVersion');
}

final banners = _bannerHistoryFile.banners
.where((el) => el.type == BannerHistoryItemType.character && el.version >= fromVersion && el.version <= untilVersion)
.toList()
Expand Down Expand Up @@ -1064,9 +1060,23 @@ class GenshinServiceImpl implements GenshinService {
}
}

double from = fromVersion;
while (from <= untilVersion) {
for (final chart in charts) {
if (!chart.points.any((el) => el.x == from)) {
chart.points.add(Point<double>(from, 0));
}
}
from = (from + gameVersionIncrementsBy).truncateToDecimalPlaces();
}

for (final chart in charts) {
chart.points.sort((x, y) => x.x.compareTo(y.x));
}

assert(charts.isNotEmpty, 'Element chart items must not be empty');

return charts;
return charts..sort((x, y) => x.type.index.compareTo(y.type.index));
}

@override
Expand All @@ -1078,18 +1088,9 @@ class GenshinServiceImpl implements GenshinService {
final stats = itemType == ItemType.character ? getCharacterPossibleAscensionStats() : getWeaponPossibleAscensionStats();
return stats.map(
(stat) {
int count = 0;
switch (itemType) {
case ItemType.character:
count = _charactersFile.characters.where((el) => !el.isComingSoon && el.subStatType == stat).length;
break;
case ItemType.weapon:
count = _weaponsFile.weapons.where((el) => !el.isComingSoon && el.secondaryStat == stat).length;
break;
default:
throw Exception('ItemType = $itemType is not Not supported');
}

final count = itemType == ItemType.character
? _charactersFile.characters.where((el) => !el.isComingSoon && el.subStatType == stat).length
: _weaponsFile.weapons.where((el) => !el.isComingSoon && el.secondaryStat == stat).length;
return ChartAscensionStatModel(type: stat, itemType: itemType, quantity: count);
},
).toList()
Expand Down Expand Up @@ -1148,7 +1149,6 @@ class GenshinServiceImpl implements GenshinService {
..sort((x, y) => x.name.compareTo(y.name));
}

//TODO: CALL THIS METHOD IN THE MAIN PAGE
@override
List<CharacterBirthdayModel> getCharacterBirthdays({int? month, int? day}) {
if (month == null && day == null) {
Expand Down Expand Up @@ -1192,7 +1192,6 @@ class GenshinServiceImpl implements GenshinService {

return true;
}).map((e) {
//TODO: CHECK BENNET
final char = getCharacterForCard(e.key);
final birthday = _localeService.getCharBirthDate(e.birthday, useCurrentYear: true);
final now = DateTime.now();
Expand Down Expand Up @@ -1230,7 +1229,7 @@ class GenshinServiceImpl implements GenshinService {
);
break;
default:
throw Exception('Invalid statType = $itemType');
throw Exception('Invalid itemType = $itemType');
}
return items..sort((x, y) => x.name.compareTo(y.name));
}
Expand Down Expand Up @@ -1268,6 +1267,7 @@ class GenshinServiceImpl implements GenshinService {
isNew: character.isNew,
roleType: character.role,
regionType: character.region,
subStatType: character.subStatType,
);
}

Expand Down
15 changes: 12 additions & 3 deletions lib/infrastructure/locale_service.dart
Expand Up @@ -5,6 +5,7 @@ import 'package:shiori/domain/extensions/string_extensions.dart';
import 'package:shiori/domain/models/models.dart';
import 'package:shiori/domain/services/locale_service.dart';
import 'package:shiori/domain/services/settings_service.dart';
import 'package:shiori/domain/utils/date_utils.dart';

class LocaleServiceImpl implements LocaleService {
final SettingsService _settingsService;
Expand All @@ -24,13 +25,21 @@ class LocaleServiceImpl implements LocaleService {
final format = DateFormat('MM/dd/yyyy', locale);
//The format is in MM/dd, I use 2024 since that is a leap-year
final now = DateTime.now();
//TODO: TEST THIS WITH BENNET SINCE THE NOW DATE MAY NOT BE A LEAP YEAR
final year = useCurrentYear ? now.year : 2024;
final charBirthday = format.parse('$birthday/$year');
DateTime charBirthday = format.parse('$birthday/$year');
if (!useCurrentYear) {
return charBirthday;
}
//TODO: TEST THIS WITH BENNET
final split = birthday.split('/');
final expectedMonth = int.parse(split.first);
final expectedDay = int.parse(split.last);

//leap year occurred
if (expectedMonth != charBirthday.month || expectedDay != charBirthday.day) {
final newDay = DateUtils.getLastDayOfMonth(expectedMonth);
charBirthday = DateTime(charBirthday.year, expectedMonth, newDay);
}

if (charBirthday.isBefore(now)) {
return charBirthday.add(const Duration(days: 365));
}
Expand Down

0 comments on commit 05119f9

Please sign in to comment.