@@ -513,30 +513,9 @@ void OnMapChange(CGameCtnChallenge@ map)
513513 global_active_game_mode = GameMode :: Unknown;
514514 }
515515
516- auto trackmania = cast<CTrackMania@ >(GetApp());
517- auto network = trackmania.Network ;
518- if (network.ClientManiaAppPlayground ! is null ) {
519- auto userMgr = network.ClientManiaAppPlayground.UserMgr ;
520- MwId userId ;
521- if (userMgr.Users.Length > 0 ) {
522- userId = userMgr.Users [0 ].Id ;
523- } else {
524- userId.Value = uint (- 1 );
525- }
526-
527- auto scoreMgr = network.ClientManiaAppPlayground.ScoreMgr ;
528- uint newPbTime = scoreMgr.Map_GetRecord_v2(userId, map.MapInfo.MapUid , " PersonalBest" , " " , " TimeAttack" , " " );
529- if (newPbTime ! = 0 ) {
530- pb.time = newPbTime;
531- print(pb.coloredIcon() + Time :: Format(pb.time ));
532- if (setting_add_pb_on_map_change && pb.hasTime()) {
533- auto run = Run(runs.NextRunID(), pb.time , GetHardestMedalBeaten(pb.time ));
534- run.isPB = true ;
535- runs.AddRun(run);
536- }
537- }
538- }
539- UpdateCurrentTarget();
516+ startnew(function() {
517+ UpdateCustomMedalTime(pb, function() { return GetPBTime(); });
518+ });
540519
541520#if DEPENDENCY_CHAMPIONMEDALS
542521 startnew(function() {
@@ -550,6 +529,31 @@ void OnMapChange(CGameCtnChallenge@ map)
550529#endif
551530}
552531
532+ int GetPBTime() {
533+
534+ auto trackmania = cast<CTrackMania@ >(GetApp());
535+ auto map = trackmania.RootMap ;
536+ auto network = trackmania.Network ;
537+ if (network.ClientManiaAppPlayground is null ) {
538+ return 0 ;
539+ }
540+
541+ auto userMgr = network.ClientManiaAppPlayground.UserMgr ;
542+ MwId userId ;
543+ if (userMgr.Users.Length > 0 ) {
544+ userId = userMgr.Users [0 ].Id ;
545+ } else {
546+ userId.Value = uint (- 1 );
547+ }
548+
549+ auto scoreMgr = network.ClientManiaAppPlayground.ScoreMgr ;
550+ uint newPbTime = scoreMgr.Map_GetRecord_v2(userId, map.MapInfo.MapUid , " PersonalBest" , " " , " TimeAttack" , " " );
551+ if (newPbTime < 0 ) {
552+ return 0 ;
553+ }
554+ return newPbTime ;
555+ }
556+
553557funcdef int MedalTimeCB();
554558
555559void UpdateCustomMedalTime(Target @ medal , MedalTimeCB @ GetTime ) {
@@ -558,12 +562,15 @@ void UpdateCustomMedalTime(Target @medal, MedalTimeCB @GetTime) {
558562 && attempts < MAX_CUSTOM_MEDAL_UPDATE_ATTEMPTS_PER_MAP
559563 ) {
560564 attempts += 1 ;
561- sleep(1000 * attempts);
565+ sleep(500 * attempts);
562566
563567 int newTime = GetTime();
564- if (medal.time ! = int ( newTime) ) {
568+ if (newTime > 0 && medal.time ! = newTime) {
565569 medal.time = newTime;
566570 print(medal.coloredIcon() + Time :: Format(medal.time ) + " attempt#" + attempts);
571+ if (@ medal == @ pb ) {
572+ OnMapPBFound();
573+ }
567574 UpdateCurrentTarget();
568575 return ;
569576 }
@@ -581,4 +588,19 @@ void OnThresholdsTableChange()
581588void OnClearHistory()
582589{
583590 runs.Clear();
584- }
591+ }
592+
593+ void OnMapPBFound()
594+ {
595+ if (! pb.hasTime()) {
596+ warn(" Invalid PB: " + pb.time );
597+ return ;
598+ }
599+ print(" PB found " + pb.coloredIcon() + Time :: Format(pb.time ));
600+
601+ if (setting_add_pb_on_map_change && pb.hasTime()) {
602+ auto run = Run(runs.NextRunID(), pb.time , GetHardestMedalBeaten(pb.time ));
603+ run.isPB = true ;
604+ runs.AddRun(run);
605+ }
606+ }
0 commit comments