Skip to content

Commit da558ac

Browse files
committed
feat: add frames to compare time
1 parent cdeae01 commit da558ac

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

Diff for: GhostMod/GhostCompareTime.cs

+9-6
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ private static void LevelOnNextLevel(On.Celeste.Level.orig_NextLevel orig, Level
3838
private static void LevelOnRegisterAreaComplete(On.Celeste.Level.orig_RegisterAreaComplete orig, Level self) {
3939
orig(self);
4040

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

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

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

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

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

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

92-
if (self.Entities.FindFirst<Player>() is Player player) {
89+
if (self.Entities.FindFirst<Player>() is { } player) {
9390
Vector2 playerPosition = self.Camera.CameraToScreen(player.TopLeft) * pixelScale;
9491
Rectangle playerRect = new Rectangle((int)playerPosition.X, (int)playerPosition.Y, (int)(8 * pixelScale), (int)(11 * pixelScale));
9592
Rectangle mirrorBgRect = bgRect;
@@ -123,4 +120,10 @@ private static void LevelLoaderOnCtor(On.Celeste.LevelLoader.orig_ctor orig, Lev
123120
CurrentTime = 0;
124121
LastCurrentTime = 0;
125122
}
123+
124+
private static string FormatTime(long time) {
125+
string sign = time > 0 ? "+" : time < 0 ? "-" : "";
126+
TimeSpan timeSpan = TimeSpan.FromTicks(time);
127+
return $"{sign}{timeSpan.ShortGameplayFormat()}({time / TimeSpan.FromSeconds(Engine.RawDeltaTime).Ticks})";
128+
}
126129
}

0 commit comments

Comments
 (0)