Skip to content

Commit

Permalink
Added a weapon substat filter to the weapons page.
Browse files Browse the repository at this point in the history
The weapon's substats are now shown in the weapon card
  • Loading branch information
Wolfteam committed Jan 1, 2021
1 parent 90ca018 commit d562346
Show file tree
Hide file tree
Showing 16 changed files with 127 additions and 54 deletions.
19 changes: 19 additions & 0 deletions lib/bloc/weapons/weapons_bloc.dart
Expand Up @@ -4,6 +4,7 @@ import 'package:bloc/bloc.dart';
import 'package:freezed_annotation/freezed_annotation.dart';

import '../../common/enums/sort_direction_type.dart';
import '../../common/enums/stat_type.dart';
import '../../common/enums/weapon_filter_type.dart';
import '../../common/enums/weapon_type.dart';
import '../../models/models.dart';
Expand Down Expand Up @@ -46,19 +47,23 @@ class WeaponsBloc extends Bloc<WeaponsEvent, WeaponsState> {
rarity: currentState.rarity,
sortDirectionType: currentState.sortDirectionType,
weaponTypes: currentState.weaponTypes,
weaponSubStatType: currentState.weaponSubStatType,
),
weaponSubStatTypeChanged: (e) => currentState.copyWith.call(tempWeaponSubStatType: e.subStatType),
applyFilterChanges: (_) => _buildInitialState(
search: currentState.search,
weaponFilterType: currentState.tempWeaponFilterType,
rarity: currentState.tempRarity,
sortDirectionType: currentState.tempSortDirectionType,
weaponTypes: currentState.tempWeaponTypes,
weaponSubStatType: currentState.tempWeaponSubStatType,
),
cancelChanges: (_) => currentState.copyWith.call(
tempWeaponFilterType: currentState.weaponFilterType,
tempRarity: currentState.rarity,
tempSortDirectionType: currentState.sortDirectionType,
tempWeaponTypes: currentState.weaponTypes,
tempWeaponSubStatType: currentState.weaponSubStatType,
),
);

Expand All @@ -71,6 +76,7 @@ class WeaponsBloc extends Bloc<WeaponsEvent, WeaponsState> {
int rarity = 0,
WeaponFilterType weaponFilterType = WeaponFilterType.rarity,
SortDirectionType sortDirectionType = SortDirectionType.asc,
StatType weaponSubStatType = StatType.all,
}) {
final isLoaded = state is _LoadedState;
var data = _genshinService.getWeaponsForCard();
Expand All @@ -90,6 +96,8 @@ class WeaponsBloc extends Bloc<WeaponsEvent, WeaponsState> {
sortDirectionType: sortDirectionType,
tempSortDirectionType: sortDirectionType,
showWeaponDetails: _settingsService.showWeaponDetails,
weaponSubStatType: weaponSubStatType,
tempWeaponSubStatType: weaponSubStatType,
);
}

Expand All @@ -105,6 +113,10 @@ class WeaponsBloc extends Bloc<WeaponsEvent, WeaponsState> {
data = data.where((el) => weaponTypes.contains(el.type)).toList();
}

if (weaponSubStatType != StatType.all) {
data = data.where((el) => el.subStatType == weaponSubStatType).toList();
}

_sortData(data, weaponFilterType, sortDirectionType);

final s = currentState.copyWith.call(
Expand Down Expand Up @@ -150,6 +162,13 @@ class WeaponsBloc extends Bloc<WeaponsEvent, WeaponsState> {
data.sort((x, y) => y.rarity.compareTo(x.rarity));
}
break;
case WeaponFilterType.subStat:
if (sortDirectionType == SortDirectionType.asc) {
data.sort((x, y) => x.subStatValue.compareTo(y.subStatValue));
} else {
data.sort((x, y) => y.subStatValue.compareTo(x.subStatValue));
}
break;
default:
break;
}
Expand Down
1 change: 1 addition & 0 deletions lib/bloc/weapons/weapons_event.dart
Expand Up @@ -12,6 +12,7 @@ abstract class WeaponsEvent with _$WeaponsEvent {
const factory WeaponsEvent.weaponFilterTypeChanged(WeaponFilterType filterType) = _WeaponFilterChanged;
const factory WeaponsEvent.applyFilterChanges() = _ApplyFilterChanges;
const factory WeaponsEvent.sortDirectionTypeChanged(SortDirectionType sortDirectionType) = _SortDirectionTypeChanged;
const factory WeaponsEvent.weaponSubStatTypeChanged(StatType subStatType) = _WeaponSubStatTypeChanged;

const factory WeaponsEvent.cancelChanges() = _CancelChanges;
}
2 changes: 2 additions & 0 deletions lib/bloc/weapons/weapons_state.dart
Expand Up @@ -15,5 +15,7 @@ abstract class WeaponsState with _$WeaponsState {
@required WeaponFilterType tempWeaponFilterType,
@required SortDirectionType sortDirectionType,
@required SortDirectionType tempSortDirectionType,
@required StatType weaponSubStatType,
@required StatType tempWeaponSubStatType,
}) = _LoadedState;
}
1 change: 1 addition & 0 deletions lib/common/enums/stat_type.dart
@@ -1,4 +1,5 @@
enum StatType {
all,
none,
atk,
atkPercentage,
Expand Down
1 change: 1 addition & 0 deletions lib/common/enums/weapon_filter_type.dart
Expand Up @@ -2,4 +2,5 @@ enum WeaponFilterType {
atk,
name,
rarity,
subStat,
}
4 changes: 4 additions & 0 deletions lib/common/extensions/i18n_extensions.dart
Expand Up @@ -86,6 +86,8 @@ extension I18nExtensions on S {

String translateStatType(StatType type, double value) {
switch (type) {
case StatType.all:
return all;
case StatType.atk:
return atk(value);
case StatType.atkPercentage:
Expand Down Expand Up @@ -208,6 +210,8 @@ extension I18nExtensions on S {
return name;
case WeaponFilterType.rarity:
return rarity;
case WeaponFilterType.subStat:
return subStat;
default:
throw Exception('Invalid weapon filter type = $type');
}
Expand Down
11 changes: 6 additions & 5 deletions lib/generated/intl/messages_en.dart
Expand Up @@ -23,25 +23,25 @@ class MessageLookup extends MessageLookupByLibrary {

static m1(value) => "${value} ATK";

static m2(value) => "${value} ATK%";
static m2(value) => "${value} ATK %";

static m3(value) => "Constellation ${value}";

static m4(value) => "${value} CRIT ATK";

static m5(value) => "${value} CRIT DMG%";
static m5(value) => "${value} CRIT DMG %";

static m6(value) => "${value} CRIT Rate";

static m7(value) => "${value} CRIT Rate%";
static m7(value) => "${value} CRIT Rate %";

static m8(value) => "${value} DEF%";
static m8(value) => "${value} DEF %";

static m9(value) => "${value} Elementary Master";

static m10(value) => "${value} Energy Recharge %";

static m11(value) => "${value} HP%";
static m11(value) => "${value} HP %";

static m12(value) => "${value} PHYS DMG Bonus";

Expand Down Expand Up @@ -175,6 +175,7 @@ class MessageLookup extends MessageLookupByLibrary {
"sortType" : MessageLookupByLibrary.simpleMessage("Sort type"),
"spanish" : MessageLookupByLibrary.simpleMessage("Spanish"),
"starglitterExchange" : MessageLookupByLibrary.simpleMessage("Starglitter Exchange"),
"subStat" : MessageLookupByLibrary.simpleMessage("Sub. Stat"),
"sunday" : MessageLookupByLibrary.simpleMessage("Sunday"),
"support" : MessageLookupByLibrary.simpleMessage("Support"),
"supportMsg" : MessageLookupByLibrary.simpleMessage("I made this app in my free time and it is also open source. If you would like to help me, report an issue, have an idea, want a feature to be implemented, etc, please open an issue in my Github:"),
Expand Down
11 changes: 6 additions & 5 deletions lib/generated/intl/messages_es_ES.dart
Expand Up @@ -23,25 +23,25 @@ class MessageLookup extends MessageLookupByLibrary {

static m1(value) => "${value} ATK";

static m2(value) => "${value} ATK%";
static m2(value) => "${value} ATK %";

static m3(value) => "Constelación ${value}";

static m4(value) => "${value} CRIT ATK";

static m5(value) => "${value} CRIT DMG%";
static m5(value) => "${value} CRIT DMG %";

static m6(value) => "${value} CRIT Rate";

static m7(value) => "${value} CRIT Rate%";
static m7(value) => "${value} CRIT Rate %";

static m8(value) => "${value} DEF%";
static m8(value) => "${value} DEF %";

static m9(value) => "${value} Maestría Elemental";

static m10(value) => "${value} Recarga de Energía %";

static m11(value) => "${value} HP%";
static m11(value) => "${value} HP %";

static m12(value) => "${value} PHYS DMG Bonus";

Expand Down Expand Up @@ -175,6 +175,7 @@ class MessageLookup extends MessageLookupByLibrary {
"sortType" : MessageLookupByLibrary.simpleMessage("Tipo de ordenamiento"),
"spanish" : MessageLookupByLibrary.simpleMessage("Español"),
"starglitterExchange" : MessageLookupByLibrary.simpleMessage("Starglitter Exchange"),
"subStat" : MessageLookupByLibrary.simpleMessage("Sub. Stat"),
"sunday" : MessageLookupByLibrary.simpleMessage("Domingo"),
"support" : MessageLookupByLibrary.simpleMessage("Soporte"),
"supportMsg" : MessageLookupByLibrary.simpleMessage("Hice esta aplicación en mi tiempo libre y también es de código abierto. Si deseas ayudarme, informar de un problema, tienes una idea, deseas que se implemente una funcionalidad, etc., crea un issue en mi Github:"),
Expand Down
30 changes: 20 additions & 10 deletions lib/generated/l10n.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 7 additions & 6 deletions lib/l10n/intl_en.arb
Expand Up @@ -11,14 +11,14 @@
"catalyst": "Catalyst",
"none": "None",
"atk": "{value} ATK",
"atkPercentage": "{value} ATK%",
"defPercentage": "{value} DEF%",
"atkPercentage": "{value} ATK %",
"defPercentage": "{value} DEF %",
"critAtk": "{value} CRIT ATK",
"critRate": "{value} CRIT Rate",
"critRatePercentage": "{value} CRIT Rate%",
"critDmgPercentage": "{value} CRIT DMG%",
"critRatePercentage": "{value} CRIT Rate %",
"critDmgPercentage": "{value} CRIT DMG %",
"elementaryMaster": "{value} Elementary Master",
"hpPercentage": "{value} HP%",
"hpPercentage": "{value} HP %",
"physDmgPercentage": "{value} PHYS DMG %",
"physDmgBonus": "{value} PHYS DMG Bonus",
"energyRechargePercentage": "{value} Energy Recharge %",
Expand Down Expand Up @@ -141,5 +141,6 @@
"generalSettings": "General settings",
"showCharacterDetails": "Show character details",
"showWeaponDetails": "Show weapon details",
"quest": "Quest"
"quest": "Quest",
"subStat": "Sub. Stat"
}
13 changes: 7 additions & 6 deletions lib/l10n/intl_es_ES.arb
Expand Up @@ -11,14 +11,14 @@
"catalyst": "Catalizador",
"none": "Ninguno",
"atk": "{value} ATK",
"atkPercentage": "{value} ATK%",
"defPercentage": "{value} DEF%",
"atkPercentage": "{value} ATK %",
"defPercentage": "{value} DEF %",
"critAtk": "{value} CRIT ATK",
"critRate": "{value} CRIT Rate",
"critRatePercentage": "{value} CRIT Rate%",
"critDmgPercentage": "{value} CRIT DMG%",
"critRatePercentage": "{value} CRIT Rate %",
"critDmgPercentage": "{value} CRIT DMG %",
"elementaryMaster": "{value} Maestría Elemental",
"hpPercentage": "{value} HP%",
"hpPercentage": "{value} HP %",
"physDmgPercentage": "{value} PHYS DMG %",
"physDmgBonus": "{value} PHYS DMG Bonus",
"energyRechargePercentage": "{value} Recarga de Energía %",
Expand Down Expand Up @@ -140,5 +140,6 @@
"generalSettings": "General settings",
"showCharacterDetails": "Mostrar el detalle de los personajes",
"showWeaponDetails": "Mostrar el detalle de las armas",
"quest": "Misión"
"quest": "Misión",
"subStat": "Sub. Stat"
}
8 changes: 7 additions & 1 deletion lib/models/weapons/weapon_card_model.dart
@@ -1,5 +1,6 @@
import 'package:flutter/widgets.dart';

import '../../common/enums/stat_type.dart';
import '../../common/enums/weapon_type.dart';

class WeaponCardModel {
Expand All @@ -8,11 +9,16 @@ class WeaponCardModel {
final int rarity;
final int baseAtk;
final WeaponType type;
WeaponCardModel({
final StatType subStatType;
final double subStatValue;

const WeaponCardModel({
@required this.image,
@required this.name,
@required this.rarity,
@required this.baseAtk,
@required this.type,
@required this.subStatType,
@required this.subStatValue,
});
}
4 changes: 4 additions & 0 deletions lib/services/genshing_service.dart
Expand Up @@ -173,6 +173,8 @@ class GenshinServiceImpl implements GenshinService {
name: translation.name,
rarity: e.rarity,
type: e.type,
subStatType: e.secondaryStat,
subStatValue: e.secondaryStatValue,
);
},
).toList();
Expand All @@ -188,6 +190,8 @@ class GenshinServiceImpl implements GenshinService {
name: translation.name,
rarity: weapon.rarity,
type: weapon.type,
subStatType: weapon.secondaryStat,
subStatValue: weapon.secondaryStatValue,
);
}

Expand Down
2 changes: 2 additions & 0 deletions lib/ui/pages/weapons_page.dart
Expand Up @@ -60,6 +60,8 @@ class _WeaponsPageState extends State<WeaponsPage> with AutomaticKeepAliveClient
name: weapon.name,
rarity: weapon.rarity,
type: weapon.type,
subStatType: weapon.subStatType,
subStatValue: weapon.subStatValue,
);
},
itemCount: weapons.length,
Expand Down

0 comments on commit d562346

Please sign in to comment.