Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[WIP] Added initial ui for the asc. material's calculator
- Loading branch information
Showing
21 changed files
with
636 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
lib/bloc/calculator_asc_materials/calculator_asc_materials_bloc.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import 'dart:async'; | ||
|
||
import 'package:bloc/bloc.dart'; | ||
import 'package:freezed_annotation/freezed_annotation.dart'; | ||
|
||
import '../../common/assets.dart'; | ||
import '../../models/models.dart'; | ||
import '../../services/genshing_service.dart'; | ||
|
||
part 'calculator_asc_materials_bloc.freezed.dart'; | ||
|
||
part 'calculator_asc_materials_event.dart'; | ||
|
||
part 'calculator_asc_materials_state.dart'; | ||
|
||
class CalculatorAscMaterialsBloc extends Bloc<CalculatorAscMaterialsEvent, CalculatorAscMaterialsState> { | ||
final GenshinService _genshinService; | ||
|
||
_InitialState get currentState => state as _InitialState; | ||
|
||
CalculatorAscMaterialsBloc(this._genshinService) : super(const CalculatorAscMaterialsState.initial(items: [], summary: [])); | ||
|
||
//TODO: CALCULATE THE SUMMARY | ||
@override | ||
Stream<CalculatorAscMaterialsState> mapEventToState( | ||
CalculatorAscMaterialsEvent event, | ||
) async* { | ||
final s = event.map( | ||
init: (_) => const CalculatorAscMaterialsState.initial(items: [], summary: []), | ||
addCharacter: (e) { | ||
final char = _genshinService.getCharacter(e.key); | ||
final translation = _genshinService.getCharacterTranslation(e.key); | ||
final materials = char.ascentionMaterials.expand((e) => e.materials).map((e) => e).toList(); | ||
final items = [ | ||
...currentState.items, | ||
ItemAscentionMaterials.forCharacters( | ||
key: e.key, | ||
image: Assets.getCharacterFullPath(char.fullImage), | ||
name: translation.name, | ||
rarity: char.rarity, | ||
materials: materials, | ||
) | ||
]; | ||
return currentState.copyWith.call(items: items); | ||
}, | ||
addWeapon: (e) { | ||
final weapon = _genshinService.getWeapon(e.key); | ||
final translation = _genshinService.getWeaponTranslation(e.key); | ||
final items = [ | ||
...currentState.items, | ||
ItemAscentionMaterials.forWeapons( | ||
key: e.key, | ||
image: weapon.fullImagePath, | ||
name: translation.name, | ||
rarity: weapon.rarity, | ||
materials: [], | ||
) | ||
]; | ||
return currentState.copyWith.call(items: items); | ||
}, | ||
removeItem: (e) { | ||
final items = [...currentState.items]; | ||
items.removeAt(e.index); | ||
return currentState.copyWith.call(items: items); | ||
}, | ||
); | ||
|
||
yield s; | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
lib/bloc/calculator_asc_materials/calculator_asc_materials_event.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
part of 'calculator_asc_materials_bloc.dart'; | ||
|
||
@freezed | ||
abstract class CalculatorAscMaterialsEvent with _$CalculatorAscMaterialsEvent { | ||
const factory CalculatorAscMaterialsEvent.init() = _Init; | ||
|
||
const factory CalculatorAscMaterialsEvent.addCharacter({ | ||
@required String key, | ||
@required int currentLevel, | ||
@required int desiredLevel, | ||
@required List<CharacterSkill> skills, | ||
}) = _AddCharacter; | ||
|
||
const factory CalculatorAscMaterialsEvent.updateCharacter({ | ||
@required int index, | ||
@required int currentLevel, | ||
@required int desiredLevel, | ||
@required List<CharacterSkill> skills, | ||
}) = _UpdateCharacter; | ||
|
||
const factory CalculatorAscMaterialsEvent.addWeapon({ | ||
@required String key, | ||
@required int currentLevel, | ||
@required int desiredLevel, | ||
}) = _AddWeapon; | ||
|
||
const factory CalculatorAscMaterialsEvent.updateWeapon({ | ||
@required int index, | ||
@required int currentLevel, | ||
@required int desiredLevel, | ||
}) = _UpdateWeapon; | ||
|
||
const factory CalculatorAscMaterialsEvent.removeItem({ | ||
@required int index, | ||
}) = _RemoveItem; | ||
} |
9 changes: 9 additions & 0 deletions
9
lib/bloc/calculator_asc_materials/calculator_asc_materials_state.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
part of 'calculator_asc_materials_bloc.dart'; | ||
|
||
@freezed | ||
abstract class CalculatorAscMaterialsState with _$CalculatorAscMaterialsState { | ||
const factory CalculatorAscMaterialsState.initial({ | ||
@required List<ItemAscentionMaterials> items, | ||
@required List<AscentionMaterialsSummary> summary, | ||
}) = _InitialState; | ||
} |
132 changes: 132 additions & 0 deletions
132
lib/bloc/calculator_asc_materials_item/calculator_asc_materials_item_bloc.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
import 'dart:async'; | ||
|
||
import 'package:bloc/bloc.dart'; | ||
import 'package:freezed_annotation/freezed_annotation.dart'; | ||
|
||
import '../../common/assets.dart'; | ||
import '../../models/models.dart'; | ||
import '../../services/genshing_service.dart'; | ||
|
||
part 'calculator_asc_materials_item_bloc.freezed.dart'; | ||
|
||
part 'calculator_asc_materials_item_event.dart'; | ||
|
||
part 'calculator_asc_materials_item_state.dart'; | ||
|
||
class CalculatorAscMaterialsItemBloc extends Bloc<CalculatorAscMaterialsItemEvent, CalculatorAscMaterialsItemState> { | ||
final GenshinService _genshinService; | ||
|
||
static int minSkillLevel = 1; | ||
static int maxSkillLevel = 10; | ||
static int minAscensionLevel = 1; | ||
static int maxAscensionLevel = 6; | ||
|
||
_LoadedState get currentState => state as _LoadedState; | ||
|
||
CalculatorAscMaterialsItemBloc(this._genshinService) : super(const CalculatorAscMaterialsItemState.loading()); | ||
|
||
@override | ||
Stream<CalculatorAscMaterialsItemState> mapEventToState( | ||
CalculatorAscMaterialsItemEvent event, | ||
) async* { | ||
if (event is _Init) { | ||
yield const CalculatorAscMaterialsItemState.loading(); | ||
} | ||
|
||
final s = event.map( | ||
load: (e) { | ||
if (e.isCharacter) { | ||
final char = _genshinService.getCharacter(e.key); | ||
final translation = _genshinService.getCharacterTranslation(e.key); | ||
return CalculatorAscMaterialsItemState.loaded( | ||
name: translation.name, | ||
imageFullPath: Assets.getCharacterPath(char.image), | ||
currentLevel: minAscensionLevel, | ||
desiredLevel: maxAscensionLevel, | ||
skills: translation.skills | ||
.map( | ||
(e) => CharacterSkill.skill(name: e.title, currentLevel: minSkillLevel, desiredLevel: maxSkillLevel), | ||
) | ||
.toList(), | ||
); | ||
} | ||
final weapon = _genshinService.getWeapon(e.key); | ||
final translation = _genshinService.getWeaponTranslation(e.key); | ||
return CalculatorAscMaterialsItemState.loaded( | ||
name: translation.name, | ||
imageFullPath: weapon.fullImagePath, | ||
currentLevel: minAscensionLevel, | ||
desiredLevel: maxAscensionLevel, | ||
); | ||
}, | ||
currentLevelChanged: (e) { | ||
return _ascensionChanged(e.newValue, currentState.desiredLevel); | ||
}, | ||
desiredLevelChanged: (e) { | ||
return _ascensionChanged(currentState.currentLevel, e.newValue); | ||
}, | ||
skillCurrentLevelChanged: (e) { | ||
return _skillChanged(e.index, e.newValue, true); | ||
}, | ||
skillDesiredLevelChanged: (e) { | ||
return _skillChanged(e.index, e.newValue, false); | ||
}, | ||
); | ||
|
||
yield s; | ||
} | ||
|
||
CalculatorAscMaterialsItemState _ascensionChanged(int currentLevel, int desiredLevel) { | ||
var cl = currentLevel; | ||
var dl = desiredLevel; | ||
|
||
if (cl > dl) { | ||
dl = cl; | ||
} else if (dl < cl) { | ||
cl = dl; | ||
} | ||
|
||
if (cl > maxAscensionLevel || cl < minAscensionLevel) { | ||
return currentState; | ||
} | ||
|
||
if (dl > maxAscensionLevel || dl < minAscensionLevel) { | ||
return currentState; | ||
} | ||
|
||
return currentState.copyWith.call(currentLevel: cl, desiredLevel: dl); | ||
} | ||
|
||
CalculatorAscMaterialsItemState _skillChanged(int skillIndex, int newValue, bool currentChanged) { | ||
final skills = <CharacterSkill>[]; | ||
|
||
for (var i = 0; i < currentState.skills.length; i++) { | ||
final item = currentState.skills[i]; | ||
if (i != skillIndex) { | ||
skills.add(item); | ||
continue; | ||
} | ||
|
||
var cl = currentChanged ? newValue : item.currentLevel; | ||
var dl = currentChanged ? item.desiredLevel : newValue; | ||
|
||
if (cl > dl) { | ||
dl = cl; | ||
} else if (dl < cl) { | ||
cl = dl; | ||
} | ||
|
||
if (cl > maxSkillLevel || cl < minSkillLevel) { | ||
return currentState; | ||
} | ||
|
||
if (dl > maxSkillLevel || dl < minSkillLevel) { | ||
return currentState; | ||
} | ||
|
||
skills.add(item.copyWith.call(currentLevel: cl, desiredLevel: dl)); | ||
} | ||
|
||
return currentState.copyWith.call(skills: skills); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
lib/bloc/calculator_asc_materials_item/calculator_asc_materials_item_event.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
part of 'calculator_asc_materials_item_bloc.dart'; | ||
|
||
@freezed | ||
abstract class CalculatorAscMaterialsItemEvent with _$CalculatorAscMaterialsItemEvent { | ||
const factory CalculatorAscMaterialsItemEvent.load({ | ||
@required String key, | ||
@required bool isCharacter, | ||
}) = _Init; | ||
|
||
const factory CalculatorAscMaterialsItemEvent.currentLevelChanged({ | ||
@required int newValue, | ||
}) = _CurrentLevelChanged; | ||
|
||
const factory CalculatorAscMaterialsItemEvent.desiredLevelChanged({ | ||
@required int newValue, | ||
}) = _DesiredLevelChanged; | ||
|
||
const factory CalculatorAscMaterialsItemEvent.skillCurrentLevelChanged({ | ||
@required int index, | ||
@required int newValue, | ||
}) = _SkillCurrentLevelChanged; | ||
|
||
const factory CalculatorAscMaterialsItemEvent.skillDesiredLevelChanged({ | ||
@required int index, | ||
@required int newValue, | ||
}) = _SkillDesiredLevelChanged; | ||
} |
14 changes: 14 additions & 0 deletions
14
lib/bloc/calculator_asc_materials_item/calculator_asc_materials_item_state.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
part of 'calculator_asc_materials_item_bloc.dart'; | ||
|
||
@freezed | ||
abstract class CalculatorAscMaterialsItemState with _$CalculatorAscMaterialsItemState { | ||
const factory CalculatorAscMaterialsItemState.loading() = _LoadingState; | ||
|
||
const factory CalculatorAscMaterialsItemState.loaded({ | ||
@required String name, | ||
@required String imageFullPath, | ||
@required int currentLevel, | ||
@required int desiredLevel, | ||
@Default([]) List<CharacterSkill> skills, | ||
}) = _LoadedState; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.