Skip to content

Commit

Permalink
[Infrastructure] Items were not being shown in the game codes section
Browse files Browse the repository at this point in the history
  • Loading branch information
Wolfteam committed Aug 22, 2022
1 parent 463f007 commit abf5a21
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions lib/infrastructure/game_codes_service.dart
Expand Up @@ -77,7 +77,7 @@ class GameCodeServiceImpl implements GameCodeService {
expiredOn ??= _parseDate(nodeText, expired: true);
}

final rewards = _parseRewards(cells[2].nodes);
final rewards = _parseRewards(cells[2].nodes.whereType<Element>().where((el) => el.localName == 'span').toList());
return GameCodeModel(
code: code,
expiredOn: expiredOn,
Expand All @@ -93,31 +93,30 @@ class GameCodeServiceImpl implements GameCodeService {
return null;
}

List<ItemAscensionMaterialModel> _parseRewards(NodeList cellNodes) {
List<ItemAscensionMaterialModel> _parseRewards(List<Element> cellNodes) {
final rewards = <ItemAscensionMaterialModel>[];
for (var i = 0; i < cellNodes.length; i++) {
try {
final node = cellNodes[i];
if (node.text!.trim().isEmpty) {
if (node.text.trim().isEmpty) {
continue;
}

final wikiName = node.text!.trim();
final nameAndQuantity = node.text.trim().split('×');
final wikiName = nameAndQuantity.first.trim();
final type = _getMaterialType(wikiName);
if (type == null) {
continue;
}

final quantityString = cellNodes[i + 1].text!.trim().replaceAll('\n', '').replaceAll(',', '');
final quantityString = nameAndQuantity.last.trim().replaceAll('\n', '').replaceAll(',', '');
final quantity = int.parse(quantityRegex.allMatches(quantityString).first.group(0)!);
final key = _getMaterialKey(wikiName, type);
final img = _genshinService.materials.getMaterialImg(key);
rewards.add(ItemAscensionMaterialModel(quantity: quantity, type: type, key: key, image: img));
} catch (e, s) {
_logger.error(runtimeType, '_parseRewards: Unknown error', e, s);
}

i++;
}
return rewards;
}
Expand Down

0 comments on commit abf5a21

Please sign in to comment.