Skip to content

Commit

Permalink
Weapon asc. mat. are now rendered with a sliverlist.
Browse files Browse the repository at this point in the history
Minor improvements.
  • Loading branch information
Wolfteam committed Dec 29, 2020
1 parent 0a5c944 commit dc44576
Show file tree
Hide file tree
Showing 12 changed files with 210 additions and 78 deletions.
36 changes: 24 additions & 12 deletions assets/db/materials.json
Expand Up @@ -8,7 +8,8 @@
"type": "talents",
"days": [
1,
4
4,
7
]
},
{
Expand All @@ -19,7 +20,8 @@
"type": "talents",
"days": [
1,
4
4,
7
]
},
{
Expand All @@ -30,7 +32,8 @@
"type": "talents",
"days": [
2,
5
5,
7
]
},
{
Expand All @@ -41,7 +44,8 @@
"type": "talents",
"days": [
2,
5
5,
7
]
},
{
Expand All @@ -52,7 +56,8 @@
"type": "talents",
"days": [
3,
6
6,
7
]
},
{
Expand All @@ -63,7 +68,8 @@
"type": "talents",
"days": [
3,
6
6,
7
]
},
{
Expand Down Expand Up @@ -148,7 +154,8 @@
"type": "weaponPrimary",
"days": [
1,
4
4,
7
]
},
{
Expand All @@ -159,7 +166,8 @@
"type": "weaponPrimary",
"days": [
1,
4
4,
7
]
},
{
Expand All @@ -170,7 +178,8 @@
"type": "weaponPrimary",
"days": [
2,
5
5,
7
]
},
{
Expand All @@ -181,7 +190,8 @@
"type": "weaponPrimary",
"days": [
2,
5
5,
7
]
},
{
Expand All @@ -192,7 +202,8 @@
"type": "weaponPrimary",
"days": [
3,
6
6,
7
]
},
{
Expand All @@ -203,7 +214,8 @@
"type": "weaponPrimary",
"days": [
3,
6
6,
7
]
}
]
Expand Down
55 changes: 32 additions & 23 deletions lib/bloc/weapon/weapon_bloc.dart
Expand Up @@ -23,34 +23,43 @@ class WeaponBloc extends Bloc<WeaponEvent, WeaponState> {
) async* {
yield const WeaponState.loading();
final s = event.when(
loadWeapon: (name) {
loadFromImg: (img) {
final weapon = _genshinService.getWeaponByImg(img);
final translation = _genshinService.getWeaponTranslation(weapon.name);
return _buildInitialState(weapon, translation);
},
loadFromName: (name) {
final weapon = _genshinService.getWeapon(name);
final translation = _genshinService.getWeaponTranslation(name);
return WeaponState.loaded(
name: weapon.name,
weaponType: weapon.type,
fullImage: weapon.fullImagePath,
rarity: weapon.rarity,
atk: weapon.atk,
secondaryStat: weapon.secondaryStat,
secondaryStatValue: weapon.secondaryStatValue,
description: translation.description,
locationType: weapon.location,
ascentionMaterials: weapon.ascentionMaterials,
refinements: weapon.refinements.map(
(e) {
var description = translation.refinement;
for (var i = 0; i < e.values.length; i++) {
description = description.replaceFirst('{{$i}}', '${e.values[i]}');
}

return WeaponFileRefinementModel(level: e.level, description: description);
},
).toList(),
);
return _buildInitialState(weapon, translation);
},
);

yield s;
}

WeaponState _buildInitialState(WeaponFileModel weapon, TranslationWeaponFile translation) {
return WeaponState.loaded(
name: weapon.name,
weaponType: weapon.type,
fullImage: weapon.fullImagePath,
rarity: weapon.rarity,
atk: weapon.atk,
secondaryStat: weapon.secondaryStat,
secondaryStatValue: weapon.secondaryStatValue,
description: translation.description,
locationType: weapon.location,
ascentionMaterials: weapon.ascentionMaterials,
refinements: weapon.refinements.map(
(e) {
var description = translation.refinement;
for (var i = 0; i < e.values.length; i++) {
description = description.replaceFirst('{{$i}}', '${e.values[i]}');
}

return WeaponFileRefinementModel(level: e.level, description: description);
},
).toList(),
);
}
}
8 changes: 6 additions & 2 deletions lib/bloc/weapon/weapon_event.dart
Expand Up @@ -2,7 +2,11 @@ part of 'weapon_bloc.dart';

@freezed
abstract class WeaponEvent with _$WeaponEvent {
const factory WeaponEvent.loadWeapon({
const factory WeaponEvent.loadFromName({
@required String name,
}) = _LoadWeapon;
}) = _LoadWeaponFromName;

const factory WeaponEvent.loadFromImg({
@required String image,
}) = _LoadWeaponFromImg;
}
3 changes: 2 additions & 1 deletion lib/models/home/today_weapon_ascention_material_model.dart
Expand Up @@ -4,10 +4,11 @@ class TodayWeaponAscentionMaterialModel {
final String name;
final String image;
final List<int> days;

final List<String> weapons;
TodayWeaponAscentionMaterialModel({
@required this.name,
@required this.image,
@required this.days,
@required this.weapons,
});
}
16 changes: 16 additions & 0 deletions lib/services/genshing_service.dart
Expand Up @@ -23,6 +23,7 @@ abstract class GenshinService {
List<WeaponCardModel> getWeaponsForCard();
WeaponCardModel getWeaponForCardByImg(String image);
WeaponFileModel getWeapon(String name);
WeaponFileModel getWeaponByImg(String img);

List<ArtifactCardModel> getArtifactsForCard();
ArtifactCardModel getArtifactForCardByImg(String image);
Expand Down Expand Up @@ -195,6 +196,11 @@ class GenshinServiceImpl implements GenshinService {
return _weaponsFile.weapons.firstWhere((element) => element.name == name);
}

@override
WeaponFileModel getWeaponByImg(String img) {
return _weaponsFile.weapons.firstWhere((element) => Assets.getWeaponPath(element.image, element.type) == img);
}

@override
TranslationWeaponFile getWeaponTranslation(String name) {
return _translationFile.weapons.firstWhere((element) => element.key == name);
Expand Down Expand Up @@ -280,13 +286,23 @@ class GenshinServiceImpl implements GenshinService {
final iterable = day == DateTime.sunday
? _materialsFile.weaponPrimary
: _materialsFile.weaponPrimary.where((t) => t.days.contains(day));

return iterable.map((e) {
final translation = _translationFile.materials.firstWhere((t) => t.key == e.name);

final weapons = <String>[];
for (final weapon in _weaponsFile.weapons) {
final materialIsBeingUsed =
weapon.ascentionMaterials.expand((m) => m.materials).where((m) => m.image == e.image).isNotEmpty;
if (materialIsBeingUsed) {
weapons.add(weapon.fullImagePath);
}
}
return TodayWeaponAscentionMaterialModel(
days: e.days,
name: translation.name,
image: Assets.getMaterialPath(e.image, e.type),
weapons: weapons,
);
}).toList();
}
Expand Down
34 changes: 21 additions & 13 deletions lib/ui/pages/map_page.dart
Expand Up @@ -16,21 +16,29 @@ class _MapPageState extends State<MapPage> {
final flutterWebviewPlugin = FlutterWebviewPlugin();

final String script = '''
let elements = document.getElementsByClassName("nav-link");
let total = elements.length;
for (let index = 0; index < total; index++) {
const element = elements[index];
const text = element.childNodes[0].textContent;
if (text !== "Markers") {
element.remove();
total--;
index--;
setTimeout(function(){
let elements = document.getElementsByClassName("nav-link");
let total = elements.length;
for (let index = 0; index < total; index++) {
const element = elements[index];
const text = element.childNodes[0].textContent;
if (text !== "Markers") {
element.remove();
total--;
index--;
}
if (total === 1)
break;
}
if (total === 1)
break;
}
document.getElementsByClassName("fixed-bottom")[0].remove();
total = document.getElementsByClassName("fixed-bottom").length;
for (let index = 0; index < total; index++) {
if (document.getElementsByClassName("fixed-bottom").length > 0)
document.getElementsByClassName("fixed-bottom")[0].remove();
}
},
800);
''';

@override
Expand Down
12 changes: 1 addition & 11 deletions lib/ui/pages/materials_page.dart
Expand Up @@ -8,19 +8,9 @@ import '../widgets/common/loading.dart';
import '../widgets/materials/sliver_character_ascention_materials.dart';
import '../widgets/materials/sliver_weapon_ascention_materials.dart';

class MaterialsPage extends StatefulWidget {
@override
_MaterialsPageState createState() => _MaterialsPageState();
}

class _MaterialsPageState extends State<MaterialsPage> with AutomaticKeepAliveClientMixin<MaterialsPage> {
@override
bool get wantKeepAlive => true;

class MaterialsPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
super.build(context);

final theme = Theme.of(context);
final s = S.of(context);
return BlocBuilder<MaterialsBloc, MaterialsState>(
Expand Down
16 changes: 12 additions & 4 deletions lib/ui/widgets/common/item_description_detail.dart
Expand Up @@ -30,10 +30,18 @@ class ItemDescriptionDetail extends StatelessWidget {
offset: Styles.listItemWithIconOffset,
child: Tooltip(
message: title,
child: Text(
title,
style: theme.textTheme.headline5.copyWith(color: textColor, fontWeight: FontWeight.bold),
overflow: TextOverflow.ellipsis,
child: Column(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Text(
title,
style: theme.textTheme.headline5.copyWith(color: textColor, fontWeight: FontWeight.bold),
overflow: TextOverflow.ellipsis,
),
Divider(color: textColor, thickness: 2),
],
),
),
),
Expand Down
1 change: 0 additions & 1 deletion lib/ui/widgets/home/char_card_ascention_material.dart
Expand Up @@ -82,7 +82,6 @@ class CharCardAscentionMaterial extends StatelessWidget {
child: Text(
obtainOn,
textAlign: TextAlign.center,
overflow: TextOverflow.ellipsis,
style: theme.textTheme.subtitle2.copyWith(fontSize: 12),
),
),
Expand Down

0 comments on commit dc44576

Please sign in to comment.