Skip to content

Commit

Permalink
feat: add frames to compare time
Browse files Browse the repository at this point in the history
  • Loading branch information
DemoJameson committed Mar 14, 2023
1 parent cdeae01 commit da558ac
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions GhostMod/GhostCompareTime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ private static void LevelOnNextLevel(On.Celeste.Level.orig_NextLevel orig, Level
private static void LevelOnRegisterAreaComplete(On.Celeste.Level.orig_RegisterAreaComplete orig, Level self) {
orig(self);

if (GhostModule.Instance.GhostManager?.Ghosts.FirstOrDefault()?.Data.Frames.LastOrDefault().Data.Time is long time) {
if (GhostModule.Instance.GhostManager?.Ghosts.FirstOrDefault()?.Data.Frames.LastOrDefault().Data.Time is { } time) {
LastGhostTime = GhostTime;
GhostTime = time;
LastCurrentTime = CurrentTime;
Expand All @@ -51,7 +51,6 @@ private static void LevelOnRender(On.Celeste.Level.orig_Render orig, Level self)

if (GhostModule.ModuleSettings.Mode == GhostModuleMode.Play && GhostModule.ModuleSettings.ShowCompareTime) {
int viewWidth = Engine.ViewWidth;
int viewHeight = Engine.ViewHeight;

float pixelScale = viewWidth / 320f;
float margin = 2 * pixelScale;
Expand All @@ -65,9 +64,7 @@ private static void LevelOnRender(On.Celeste.Level.orig_Render orig, Level self)

long diffRoomTime = CurrentTime - GhostTime - LastCurrentTime + LastGhostTime;
long diffTotalTime = CurrentTime - GhostTime;
string diffRoomTimeStr = (diffRoomTime > 0 ? "+" : string.Empty) + (diffRoomTime / 10000000D).ToString("0.000");
string diffTotalTimeStr = (diffTotalTime > 0 ? "+" : string.Empty) + (diffTotalTime / 10000000D).ToString("0.000");
string timeStr = $"last room: {diffRoomTimeStr}\ntotal : {diffTotalTimeStr}";
string timeStr = $"last room: {FormatTime(diffRoomTime)}\ntotal : {FormatTime(diffTotalTime)}";

if (string.IsNullOrEmpty(timeStr)) {
return;
Expand All @@ -89,7 +86,7 @@ private static void LevelOnRender(On.Celeste.Level.orig_Render orig, Level self)

Rectangle bgRect = new Rectangle((int)x, (int)y, (int)(size.X + padding * 2), (int)(size.Y + padding * 2));

if (self.Entities.FindFirst<Player>() is Player player) {
if (self.Entities.FindFirst<Player>() is { } player) {
Vector2 playerPosition = self.Camera.CameraToScreen(player.TopLeft) * pixelScale;
Rectangle playerRect = new Rectangle((int)playerPosition.X, (int)playerPosition.Y, (int)(8 * pixelScale), (int)(11 * pixelScale));
Rectangle mirrorBgRect = bgRect;
Expand Down Expand Up @@ -123,4 +120,10 @@ private static void LevelLoaderOnCtor(On.Celeste.LevelLoader.orig_ctor orig, Lev
CurrentTime = 0;
LastCurrentTime = 0;
}

private static string FormatTime(long time) {
string sign = time > 0 ? "+" : time < 0 ? "-" : "";
TimeSpan timeSpan = TimeSpan.FromTicks(time);
return $"{sign}{timeSpan.ShortGameplayFormat()}({time / TimeSpan.FromSeconds(Engine.RawDeltaTime).Ticks})";
}
}

0 comments on commit da558ac

Please sign in to comment.