Skip to content

Commit

Permalink
Merge pull request #68 from Wolfteam/feature/game_codes_improvements
Browse files Browse the repository at this point in the history
feature/game_codes_improvements
  • Loading branch information
Wolfteam committed Jun 3, 2021
2 parents 1c2ec2e + 8bd1666 commit 4604b46
Show file tree
Hide file tree
Showing 36 changed files with 686 additions and 738 deletions.
547 changes: 0 additions & 547 deletions assets/db/game_codes.json

This file was deleted.

2 changes: 1 addition & 1 deletion assets/i18n/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -4436,7 +4436,7 @@
},
{
"key": "Mappa Mare",
"name": "Морская карта",
"name": "Морской атлас",
"description": "Привезённая иностранными торговцами в Ли Юэ карта морских течений и ветров.",
"refinement": "В течение 10 сек. после вызова элементальной реакции увелчивает бонус элементального урона на {{0}}%. Может складываться до 2 раз."
},
Expand Down
24 changes: 22 additions & 2 deletions lib/application/game_codes/game_codes_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import 'package:bloc/bloc.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:genshindb/domain/models/models.dart';
import 'package:genshindb/domain/services/data_service.dart';
import 'package:genshindb/domain/services/game_code_service.dart';
import 'package:genshindb/domain/services/network_service.dart';
import 'package:genshindb/domain/services/telemetry_service.dart';
import 'package:meta/meta.dart';

Expand All @@ -16,12 +18,29 @@ const _initialState = GameCodesState.loaded(workingGameCodes: [], expiredGameCod
class GameCodesBloc extends Bloc<GameCodesEvent, GameCodesState> {
final DataService _dataService;
final TelemetryService _telemetryService;
final GameCodeService _gameCodeService;
final NetworkService _networkService;

GameCodesBloc(this._dataService, this._telemetryService) : super(_initialState);
GameCodesBloc(this._dataService, this._telemetryService, this._gameCodeService, this._networkService) : super(_initialState);

@override
Stream<GameCodesState> mapEventToState(GameCodesEvent event) async* {
final s = await event.when(
if (event is _Refresh) {
final isInternetAvailable = await _networkService.isInternetAvailable();
if (!isInternetAvailable) {
yield state.copyWith.call(isInternetAvailable: false);
yield state.copyWith.call(isInternetAvailable: null);
return;
}
yield _initialState.copyWith.call(isBusy: true, workingGameCodes: [], expiredGameCodes: []);
final gameCodes = await _gameCodeService.getAllGameCodes();
await _dataService.saveGameCodes(gameCodes);

add(const GameCodesEvent.init());
return;
}

final s = await event.maybeWhen(
init: () async {
await _telemetryService.trackGameCodesOpened();
return _buildInitialState();
Expand All @@ -31,6 +50,7 @@ class GameCodesBloc extends Bloc<GameCodesEvent, GameCodesState> {
return _buildInitialState();
},
close: () async => _initialState,
orElse: () async => _initialState,
);

yield s;
Expand Down
2 changes: 2 additions & 0 deletions lib/application/game_codes/game_codes_event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,7 @@ abstract class GameCodesEvent with _$GameCodesEvent {
@required bool wasUsed,
}) = _MarkAsUsed;

const factory GameCodesEvent.refresh() = _Refresh;

const factory GameCodesEvent.close() = _Close;
}
2 changes: 2 additions & 0 deletions lib/application/game_codes/game_codes_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@ abstract class GameCodesState with _$GameCodesState {
const factory GameCodesState.loaded({
@required List<GameCodeModel> workingGameCodes,
@required List<GameCodeModel> expiredGameCodes,
@Default(false) bool isBusy,
bool isInternetAvailable,
}) = _Loaded;
}
2 changes: 1 addition & 1 deletion lib/domain/assets.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ class Assets {
static String artifactsDbPath = '$dbPath/artifacts.json';
static String materialsDbPath = '$dbPath/materials.json';
static String elementsDbPath = '$dbPath/elements.json';
static String gameCodesDbPath = '$dbPath/game_codes.json';
static String monstersDbPath = '$dbPath/monsters.json';
static String translationsBasePath = 'assets/i18n';

Expand Down Expand Up @@ -44,6 +43,7 @@ class Assets {

//Others
static String otherImgsBasePath = 'assets/others';
static String noImageAvailablePath = '$othersBasePath/$noImageAvailableName';

//Monsters
static String monstersImgsBasePath = 'assets/monsters';
Expand Down
31 changes: 0 additions & 31 deletions lib/domain/models/db/game_codes/game_codes_file.dart

This file was deleted.

3 changes: 2 additions & 1 deletion lib/domain/models/entities.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
export 'entities/calculator/calculator_character_skill.dart';
export 'entities/calculator/calculator_item.dart';
export 'entities/calculator/calculator_session.dart';
export 'entities/game_code/used_game_code.dart';
export 'entities/game_code/game_code.dart';
export 'entities/game_code/game_code_reward.dart';
export 'entities/inventory/inventory_item.dart';
export 'entities/inventory/inventory_used_item.dart';
export 'entities/tierlist/tierlist_item.dart';
26 changes: 26 additions & 0 deletions lib/domain/models/entities/game_code/game_code.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import 'package:hive/hive.dart';

part 'game_code.g.dart';

@HiveType(typeId: 6)
class GameCode extends HiveObject {
@HiveField(0)
final String code;

@HiveField(1)
DateTime usedOn;

@HiveField(2)
DateTime discoveredOn;

@HiveField(3)
DateTime expiredOn;

@HiveField(4)
bool isExpired;

@HiveField(5)
int region;

GameCode(this.code, this.usedOn, this.discoveredOn, this.expiredOn, this.isExpired, this.region);
}
17 changes: 17 additions & 0 deletions lib/domain/models/entities/game_code/game_code_reward.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import 'package:hive/hive.dart';

part 'game_code_reward.g.dart';

@HiveType(typeId: 8)
class GameCodeReward extends HiveObject {
@HiveField(0)
final int gameCodeKey;

@HiveField(1)
final String itemKey;

@HiveField(2)
final int quantity;

GameCodeReward(this.gameCodeKey, this.itemKey, this.quantity);
}
14 changes: 0 additions & 14 deletions lib/domain/models/entities/game_code/used_game_code.dart

This file was deleted.

11 changes: 10 additions & 1 deletion lib/domain/models/game_codes/game_code_model.dart
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
import 'package:flutter/cupertino.dart';
import 'package:genshindb/domain/enums/enums.dart';
import 'package:genshindb/domain/models/models.dart';

class GameCodeModel {
final String code;
final AppServerResetTimeType region;

final DateTime discoveredOn;
final DateTime expiredOn;
final bool isExpired;

final bool isUsed;
final List<ItemAscensionMaterialModel> rewards;

GameCodeModel({
@required this.code,
@required this.isExpired,
@required this.isUsed,
@required this.rewards,
@required this.isExpired,
@required this.discoveredOn,
this.expiredOn,
this.region,
});
}
1 change: 0 additions & 1 deletion lib/domain/models/models.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ export 'db/characters/characters_file.dart';
export 'db/elements/element_debuff_file_model.dart';
export 'db/elements/element_reaction_file_model.dart';
export 'db/elements/elements_file.dart';
export 'db/game_codes/game_codes_file.dart';
export 'db/materials/material_file_model.dart';
export 'db/materials/materials_file.dart';
export 'db/monsters/monster_file_model.dart';
Expand Down
6 changes: 5 additions & 1 deletion lib/domain/services/data_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,11 @@ abstract class DataService {

List<GameCodeModel> getAllGameCodes();

List<String> getAllUsedGameCodes();
Future<void> saveGameCodes(List<GameCodeModel> items);

Future<void> saveGameCodeRewards(int gameCodeKey, List<ItemAscensionMaterialModel> rewards);

Future<void> deleteAllGameCodeRewards(int gameCodeKey);

Future<void> markCodeAsUsed(String code, {bool wasUsed = true});

Expand Down
5 changes: 5 additions & 0 deletions lib/domain/services/game_code_service.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import 'package:genshindb/domain/models/models.dart';

abstract class GameCodeService {
Future<List<GameCodeModel>> getAllGameCodes();
}
3 changes: 0 additions & 3 deletions lib/domain/services/genshin_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ abstract class GenshinService {
Future<void> initArtifacts();
Future<void> initMaterials();
Future<void> initElements();
Future<void> initGameCodes();
Future<void> initMonsters();
Future<void> initTranslations(AppLanguageType languageType);

Expand Down Expand Up @@ -60,8 +59,6 @@ abstract class GenshinService {
int getServerDay(AppServerResetTimeType type);
DateTime getServerDate(AppServerResetTimeType type);

List<GameCodeFileModel> getAllGameCodes();

List<String> getUpcomingKeys();

MonsterFileModel getMonster(String key);
Expand Down
25 changes: 25 additions & 0 deletions lib/domain/utils/date_utils.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import 'package:intl/intl.dart';

class DateUtils {
static const String defaultFormat = 'dd/MM/yyyy hh:mm:ss a';
static const String twentyFourHoursFormat = 'dd/MM/yyyy HH:mm:ss';
static const String dayMonthYearFormat = 'dd/MM/yyyy';

static String formatDate(
DateTime date, {
String locale,
String format = defaultFormat,
}) {
if (date == null) {
return 'N/A';
}
final formatter = DateFormat(format, locale);
final formatted = formatter.format(date);
return formatted;
}

static String formatDateMilitaryTime(DateTime date, {bool useTwentyFourHoursFormat = false}) {
final format = useTwentyFourHoursFormat ? twentyFourHoursFormat : defaultFormat;
return formatDate(date, format: format);
}
}

0 comments on commit 4604b46

Please sign in to comment.