Skip to content

Commit

Permalink
Build fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Wolfteam committed Jul 16, 2022
1 parent 5288230 commit a4b170e
Show file tree
Hide file tree
Showing 20 changed files with 172 additions and 165 deletions.
Expand Up @@ -20,7 +20,7 @@ class CalculatorAscMaterialsItemUpdateQuantityBloc
Stream<CalculatorAscMaterialsItemUpdateQuantityState> mapEventToState(CalculatorAscMaterialsItemUpdateQuantityEvent event) async* {
final s = await event.map(
load: (e) async {
final material = _dataService.getMaterialFromInventory(e.key);
final material = _dataService.inventory.getMaterialFromInventory(e.key);
return CalculatorAscMaterialsItemUpdateQuantityState.loaded(key: material.key, quantity: material.quantity);
},
update: (e) async {
Expand All @@ -34,6 +34,6 @@ class CalculatorAscMaterialsItemUpdateQuantityBloc

Future<void> _updateMaterialQuantity(String key, int quantity) async {
await _telemetryService.trackItemUpdatedInInventory(key, quantity);
await _dataService.updateItemInInventory(key, ItemType.material, quantity);
await _dataService.inventory.updateItemInInventory(key, ItemType.material, quantity, _dataService.calculator.redistributeInventoryMaterial);
}
}
Expand Up @@ -40,7 +40,7 @@ class CalculatorAscMaterialsBloc extends Bloc<CalculatorAscMaterialsEvent, Calcu
) async* {
final s = await event.map(
init: (e) async {
final session = _dataService.getCalcAscMatSession(e.sessionKey);
final session = _dataService.calculator.getCalcAscMatSession(e.sessionKey);
final materialsForSummary = _buildMaterialsForSummary(session.items);
final summary = _calculatorService.generateSummary(materialsForSummary);
return CalculatorAscMaterialsState.initial(items: session.items, summary: summary);
Expand Down Expand Up @@ -71,7 +71,7 @@ class CalculatorAscMaterialsBloc extends Bloc<CalculatorAscMaterialsEvent, Calcu
currentAscensionLevel: e.currentAscensionLevel,
useMaterialsFromInventory: e.useMaterialsFromInventory,
);
newItem = await _dataService.addCalAscMatSessionItem(e.sessionKey, newItem);
newItem = await _dataService.calculator.addCalAscMatSessionItem(e.sessionKey, newItem);
final items = [...currentState.items, newItem];
final materialsForSummary = _buildMaterialsForSummary(items);

Expand Down Expand Up @@ -101,7 +101,7 @@ class CalculatorAscMaterialsBloc extends Bloc<CalculatorAscMaterialsEvent, Calcu
currentAscensionLevel: e.currentAscensionLevel,
useMaterialsFromInventory: e.useMaterialsFromInventory,
);
newItem = await _dataService.addCalAscMatSessionItem(e.sessionKey, newItem);
newItem = await _dataService.calculator.addCalAscMatSessionItem(e.sessionKey, newItem);
final items = [...currentState.items, newItem];
final materialsForSummary = _buildMaterialsForSummary(items);

Expand All @@ -115,16 +115,16 @@ class CalculatorAscMaterialsBloc extends Bloc<CalculatorAscMaterialsEvent, Calcu
final itemPosition = itemsToLoop.elementAt(e.index).position;
itemsToLoop.removeAt(e.index);

await _dataService.deleteCalAscMatSessionItem(e.sessionKey, itemPosition, redistribute: false);
await _dataService.calculator.deleteCalAscMatSessionItem(e.sessionKey, itemPosition, redistribute: false);

for (var i = 0; i < itemsToLoop.length; i++) {
final item = itemsToLoop[i];
await _dataService.updateCalAscMatSessionItem(e.sessionKey, i, item, redistribute: false);
await _dataService.calculator.updateCalAscMatSessionItem(e.sessionKey, i, item, redistribute: false);
}

await _dataService.redistributeAllInventoryMaterials();
await _dataService.calculator.redistributeAllInventoryMaterials();

final session = _dataService.getCalcAscMatSession(e.sessionKey);
final session = _dataService.calculator.getCalcAscMatSession(e.sessionKey);
final materialsForSummary = _buildMaterialsForSummary(session.items);

_notifyParent();
Expand Down Expand Up @@ -176,7 +176,7 @@ class CalculatorAscMaterialsBloc extends Bloc<CalculatorAscMaterialsEvent, Calcu
return _updateItem(e.sessionKey, e.index, updatedWeapon);
},
clearAllItems: (e) async {
await _dataService.deleteAllCalAscMatSessionItems(e.sessionKey);
await _dataService.calculator.deleteAllCalAscMatSessionItems(e.sessionKey);
return const CalculatorAscMaterialsState.initial(items: [], summary: []);
},
);
Expand All @@ -189,7 +189,7 @@ class CalculatorAscMaterialsBloc extends Bloc<CalculatorAscMaterialsEvent, Calcu
List<String> getItemsKeysToExclude() => currentState.items.map((e) => e.key).toList();

Future<CalculatorAscMaterialsState> _updateItem(int sessionKey, int index, ItemAscensionMaterials updatedItem) async {
final toAdd = await _dataService.updateCalAscMatSessionItem(sessionKey, index, updatedItem);
final toAdd = await _dataService.calculator.updateCalAscMatSessionItem(sessionKey, index, updatedItem);
final items = [...currentState.items];
items.removeAt(index);
items.insert(index, toAdd);
Expand Down
Expand Up @@ -30,10 +30,10 @@ class CalculatorAscMaterialsOrderBloc extends Bloc<CalculatorAscMaterialsOrderEv
applyChanges: (_) async {
for (var i = 0; i < state.items.length; i++) {
final item = state.items[i];
await _dataService.updateCalAscMatSessionItem(state.sessionKey, i, item, redistribute: false);
await _dataService.calculator.updateCalAscMatSessionItem(state.sessionKey, i, item, redistribute: false);
}

await _dataService.redistributeAllInventoryMaterials();
await _dataService.calculator.redistributeAllInventoryMaterials();

_calculatorAscMaterialsBloc.add(CalculatorAscMaterialsEvent.init(sessionKey: state.sessionKey));

Expand Down
Expand Up @@ -23,31 +23,31 @@ class CalculatorAscMaterialsSessionsBloc extends Bloc<CalculatorAscMaterialsSess
final s = await event.map(
init: (_) async {
await _telemetryService.trackCalculatorAscMaterialsSessionsLoaded();
final sessions = _dataService.getAllCalAscMatSessions();
final sessions = _dataService.calculator.getAllCalAscMatSessions();
return CalculatorAscMaterialsSessionsState.loaded(sessions: sessions);
},
createSession: (e) async {
await _telemetryService.trackCalculatorAscMaterialsSessionsCreated();
await _dataService.createCalAscMatSession(e.name.trim(), currentState.sessions.length);
final sessions = _dataService.getAllCalAscMatSessions();
await _dataService.calculator.createCalAscMatSession(e.name.trim(), currentState.sessions.length);
final sessions = _dataService.calculator.getAllCalAscMatSessions();
return CalculatorAscMaterialsSessionsState.loaded(sessions: sessions);
},
updateSession: (e) async {
final position = currentState.sessions.firstWhere((el) => el.key == e.key).position;
await _telemetryService.trackCalculatorAscMaterialsSessionsUpdated();
await _dataService.updateCalAscMatSession(e.key, e.name.trim(), position);
final sessions = _dataService.getAllCalAscMatSessions();
await _dataService.calculator.updateCalAscMatSession(e.key, e.name.trim(), position);
final sessions = _dataService.calculator.getAllCalAscMatSessions();
return CalculatorAscMaterialsSessionsState.loaded(sessions: sessions);
},
deleteSession: (e) async {
await _telemetryService.trackCalculatorAscMaterialsSessionsDeleted();
await _dataService.deleteCalAscMatSession(e.key);
final sessions = _dataService.getAllCalAscMatSessions();
await _dataService.calculator.deleteCalAscMatSession(e.key);
final sessions = _dataService.calculator.getAllCalAscMatSessions();
return CalculatorAscMaterialsSessionsState.loaded(sessions: sessions);
},
deleteAllSessions: (_) async {
await _telemetryService.trackCalculatorAscMaterialsSessionsDeleted(all: true);
await _dataService.deleteAllCalAscMatSession();
await _dataService.calculator.deleteAllCalAscMatSession();
return const CalculatorAscMaterialsSessionsState.loaded(sessions: []);
},
);
Expand Down
Expand Up @@ -40,10 +40,10 @@ class CalculatorAscMaterialsSessionsOrderBloc extends Bloc<CalculatorAscMaterial
applyChanges: (_) async {
for (var i = 0; i < state.sessions.length; i++) {
final session = state.sessions[i];
await _dataService.updateCalAscMatSession(session.key, session.name, i);
await _dataService.calculator.updateCalAscMatSession(session.key, session.name, i);
}

await _dataService.redistributeAllInventoryMaterials();
await _dataService.calculator.redistributeAllInventoryMaterials();

_sessionsBloc.add(const CalculatorAscMaterialsSessionsEvent.init());

Expand Down
6 changes: 3 additions & 3 deletions lib/application/character/character_bloc.dart
Expand Up @@ -42,15 +42,15 @@ class CharacterBloc extends Bloc<CharacterEvent, CharacterState> {
loading: (state) async => state,
loaded: (state) async {
await _telemetryService.trackItemAddedToInventory(key, 1);
await _dataService.addCharacterToInventory(key);
await _dataService.inventory.addCharacterToInventory(key);
return state.copyWith.call(isInInventory: true);
},
),
deleteFromInventory: (key) async => state.map(
loading: (state) async => state,
loaded: (state) async {
await _telemetryService.trackItemDeletedFromInventory(key);
await _dataService.deleteCharacterFromInventory(key);
await _dataService.inventory.deleteCharacterFromInventory(key);
return state.copyWith.call(isInInventory: false);
},
),
Expand Down Expand Up @@ -85,7 +85,7 @@ class CharacterBloc extends Bloc<CharacterEvent, CharacterState> {
}).toList();

final birthday = _localeService.formatCharBirthDate(char.birthday);
final isInInventory = _dataService.isItemInInventory(char.key, ItemType.character);
final isInInventory = _dataService.inventory.isItemInInventory(char.key, ItemType.character);
final builds = char.builds.map((build) {
return CharacterBuildCardModel(
isRecommended: build.isRecommended,
Expand Down
6 changes: 3 additions & 3 deletions lib/application/game_codes/game_codes_bloc.dart
Expand Up @@ -40,12 +40,12 @@ class GameCodesBloc extends Bloc<GameCodesEvent, GameCodesState> {
return _buildInitialState();
},
markAsUsed: (code, wasUsed) async {
await _dataService.markCodeAsUsed(code, wasUsed: wasUsed);
await _dataService.gameCodes.markCodeAsUsed(code, wasUsed: wasUsed);
return _buildInitialState();
},
refresh: () async {
final gameCodes = await _gameCodeService.getAllGameCodes();
await _dataService.saveGameCodes(gameCodes);
await _dataService.gameCodes.saveGameCodes(gameCodes);

await _telemetryService.trackGameCodesOpened();
return _buildInitialState();
Expand All @@ -57,7 +57,7 @@ class GameCodesBloc extends Bloc<GameCodesEvent, GameCodesState> {
}

GameCodesState _buildInitialState() {
final gameCodes = _dataService.getAllGameCodes();
final gameCodes = _dataService.gameCodes.getAllGameCodes();

return GameCodesState.loaded(
workingGameCodes: gameCodes.where((code) => !code.isExpired).toList(),
Expand Down
40 changes: 23 additions & 17 deletions lib/application/inventory/inventory_bloc.dart
Expand Up @@ -25,60 +25,66 @@ class InventoryBloc extends Bloc<InventoryEvent, InventoryState> {
this._telemetryService,
) : super(const InventoryState.loaded(characters: [], weapons: [], materials: [])) {
_streamSubscriptions = [
_dataService.itemAddedToInventory.stream.listen((type) => add(InventoryEvent.refresh(type: type))),
_dataService.itemDeletedFromInventory.stream.listen((type) => add(InventoryEvent.refresh(type: type))),
_dataService.itemUpdatedInInventory.stream.listen((type) => add(InventoryEvent.refresh(type: type))),
_dataService.inventory.itemAddedToInventory.stream.listen((type) => add(InventoryEvent.refresh(type: type))),
_dataService.inventory.itemDeletedFromInventory.stream.listen((type) => add(InventoryEvent.refresh(type: type))),
_dataService.inventory.itemUpdatedInInventory.stream.listen((type) => add(InventoryEvent.refresh(type: type))),
];
}

@override
Stream<InventoryState> mapEventToState(InventoryEvent event) async* {
final s = await event.map(
init: (_) async {
final characters = _dataService.getAllCharactersInInventory();
final weapons = _dataService.getAllWeaponsInInventory();
final materials = _dataService.getAllMaterialsInInventory();
final characters = _dataService.inventory.getAllCharactersInInventory();
final weapons = _dataService.inventory.getAllWeaponsInInventory();
final materials = _dataService.inventory.getAllMaterialsInInventory();

return InventoryState.loaded(characters: characters, weapons: weapons, materials: materials);
},
addCharacter: (e) async {
await _telemetryService.trackItemAddedToInventory(e.key, 1);
await _dataService.addCharacterToInventory(e.key, raiseEvent: false);
await _dataService.inventory.addCharacterToInventory(e.key, raiseEvent: false);
return _refreshItems(ItemType.character);
},
addWeapon: (e) async {
await _telemetryService.trackItemAddedToInventory(e.key, 1);
await _dataService.addWeaponToInventory(e.key, raiseEvent: false);
await _dataService.inventory.addWeaponToInventory(e.key, raiseEvent: false);
return _refreshItems(ItemType.weapon);
},
deleteCharacter: (e) async {
await _telemetryService.trackItemDeletedFromInventory(e.key);
await _dataService.deleteCharacterFromInventory(e.key, raiseEvent: false);
await _dataService.inventory.deleteCharacterFromInventory(e.key, raiseEvent: false);
return _refreshItems(ItemType.character);
},
deleteWeapon: (e) async {
await _telemetryService.trackItemDeletedFromInventory(e.key);
await _dataService.deleteWeaponFromInventory(e.key, raiseEvent: false);
await _dataService.inventory.deleteWeaponFromInventory(e.key, raiseEvent: false);
return _refreshItems(ItemType.weapon);
},
updateMaterial: (e) async {
await _telemetryService.trackItemUpdatedInInventory(e.key, e.quantity);
await _dataService.updateItemInInventory(e.key, ItemType.material, e.quantity, raiseEvent: false);
await _dataService.inventory.updateItemInInventory(
e.key,
ItemType.material,
e.quantity,
_dataService.calculator.redistributeInventoryMaterial,
raiseEvent: false,
);
return _refreshItems(ItemType.material);
},
clearAllCharacters: (_) async {
await _telemetryService.trackItemsDeletedFromInventory(ItemType.character);
await _dataService.deleteItemsFromInventory(ItemType.character, raiseEvent: false);
await _dataService.inventory.deleteItemsFromInventory(ItemType.character, raiseEvent: false);
return state.copyWith.call(characters: []);
},
clearAllWeapons: (_) async {
await _telemetryService.trackItemsDeletedFromInventory(ItemType.weapon);
await _dataService.deleteItemsFromInventory(ItemType.weapon, raiseEvent: false);
await _dataService.inventory.deleteItemsFromInventory(ItemType.weapon, raiseEvent: false);
return state.copyWith.call(weapons: []);
},
clearAllMaterials: (_) async {
await _telemetryService.trackItemsDeletedFromInventory(ItemType.material);
await _dataService.deleteItemsFromInventory(ItemType.material, raiseEvent: false);
await _dataService.inventory.deleteItemsFromInventory(ItemType.material, raiseEvent: false);
return _refreshItems(ItemType.material);
},
refresh: (e) async => _refreshItems(e.type),
Expand All @@ -96,13 +102,13 @@ class InventoryBloc extends Bloc<InventoryEvent, InventoryState> {
InventoryState _refreshItems(ItemType type) {
switch (type) {
case ItemType.character:
return state.copyWith.call(characters: _dataService.getAllCharactersInInventory());
return state.copyWith.call(characters: _dataService.inventory.getAllCharactersInInventory());
case ItemType.weapon:
return state.copyWith.call(weapons: _dataService.getAllWeaponsInInventory());
return state.copyWith.call(weapons: _dataService.inventory.getAllWeaponsInInventory());
case ItemType.artifact:
throw Exception('Not implemented');
case ItemType.material:
return state.copyWith.call(materials: _dataService.getAllMaterialsInInventory());
return state.copyWith.call(materials: _dataService.inventory.getAllMaterialsInInventory());
}
}

Expand Down

0 comments on commit a4b170e

Please sign in to comment.