prettifyAbyss function

Map prettifyAbyss(
  1. dynamic data
)

Implementation

Map prettifyAbyss(dynamic data) {
  var results = {
    'season': data['schedule_id'],
    'season_start_time': _toDate(data['start_time']),
    'season_end_time': _toDate(data['end_time']),
    'stats': {
      'total_battles': data['total_battle_times'],
      'total_wins': data['total_win_times'],
      'max_floor': data['max_floor'],
      'total_stars': data['total_star'],
    },
    'character_ranks': {
      'most_played': _fchars(data['reveal_rank']),
      'most_kills': _fchars(data['defeat_rank']),
      'strongest_strike': _fchars(data['damage_rank']),
      'most_damage_taken': _fchars(data['take_damage_rank']),
      'most_bursts_used': _fchars(data['normal_skill_rank']),
      'most_skills_used': _fchars(data['energy_skill_rank']),
    },
    'floors': [],
  };

  var floors = data['floors'] ?? [];
  for (var i = 0; i < floors.length; i++) {
    var f = floors[i];
    var floor = {
      'floor': f['index'],
      'stars': f['star'],
      'max_stars': f['max_star'],
      'icon': f['icon'],
      'chambers': [],
    };
    var levels = f['levels'] ?? [];
    for (var j = 0; j < levels.length; j++) {
      var l = levels[j];
      var chamber = {
        'chamber': l['index'],
        'stars': l['star'],
        'max_stars': l['max_star'],
        'has_halves': l['battles'].length == 2,
        'battles': [],
      };
      var battles = l['battles'];
      for (var k = 0; k < battles.length; k++) {
        var b = battles[k];
        var battle = {
          'half': b['index'],
          'timestamp': _toTime(b['timestamp']),
          'characters': [],
        };

        var avatars = b['avatars'];
        for (var z = 0; z < avatars.length; z++) {
          var c = avatars[z];
          battle['characters'].add({
            'name': recognizeCharacterIcon(c['icon']),
            'rarity': c['rarity'] < 100
                ? c['rarity']
                : c['rarity'] - 100, // aloy has 105 stars
            'level': c['level'],
            'icon': c['icon'],
            'id': c['id'],
          });
        }
        chamber['battles'].add(battle);
      }
      floor['chambers'].add(chamber);
    }
  }

  return results;
}