Skip to content

Commit

Permalink
Merge branch 'main' of github.com:Vanawy/tm-run-history
Browse files Browse the repository at this point in the history
  • Loading branch information
Vanawy committed Jan 6, 2025
2 parents ed33621 + 21bd100 commit 9921d65
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 9 deletions.
35 changes: 28 additions & 7 deletions src/dnf_detector.as
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class DnfHandler {
protected uint last_start_time = 0;
protected MLFeed::SpawnStatus last_spawn_status = MLFeed::SpawnStatus::Spawning;
protected bool is_running = false;
protected bool last_finish_state = false;

Expand All @@ -8,15 +8,36 @@ class DnfHandler {
if (cpInfo is null) {
return false;
}
if (is_running && cpInfo.StartTime > last_start_time) {
last_start_time = cpInfo.StartTime;
if (!last_finish_state) {

if (!is_running && UI::CurrentActionMap() != "SpectatorMap" && cpInfo.CurrentRaceTime < 0 && cpInfo.SpawnStatus == MLFeed::SpawnStatus::Spawning) {
is_running = true;
return false;
}

if (is_running && cpInfo.SpawnStatus != last_spawn_status) {
last_spawn_status = cpInfo.SpawnStatus;

if (!last_finish_state && cpInfo.SpawnStatus == MLFeed::SpawnStatus::Spawning) {
return true;
}
}
is_running = true;
last_start_time = cpInfo.StartTime;
last_finish_state = cpInfo.IsFinished;

if (cpInfo.IsFinished) {
last_finish_state = true;
} else if (cpInfo.SpawnStatus == MLFeed::SpawnStatus::Spawned) {
last_finish_state = false;
}

return false;
}

void Reset() {
last_spawn_status = MLFeed::SpawnStatus::Spawning;
is_running = false;
last_finish_state = false;
}

bool IsRunning() {
return is_running;
}
}
6 changes: 4 additions & 2 deletions src/main.as
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ void Main()
yield();

auto race = MLFeed::GetRaceData_V4();
auto playerData = race.GetPlayer_V4(MLFeed::LocalPlayersName);
auto playerData = race.LocalPlayer;
if (playerData !is null) {
// print(playerData.spawnIndex);
if (runs.current !is null) {
Expand Down Expand Up @@ -128,6 +128,8 @@ void Main()
lastMapId = map.MapInfo.MapUid;
OnMapChange(map);
}
} else if (dnf_handler.IsRunning()) {
dnf_handler.Reset();
}
}
}
Expand Down Expand Up @@ -449,7 +451,7 @@ void OnFinishedRun(const int lastTime)


auto raceData = MLFeed::GetRaceData_V4();
auto playerData = raceData.GetPlayer_V4(MLFeed::LocalPlayersName);
auto playerData = raceData.LocalPlayer;
if (playerData !is null) {
auto noRespawnTime = playerData.LastTheoreticalCpTime;
auto norespawnTarget = GetHardestMedalBeaten(noRespawnTime);
Expand Down

0 comments on commit 9921d65

Please sign in to comment.