Skip to content

Commit

Permalink
i'm feeling a bit sick
Browse files Browse the repository at this point in the history
  • Loading branch information
dan63047 committed Oct 28, 2024
1 parent b8a8ddf commit ae7d92f
Show file tree
Hide file tree
Showing 9 changed files with 1,070 additions and 575 deletions.
4 changes: 2 additions & 2 deletions lib/data_objects/summaries.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ class Summaries {
zenithEx = RecordSingle.fromJson(json['zenithex']['record'],
json['zenithex']['rank'], json['zenithex']['rank_local']);
if (json['zenithex']['best']['record'] != null)
zenithCareerBest = RecordSingle.fromJson(
zenithExCareerBest = RecordSingle.fromJson(
json['zenithex']['best']['record'],
json['zenith']['best']['rank'],
json['zenithex']['best']['rank'],
-1);
achievements = [
for (var achievement in json['achievements'])
Expand Down
6 changes: 5 additions & 1 deletion lib/views/destination_cutoffs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import 'package:tetra_stats/main.dart';
import 'package:tetra_stats/utils/numers_formats.dart';
import 'package:tetra_stats/utils/text_shadow.dart';
import 'package:tetra_stats/views/main_view_tiles.dart';
import 'package:tetra_stats/views/rank_view.dart';
import 'package:tetra_stats/widgets/text_timestamp.dart';
import 'package:vector_math/vector_math_64.dart' hide Colors;

Expand Down Expand Up @@ -273,7 +274,10 @@ class _DestinationCutoffsState extends State<DestinationCutoffs> {
Padding(
padding: const EdgeInsets.only(right: 8.0),
child: TextButton(child: Text("View", textAlign: TextAlign.right, style: const TextStyle(fontFamily: "Eurostile Round", fontSize: 14, fontWeight: FontWeight.w500, color: Colors.white)), onPressed: () {

Navigator.push(context, MaterialPageRoute(
builder: (context) => RankView(rank: rank, nextRankTR: rank == "x+" ? snapshot.data!.data["top1"]!.tr : snapshot.data!.data[ranks[ranks.indexOf(rank)+1]]!.tr, nextRankPercentile: rank == "x+" ? 0.00 : snapshot.data!.data[ranks[ranks.indexOf(rank)+1]]!.percentile, nextRankTargetTR: rank == "x+" ? 25000.00 : snapshot.data!.data[ranks[ranks.indexOf(rank)+1]]!.targetTr, totalPlayers: snapshot.data!.total, cutoffTetrio: snapshot.data!.data[rank]!),
),
);
},),
),
]
Expand Down
78 changes: 74 additions & 4 deletions lib/views/destination_graphs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import 'package:tetra_stats/gen/strings.g.dart';
import 'package:tetra_stats/main.dart';
import 'package:tetra_stats/services/crud_exceptions.dart';
import 'package:tetra_stats/utils/numers_formats.dart';
import 'package:tetra_stats/views/destination_home.dart';
import 'package:tetra_stats/views/main_view_tiles.dart';
import 'package:tetra_stats/widgets/text_timestamp.dart';

Expand Down Expand Up @@ -45,6 +44,9 @@ class _DestinationGraphsState extends State<DestinationGraphs> {
Stats _Ychart = Stats.tr;
Stats _Xchart = Stats.tr;
int _season = currentSeason-1;
List<String> excludeRanks = [];
late Future<List<_MyScatterSpot>> futureLeague = getTetraLeagueData(_Xchart, _Ychart);
String searchLeague = "";
//Duration postSeasonLeft = seasonStart.difference(DateTime.now());

@override
Expand Down Expand Up @@ -169,18 +171,24 @@ class _DestinationGraphsState extends State<DestinationGraphs> {
TetrioPlayersLeaderboard leaderboard = await teto.fetchTLLeaderboard();
List<_MyScatterSpot> _spots = [
for (TetrioPlayerFromLeaderboard entry in leaderboard.leaderboard)
_MyScatterSpot(
if (excludeRanks.indexOf(entry.rank) == -1) _MyScatterSpot(
entry.getStatByEnum(x).toDouble(),
entry.getStatByEnum(y).toDouble(),
entry.userId,
entry.username,
entry.rank,
rankColors[entry.rank]??Colors.white
(rankColors[entry.rank]??Colors.white).withAlpha((searchLeague.isNotEmpty && entry.username.startsWith(searchLeague.toLowerCase())) ? 255 : 20)
)
];
return _spots;
}

bool? getTotalFilterValue(){
if (excludeRanks.isEmpty) return true;
if (excludeRanks.length == ranks.length) return false;
return null;
}

Widget getHistoryGraph(){
return FutureBuilder<Map<int, Map<Stats, List<_HistoryChartSpot>>>>(
future: getHistoryData(fetchData),
Expand Down Expand Up @@ -247,7 +255,7 @@ class _DestinationGraphsState extends State<DestinationGraphs> {

Widget getLeagueState (){
return FutureBuilder<List<_MyScatterSpot>>(
future: getTetraLeagueData(_Xchart, _Ychart),
future: futureLeague,
builder: (context, snapshot) {
switch (snapshot.connectionState){
case ConnectionState.none:
Expand Down Expand Up @@ -340,6 +348,21 @@ class _DestinationGraphsState extends State<DestinationGraphs> {
spacing: 20,
crossAxisAlignment: WrapCrossAlignment.center,
children: [
if (_graph == Graph.leagueState) SizedBox(
width: 300,
child: TextField(
decoration: InputDecoration(
icon: Icon(Icons.search)
),
onChanged: (v){
searchLeague = v;
},
onSubmitted: (v){
searchLeague = v;
setState((){futureLeague = getTetraLeagueData(_Xchart, _Ychart);});
},
)
),
if (_graph == Graph.history) Row(
mainAxisSize: MainAxisSize.min,
children: [
Expand Down Expand Up @@ -404,6 +427,53 @@ class _DestinationGraphsState extends State<DestinationGraphs> {
Text(t.smooth, style: const TextStyle(color: Colors.white, fontSize: 22))
],
),
if (_graph == Graph.leagueState) IconButton(
color: excludeRanks.isNotEmpty ? Theme.of(context).colorScheme.primary : null,
onPressed: (){
showDialog(context: context, builder: (BuildContext context) {
return StatefulBuilder(
builder: (context, StateSetter setAlertState) {
return AlertDialog(
title: Text("Filter ranks on graph", textAlign: TextAlign.center),
content: SingleChildScrollView(
child: Column(
children: [
CheckboxListTile(value: getTotalFilterValue(), tristate: true, title: Text("All", style: TextStyle(fontFamily: "Eurostile Round Extended")), onChanged: (value){
setAlertState(
(){
if (excludeRanks.length*2 > ranks.length){
excludeRanks.clear();
}else{
excludeRanks = List.of(ranks);
}
}
);
}),
for(String rank in ranks.reversed) CheckboxListTile(value: excludeRanks.indexOf(rank) == -1, onChanged: (value){
setAlertState(
(){
if (excludeRanks.indexOf(rank) == -1){
excludeRanks.add(rank);
}else{
excludeRanks.remove(rank);
}
}
);
}, title: Text(rank.toUpperCase()),)
],
),
),
actions: <Widget>[
TextButton(
child: const Text("Apply"),
onPressed: () {Navigator.of(context).pop(); setState((){futureLeague = getTetraLeagueData(_Xchart, _Ychart);});}
)
]
);
}
);
});
}, icon: Icon(Icons.filter_alt)),
IconButton(onPressed: () => _zoomPanBehavior.reset(), icon: const Icon(Icons.refresh), alignment: Alignment.center,)
],
),
Expand Down
28 changes: 14 additions & 14 deletions lib/views/destination_home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,13 @@ class FetchResults{
class RecordSummary extends StatelessWidget{
final RecordSingle? record;
final bool hideRank;
final bool old;
final bool? betterThanRankAverage;
final MapEntry? closestAverage;
final bool? betterThanClosestAverage;
final String? rank;

const RecordSummary({super.key, required this.record, this.betterThanRankAverage, this.closestAverage, this.betterThanClosestAverage, this.rank, this.hideRank = false});
const RecordSummary({super.key, required this.record, this.betterThanRankAverage, this.closestAverage, this.old = false, this.betterThanClosestAverage, this.rank, this.hideRank = false});

@override
Widget build(BuildContext context) {
Expand All @@ -85,13 +86,12 @@ class RecordSummary extends StatelessWidget{
"zenithex" => "${f2.format(record!.stats.zenith!.altitude)} m",
_ => record!.stats.score.toString()
},
style: const TextStyle(fontFamily: "Eurostile Round", fontSize: 36, fontWeight: FontWeight.w500, color: Colors.white, height: 0.9),
style: TextStyle(fontFamily: "Eurostile Round", fontSize: 36, fontWeight: FontWeight.w500, color: old ? Colors.grey : Colors.white, height: 0.9),
),
),
RichText(
textAlign: hideRank ? TextAlign.center : TextAlign.start,
text: TextSpan(
text: "",
style: const TextStyle(fontFamily: "Eurostile Round", fontSize: 14, color: Colors.grey),
children: [
if (rank != null && rank != "z") TextSpan(text: "${t.verdictGeneral(n: switch(record!.gamemode){
Expand Down Expand Up @@ -158,7 +158,7 @@ class LeagueCard extends StatelessWidget{
)
else Text("Tetra League", style: Theme.of(context).textTheme.titleSmall),
const Divider(),
TLRatingThingy(userID: "", tlData: league, showPositions: true),
TLRatingThingy(userID: league.id, tlData: league, showPositions: true),
const Divider(),
RichText(text: TextSpan(
style: const TextStyle(fontFamily: "Eurostile Round", color: Colors.grey),
Expand Down Expand Up @@ -229,7 +229,7 @@ class _DestinationHomeState extends State<DestinationHome> with SingleTickerProv
const Divider(),
RecordSummary(record: summaries.sprint, betterThanClosestAverage: sprintBetterThanClosestAverage, betterThanRankAverage: sprintBetterThanRankAverage, closestAverage: closestAverageSprint, rank: summaries.league.percentileRank),
const Divider(),
Text("${summaries.sprint != null ? intf.format(summaries.sprint!.stats.piecesPlaced) : "---"} P • ${summaries.sprint != null ? f2.format(summaries.sprint!.stats.pps) : "---"} PPS • ${summaries.sprint != null ? f2.format(summaries.sprint!.stats.kpp) : "---"} KPP", style: const TextStyle(color: Colors.grey))
Text("${summaries.sprint != null ? intf.format(summaries.sprint!.stats.piecesPlaced) : "---"} P • ${summaries.sprint != null ? f2.format(summaries.sprint!.stats.pps) : "-.--"} PPS • ${summaries.sprint != null ? f2.format(summaries.sprint!.stats.kpp) : "-.--"} KPP", style: const TextStyle(color: Colors.grey))
],
),
),
Expand All @@ -246,7 +246,7 @@ class _DestinationHomeState extends State<DestinationHome> with SingleTickerProv
const Divider(),
RecordSummary(record: summaries.blitz, betterThanClosestAverage: blitzBetterThanClosestAverage, betterThanRankAverage: blitzBetterThanRankAverage, closestAverage: closestAverageBlitz, rank: summaries.league.percentileRank),
const Divider(),
Text("Level ${summaries.blitz != null ? intf.format(summaries.blitz!.stats.level): "--"} • ${summaries.blitz != null ? f2.format(summaries.blitz!.stats.spp) : "-.--"} SPP • ${summaries.blitz != null ? f2.format(summaries.blitz!.stats.pps) : "---"} PPS", style: const TextStyle(color: Colors.grey))
Text("Level ${summaries.blitz != null ? intf.format(summaries.blitz!.stats.level): "--"} • ${summaries.blitz != null ? f2.format(summaries.blitz!.stats.spp) : "-.--"} SPP • ${summaries.blitz != null ? f2.format(summaries.blitz!.stats.pps) : "-.--"} PPS", style: const TextStyle(color: Colors.grey))
],
),
),
Expand All @@ -266,7 +266,7 @@ class _DestinationHomeState extends State<DestinationHome> with SingleTickerProv
children: [
Text("QP", style: Theme.of(context).textTheme.titleSmall),
const Divider(),
RecordSummary(record: summaries.zenith, hideRank: true),
RecordSummary(record: summaries.zenith != null ? summaries.zenith : summaries.zenithCareerBest, hideRank: true, old: summaries.zenith == null),
const Divider(),
Text("Overall PB: ${(summaries.achievements.isNotEmpty && summaries.achievements.firstWhere((e) => e.k == 18).v != null) ? f2.format(summaries.achievements.firstWhere((e) => e.k == 18).v!) : "-.--"} m", style: const TextStyle(color: Colors.grey))
],
Expand All @@ -283,7 +283,7 @@ class _DestinationHomeState extends State<DestinationHome> with SingleTickerProv
children: [
Text("QP Expert", style: Theme.of(context).textTheme.titleSmall),
const Divider(),
RecordSummary(record: summaries.zenithEx, hideRank: true,),
RecordSummary(record: summaries.zenithEx != null ? summaries.zenithEx : summaries.zenithExCareerBest, hideRank: true, old: summaries.zenith == null),
const Divider(),
Text("Overall PB: ${(summaries.achievements.isNotEmpty && summaries.achievements.firstWhere((e) => e.k == 19).v != null) ? f2.format(summaries.achievements.firstWhere((e) => e.k == 19).v!) : "-.--"} m", style: const TextStyle(color: Colors.grey))
],
Expand Down Expand Up @@ -623,7 +623,7 @@ class _DestinationHomeState extends State<DestinationHome> with SingleTickerProv
);
}

Widget getZenithCard(RecordSingle? record){
Widget getZenithCard(RecordSingle? record, bool old){
return Column(
children: [
Card(
Expand All @@ -641,7 +641,7 @@ class _DestinationHomeState extends State<DestinationHome> with SingleTickerProv
),
),
),
ZenithThingy(zenith: record),
ZenithThingy(zenith: record, old: old),
if (record != null) Row(
children: [
Expanded(
Expand Down Expand Up @@ -1084,17 +1084,17 @@ class _DestinationHomeState extends State<DestinationHome> with SingleTickerProv
child: SlideTransition(
position: _offsetAnimation,
child: switch (rightCard){
Cards.overview => getOverviewCard(snapshot.data!.summaries!, (snapshot.data!.averages != null && snapshot.data!.summaries!.league.rank != "z") ? snapshot.data!.averages!.data[snapshot.data!.summaries!.league.rank] : (snapshot.data!.averages != null && snapshot.data!.summaries!.league.percentileRank != "z") ? snapshot.data!.averages!.data[snapshot.data!.summaries!.league.rank] : null),
Cards.overview => getOverviewCard(snapshot.data!.summaries!, (snapshot.data!.averages != null && snapshot.data!.summaries!.league.rank != "z") ? snapshot.data!.averages!.data[snapshot.data!.summaries!.league.rank] : (snapshot.data!.averages != null && snapshot.data!.summaries!.league.percentileRank != "z") ? snapshot.data!.averages!.data[snapshot.data!.summaries!.league.percentileRank] : null),
Cards.tetraLeague => switch (cardMod){
CardMod.info => getTetraLeagueCard(snapshot.data!.summaries!.league, snapshot.data!.cutoffs, (snapshot.data!.averages != null && snapshot.data!.summaries!.league.rank != "z") ? snapshot.data!.averages!.data[snapshot.data!.summaries!.league.rank] : (snapshot.data!.averages != null && snapshot.data!.summaries!.league.percentileRank != "z") ? snapshot.data!.averages!.data[snapshot.data!.summaries!.league.rank] : null, snapshot.data!.states),
CardMod.info => getTetraLeagueCard(snapshot.data!.summaries!.league, snapshot.data!.cutoffs, (snapshot.data!.averages != null && snapshot.data!.summaries!.league.rank != "z") ? snapshot.data!.averages!.data[snapshot.data!.summaries!.league.rank] : (snapshot.data!.averages != null && snapshot.data!.summaries!.league.percentileRank != "z") ? snapshot.data!.averages!.data[snapshot.data!.summaries!.league.percentileRank] : null, snapshot.data!.states),
CardMod.ex => getPreviousSeasonsList(snapshot.data!.summaries!.pastLeague),
CardMod.records => getRecentTLrecords(widget.constraints),
_ => const Center(child: Text("huh?"))
},
Cards.quickPlay => switch (cardMod){
CardMod.info => getZenithCard(snapshot.data?.summaries!.zenith),
CardMod.info => getZenithCard(snapshot.data?.summaries?.zenith != null ? snapshot.data!.summaries!.zenith : snapshot.data!.summaries?.zenithCareerBest, snapshot.data!.summaries?.zenith == null),
CardMod.records => getListOfRecords("zenith/recent", "zenith/top", widget.constraints),
CardMod.ex => getZenithCard(snapshot.data?.summaries!.zenithEx),
CardMod.ex => getZenithCard(snapshot.data?.summaries?.zenithEx != null ? snapshot.data!.summaries!.zenithEx : snapshot.data!.summaries?.zenithExCareerBest, snapshot.data!.summaries?.zenithEx == null),
CardMod.exRecords => getListOfRecords("zenithex/recent", "zenithex/top", widget.constraints),
},
Cards.sprint => switch (cardMod){
Expand Down
Loading

0 comments on commit ae7d92f

Please sign in to comment.