Sorting functions for LB's (works kinda meh...)
This commit is contained in:
parent
af1dec56bc
commit
ba78d50f21
|
@ -38,6 +38,25 @@ class TetrioPlayersLeaderboard {
|
|||
return lb;
|
||||
}
|
||||
|
||||
List<TetrioPlayerFromLeaderboard> getStatRankingFromLB(Stats stat, {bool reversed = false, String country = ""}){
|
||||
List<TetrioPlayerFromLeaderboard> lb = List.from(leaderboard);
|
||||
if (country.isNotEmpty){
|
||||
lb.removeWhere((element) => element.country != country);
|
||||
}
|
||||
lb.sort(((a, b) {
|
||||
if (a.getStatByEnum(stat).isNaN) return 1;
|
||||
if (b.getStatByEnum(stat).isNaN) return -1;
|
||||
if (a.getStatByEnum(stat) > b.getStatByEnum(stat)){
|
||||
return reversed ? 1 : -1;
|
||||
}else if (a.getStatByEnum(stat) == b.getStatByEnum(stat)){
|
||||
return 0;
|
||||
}else{
|
||||
return reversed ? -1 : 1;
|
||||
}
|
||||
}));
|
||||
return lb;
|
||||
}
|
||||
|
||||
List<dynamic> getAverageOfRank(String rank){ // i tried to refactor it and that's was terrible
|
||||
if (rank.isNotEmpty && !rankCutoffs.keys.contains(rank)) throw Exception("Invalid rank");
|
||||
List<TetrioPlayerFromLeaderboard> filtredLeaderboard = List.from(leaderboard);
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
/// Locales: 3
|
||||
/// Strings: 1818 (606 per locale)
|
||||
///
|
||||
/// Built on 2024-09-12 at 20:23 UTC
|
||||
/// Built on 2024-09-30 at 21:23 UTC
|
||||
|
||||
// coverage:ignore-file
|
||||
// ignore_for_file: type=lint
|
||||
|
@ -396,7 +396,7 @@ class Translations implements BaseTranslations<AppLocale, Translations> {
|
|||
late final _StringsPopupActionsEn popupActions = _StringsPopupActionsEn._(_root);
|
||||
late final _StringsErrorsEn errors = _StringsErrorsEn._(_root);
|
||||
Map<String, String> get countries => {
|
||||
'': 'Not selected',
|
||||
'': 'Worldwide',
|
||||
'AF': 'Afghanistan',
|
||||
'AX': 'Åland Islands',
|
||||
'AL': 'Albania',
|
||||
|
@ -1108,7 +1108,7 @@ class _StringsRu implements Translations {
|
|||
@override late final _StringsPopupActionsRu popupActions = _StringsPopupActionsRu._(_root);
|
||||
@override late final _StringsErrorsRu errors = _StringsErrorsRu._(_root);
|
||||
@override Map<String, String> get countries => {
|
||||
'': 'Не выбрана',
|
||||
'': 'Во всём мире',
|
||||
'AF': 'Афганистан',
|
||||
'AX': 'Аландские острова',
|
||||
'AL': 'Албания',
|
||||
|
@ -2628,7 +2628,7 @@ extension on Translations {
|
|||
case 'errors.replayAlreadySaved': return 'Replay already saved';
|
||||
case 'errors.replayExpired': return 'Replay expired and not available anymore';
|
||||
case 'errors.replayRejected': return 'Third party API blocked your IP address';
|
||||
case 'countries.': return 'Not selected';
|
||||
case 'countries.': return 'Worldwide';
|
||||
case 'countries.AF': return 'Afghanistan';
|
||||
case 'countries.AX': return 'Åland Islands';
|
||||
case 'countries.AL': return 'Albania';
|
||||
|
@ -3256,7 +3256,7 @@ extension on _StringsRu {
|
|||
case 'errors.replayAlreadySaved': return 'Повтор уже сохранён';
|
||||
case 'errors.replayExpired': return 'Повтор истёк и больше недоступен';
|
||||
case 'errors.replayRejected': return 'Стороннее API заблокировало ваш IP адрес';
|
||||
case 'countries.': return 'Не выбрана';
|
||||
case 'countries.': return 'Во всём мире';
|
||||
case 'countries.AF': return 'Афганистан';
|
||||
case 'countries.AX': return 'Аландские острова';
|
||||
case 'countries.AL': return 'Албания';
|
||||
|
|
|
@ -853,14 +853,15 @@ class TetrioService extends DB {
|
|||
}
|
||||
}
|
||||
|
||||
Future<List<RecordSingle>> fetchTetrioRecordsLeaderboard({String? prisecter, String? lb}) async{
|
||||
Future<List<RecordSingle>> fetchTetrioRecordsLeaderboard({String? prisecter, String? lb, String? country}) async{
|
||||
Uri url;
|
||||
if (kIsWeb) {
|
||||
url = Uri.https('ts.dan63.by', 'oskware_bridge.php', {"endpoint": "TLLeaderboard"});
|
||||
} else {
|
||||
url = Uri.https('ch.tetr.io', 'api/records/${lb??"40l_global"}', {
|
||||
"limit": "100",
|
||||
if (prisecter != null) "after": prisecter
|
||||
if (prisecter != null) "after": prisecter,
|
||||
if (country != null) "country": country
|
||||
});
|
||||
}
|
||||
try{
|
||||
|
|
|
@ -1099,6 +1099,10 @@ class _DestinationLeaderboardsState extends State<DestinationLeaderboards> {
|
|||
List<dynamic> list = [];
|
||||
bool _isFetchingData = false;
|
||||
String? prisecter;
|
||||
List<DropdownMenuEntry> _countries = [for (MapEntry e in t.countries.entries) DropdownMenuEntry(value: e.key, label: e.value)];
|
||||
List<DropdownMenuEntry> _stats = [for (MapEntry e in chartsShortTitles.entries) DropdownMenuEntry(value: e.key, label: e.value)];
|
||||
String? _country;
|
||||
Stats stat = Stats.tr;
|
||||
|
||||
Future<void> _fetchData() async {
|
||||
if (_isFetchingData) {
|
||||
|
@ -1110,14 +1114,14 @@ class _DestinationLeaderboardsState extends State<DestinationLeaderboards> {
|
|||
setState(() {});
|
||||
|
||||
final items = switch(_currentLb){
|
||||
Leaderboards.tl => await teto.fetchTetrioLeaderboard(prisecter: prisecter),
|
||||
Leaderboards.fullTL => (await teto.fetchTLLeaderboard()).leaderboard,
|
||||
Leaderboards.xp => await teto.fetchTetrioLeaderboard(prisecter: prisecter, lb: "xp"),
|
||||
Leaderboards.ar => await teto.fetchTetrioLeaderboard(prisecter: prisecter, lb: "ar"),
|
||||
Leaderboards.sprint => await teto.fetchTetrioRecordsLeaderboard(prisecter: prisecter),
|
||||
Leaderboards.blitz => await teto.fetchTetrioRecordsLeaderboard(prisecter: prisecter, lb: "blitz_global"),
|
||||
Leaderboards.zenith => await teto.fetchTetrioRecordsLeaderboard(prisecter: prisecter, lb: "zenith_global"),
|
||||
Leaderboards.zenithex => await teto.fetchTetrioRecordsLeaderboard(prisecter: prisecter, lb: "zenithex_global"),
|
||||
Leaderboards.tl => await teto.fetchTetrioLeaderboard(prisecter: prisecter, country: _country),
|
||||
Leaderboards.fullTL => (await teto.fetchTLLeaderboard()).getStatRankingFromLB(stat, country: _country??""),
|
||||
Leaderboards.xp => await teto.fetchTetrioLeaderboard(prisecter: prisecter, lb: "xp", country: _country),
|
||||
Leaderboards.ar => await teto.fetchTetrioLeaderboard(prisecter: prisecter, lb: "ar", country: _country),
|
||||
Leaderboards.sprint => await teto.fetchTetrioRecordsLeaderboard(prisecter: prisecter, country: _country),
|
||||
Leaderboards.blitz => await teto.fetchTetrioRecordsLeaderboard(prisecter: prisecter, lb: "blitz_global", country: _country),
|
||||
Leaderboards.zenith => await teto.fetchTetrioRecordsLeaderboard(prisecter: prisecter, lb: "zenith_global", country: _country),
|
||||
Leaderboards.zenithex => await teto.fetchTetrioRecordsLeaderboard(prisecter: prisecter, lb: "zenithex_global", country: _country),
|
||||
};
|
||||
|
||||
list.addAll(items);
|
||||
|
@ -1211,6 +1215,44 @@ class _DestinationLeaderboardsState extends State<DestinationLeaderboards> {
|
|||
return Column(
|
||||
children: [
|
||||
Text(leaderboards[_currentLb]!, style: TextStyle(fontFamily: "Eurostile Round Extended", fontSize: 28, height: 0.9)),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
DropdownMenu(
|
||||
leadingIcon: Icon(Icons.public),
|
||||
inputDecorationTheme: InputDecorationTheme(
|
||||
isDense: true,
|
||||
),
|
||||
textStyle: TextStyle(fontSize: 14, height: 0.9),
|
||||
dropdownMenuEntries: _countries,
|
||||
initialSelection: "",
|
||||
onSelected: ((value) {
|
||||
_country = value as String?;
|
||||
list.clear();
|
||||
prisecter = null;
|
||||
_isFetchingData = false;
|
||||
setState((){_fetchData();});
|
||||
})
|
||||
),
|
||||
if (_currentLb == Leaderboards.fullTL) SizedBox(width: 5.0),
|
||||
if (_currentLb == Leaderboards.fullTL) DropdownMenu(
|
||||
leadingIcon: Icon(Icons.sort),
|
||||
inputDecorationTheme: InputDecorationTheme(
|
||||
isDense: true,
|
||||
),
|
||||
textStyle: TextStyle(fontSize: 14, height: 0.9),
|
||||
dropdownMenuEntries: _stats,
|
||||
initialSelection: stat,
|
||||
onSelected: ((value) {
|
||||
stat = value;
|
||||
list.clear();
|
||||
prisecter = null;
|
||||
_isFetchingData = false;
|
||||
setState((){_fetchData();});
|
||||
})
|
||||
)
|
||||
],
|
||||
),
|
||||
const Divider(color: Color.fromARGB(50, 158, 158, 158)),
|
||||
Expanded(
|
||||
child: ListView.builder(
|
||||
|
@ -4257,7 +4299,7 @@ class FutureError extends StatelessWidget{
|
|||
Text(snapshot.error.toString(), style: const TextStyle(fontFamily: "Eurostile Round", fontSize: 42, fontWeight: FontWeight.bold), textAlign: TextAlign.center),
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 8.0),
|
||||
child: Text(snapshot.stackTrace.toString(), textAlign: TextAlign.center),
|
||||
child: Text(snapshot.stackTrace.toString(), textAlign: TextAlign.left, style: TextStyle(fontFamily: "Monospace")),
|
||||
),
|
||||
Spacer()
|
||||
],
|
||||
|
|
|
@ -377,7 +377,7 @@
|
|||
"replayRejected": "Third party API blocked your IP address"
|
||||
},
|
||||
"countries(map)": {
|
||||
"": "Not selected",
|
||||
"": "Worldwide",
|
||||
|
||||
"AF": "Afghanistan",
|
||||
"AX": "\u00c5land Islands",
|
||||
|
|
|
@ -377,7 +377,7 @@
|
|||
"replayRejected": "Стороннее API заблокировало ваш IP адрес"
|
||||
},
|
||||
"countries(map)": {
|
||||
"": "Не выбрана",
|
||||
"": "Во всём мире",
|
||||
|
||||
"AF": "Афганистан",
|
||||
"AX": "Аландские острова",
|
||||
|
|
Loading…
Reference in New Issue