]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Jobreq format (#32806)
authormetalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
Mon, 14 Oct 2024 03:54:31 +0000 (14:54 +1100)
committerGitHub <noreply@github.com>
Mon, 14 Oct 2024 03:54:31 +0000 (14:54 +1100)
* Format job requirements as hours and minutes

* Use TimeSpan.ToString for playtime instead of custom method

* wehflicts

---------

Co-authored-by: jmcb <joelsgp@protonmail.com>
Content.Client/Info/PlaytimeStats/PlaytimeStatsWindow.cs
Content.Shared/Roles/JobRequirement/AgeRequirement.cs
Content.Shared/Roles/JobRequirement/DepartmentTimeRequirement.cs
Content.Shared/Roles/JobRequirement/OverallPlaytimeRequirement.cs
Content.Shared/Roles/JobRequirement/RoleTimeRequirement.cs
Resources/Locale/en-US/info/playtime-stats.ftl
Resources/Locale/en-US/job/role-requirements.ftl

index 3b54bf82daf20701bc4cddc8007cb411699845c0..1a530d950f983f0e29d87e93864916c3c92c52e4 100644 (file)
@@ -104,7 +104,7 @@ public sealed partial class PlaytimeStatsWindow : FancyWindow
     {
         var overallPlaytime = _jobRequirementsManager.FetchOverallPlaytime();
 
-        var formattedPlaytime = ConvertTimeSpanToHoursMinutes(overallPlaytime);
+        var formattedPlaytime = overallPlaytime.ToString(Loc.GetString("ui-playtime-time-format"));
         OverallPlaytimeLabel.Text = Loc.GetString("ui-playtime-overall", ("time", formattedPlaytime));
 
         var rolePlaytimes = _jobRequirementsManager.FetchPlaytimeByRoles();
@@ -134,13 +134,4 @@ public sealed partial class PlaytimeStatsWindow : FancyWindow
             _sawmill.Error($"The provided playtime string '{playtimeString}' is not in the correct format.");
         }
     }
-
-    private static string ConvertTimeSpanToHoursMinutes(TimeSpan timeSpan)
-    {
-        var hours = (int) timeSpan.TotalHours;
-        var minutes = timeSpan.Minutes;
-
-        var formattedTimeLoc = Loc.GetString("ui-playtime-time-format", ("hours", hours), ("minutes", minutes));
-        return formattedTimeLoc;
-    }
 }
index 75a77ae155652eccd8ff9d15d3502bdfbe3c10e8..30f607adf7fd09ff7723c563759a903c4b247811 100644 (file)
@@ -30,7 +30,7 @@ public sealed partial class AgeRequirement : JobRequirement
 
         if (!Inverted)
         {
-            reason = FormattedMessage.FromMarkupPermissive(Loc.GetString("role-timer-age-to-young",
+            reason = FormattedMessage.FromMarkupPermissive(Loc.GetString("role-timer-age-too-young",
                 ("age", RequiredAge)));
 
             if (profile.Age < RequiredAge)
@@ -38,7 +38,7 @@ public sealed partial class AgeRequirement : JobRequirement
         }
         else
         {
-            reason = FormattedMessage.FromMarkupPermissive(Loc.GetString("role-timer-age-to-old",
+            reason = FormattedMessage.FromMarkupPermissive(Loc.GetString("role-timer-age-too-old",
                 ("age", RequiredAge)));
 
             if (profile.Age > RequiredAge)
index 56b7d8ba811b56f6f68a7c477447e74e6365c85a..78c6bd251779846c825310ddbd41c84000a2a7ac 100644 (file)
@@ -15,7 +15,7 @@ public sealed partial class DepartmentTimeRequirement : JobRequirement
     /// Which department needs the required amount of time.
     /// </summary>
     [DataField(required: true)]
-    public ProtoId<DepartmentPrototype> Department = default!;
+    public ProtoId<DepartmentPrototype> Department;
 
     /// <summary>
     /// How long (in seconds) this requirement is.
@@ -47,7 +47,9 @@ public sealed partial class DepartmentTimeRequirement : JobRequirement
             playtime += otherTime;
         }
 
-        var deptDiff = Time.TotalMinutes - playtime.TotalMinutes;
+        var deptDiffSpan = Time - playtime;
+        var deptDiff = deptDiffSpan.TotalMinutes;
+        var formattedDeptDiff = deptDiffSpan.ToString(Loc.GetString("role-timer-time-format"));
         var nameDepartment = "role-timer-department-unknown";
 
         if (protoManager.TryIndex(Department, out var departmentIndexed))
@@ -62,7 +64,7 @@ public sealed partial class DepartmentTimeRequirement : JobRequirement
 
             reason = FormattedMessage.FromMarkupPermissive(Loc.GetString(
                 "role-timer-department-insufficient",
-                ("time", Math.Ceiling(deptDiff)),
+                ("time", formattedDeptDiff),
                 ("department", Loc.GetString(nameDepartment)),
                 ("departmentColor", department.Color.ToHex())));
             return false;
@@ -72,7 +74,7 @@ public sealed partial class DepartmentTimeRequirement : JobRequirement
         {
             reason = FormattedMessage.FromMarkupPermissive(Loc.GetString(
                 "role-timer-department-too-high",
-                ("time", -deptDiff),
+                ("time", formattedDeptDiff),
                 ("department", Loc.GetString(nameDepartment)),
                 ("departmentColor", department.Color.ToHex())));
             return false;
index acbb8f2b4d471675ff7d99114ddeaf0e383a80d2..ed985cadfba07ede18079355648206b956ece3a7 100644 (file)
@@ -25,7 +25,9 @@ public sealed partial class OverallPlaytimeRequirement : JobRequirement
         reason = new FormattedMessage();
 
         var overallTime = playTimes.GetValueOrDefault(PlayTimeTrackingShared.TrackerOverall);
-        var overallDiff = Time.TotalMinutes - overallTime.TotalMinutes;
+        var overallDiffSpan = Time - overallTime;
+        var overallDiff = overallDiffSpan.TotalMinutes;
+        var formattedOverallDiff = overallDiffSpan.ToString(Loc.GetString("role-timer-time-format"));
 
         if (!Inverted)
         {
@@ -34,14 +36,14 @@ public sealed partial class OverallPlaytimeRequirement : JobRequirement
 
             reason = FormattedMessage.FromMarkupPermissive(Loc.GetString(
                 "role-timer-overall-insufficient",
-                ("time", Math.Ceiling(overallDiff))));
+                ("time", formattedOverallDiff)));
             return false;
         }
 
         if (overallDiff <= 0 || overallTime >= Time)
         {
             reason = FormattedMessage.FromMarkupPermissive(Loc.GetString("role-timer-overall-too-high",
-                ("time", -overallDiff)));
+                ("time", formattedOverallDiff)));
             return false;
         }
 
index 658db95ab566eb19516985ff5f809760cd020f01..23498ab91ad21c8eee1be1b0f1aec949599266e8 100644 (file)
@@ -17,7 +17,7 @@ public sealed partial class RoleTimeRequirement : JobRequirement
     /// What particular role they need the time requirement with.
     /// </summary>
     [DataField(required: true)]
-    public ProtoId<PlayTimeTrackerPrototype> Role = default!;
+    public ProtoId<PlayTimeTrackerPrototype> Role;
 
     /// <inheritdoc cref="DepartmentTimeRequirement.Time"/>
     [DataField(required: true)]
@@ -34,7 +34,9 @@ public sealed partial class RoleTimeRequirement : JobRequirement
         string proto = Role;
 
         playTimes.TryGetValue(proto, out var roleTime);
-        var roleDiff = Time.TotalMinutes - roleTime.TotalMinutes;
+        var roleDiffSpan = Time - roleTime;
+        var roleDiff = roleDiffSpan.TotalMinutes;
+        var formattedRoleDiff = roleDiffSpan.ToString(Loc.GetString("role-timer-time-format"));
         var departmentColor = Color.Yellow;
 
         if (entManager.EntitySysManager.TryGetEntitySystem(out SharedJobSystem? jobSystem))
@@ -52,7 +54,7 @@ public sealed partial class RoleTimeRequirement : JobRequirement
 
             reason = FormattedMessage.FromMarkupPermissive(Loc.GetString(
                 "role-timer-role-insufficient",
-                ("time", Math.Ceiling(roleDiff)),
+                ("time", formattedRoleDiff),
                 ("job", Loc.GetString(proto)),
                 ("departmentColor", departmentColor.ToHex())));
             return false;
@@ -62,7 +64,7 @@ public sealed partial class RoleTimeRequirement : JobRequirement
         {
             reason = FormattedMessage.FromMarkupPermissive(Loc.GetString(
                 "role-timer-role-too-high",
-                ("time", -roleDiff),
+                ("time", formattedRoleDiff),
                 ("job", Loc.GetString(proto)),
                 ("departmentColor", departmentColor.ToHex())));
             return false;
index 44ba39c25e9e0811115bcfb1c28799327ebb5489..85508c1d09cd9b5ac474aef75c786606aad5f6eb 100644 (file)
@@ -5,6 +5,6 @@ ui-playtime-overall-base = Overall Playtime:
 ui-playtime-overall = Overall Playtime: {$time}
 ui-playtime-first-time = First Time Playing
 ui-playtime-roles = Playtime per Role
-ui-playtime-time-format = {$hours}H {$minutes}M
+ui-playtime-time-format = %h\H\ %m\M
 ui-playtime-header-role-type = Role
 ui-playtime-header-role-time = Time
index 00281fa6cd5e7585c7b994d2f8baf545e47b9477..79a216fccaf41fb8e39d9464c1fb1db4c17f5143 100644 (file)
@@ -1,11 +1,12 @@
-role-timer-department-insufficient = You require [color=yellow]{TOSTRING($time, "0")}[/color] more minutes of [color={$departmentColor}]{$department}[/color] department playtime to play this role.
-role-timer-department-too-high = You require [color=yellow]{TOSTRING($time, "0")}[/color] fewer minutes in [color={$departmentColor}]{$department}[/color] department to play this role. (Are you trying to play a trainee role?)
-role-timer-overall-insufficient = You require [color=yellow]{TOSTRING($time, "0")}[/color] more minutes of playtime to play this role.
-role-timer-overall-too-high = You require [color=yellow]{TOSTRING($time, "0")}[/color] fewer minutes of playtime to play this role. (Are you trying to play a trainee role?)
-role-timer-role-insufficient = You require [color=yellow]{TOSTRING($time, "0")}[/color] more minutes with [color={$departmentColor}]{$job}[/color] to play this role.
-role-timer-role-too-high = You require[color=yellow] {TOSTRING($time, "0")}[/color] fewer minutes with [color={$departmentColor}]{$job}[/color] to play this role. (Are you trying to play a trainee role?)
-role-timer-age-to-old = Your character's age must be at most [color=yellow]{$age}[/color] to play this role.
-role-timer-age-to-young = Your character's age must be at least [color=yellow]{$age}[/color] to play this role.
+role-timer-department-insufficient = You require [color=yellow]{$time}[/color] more playtime in the [color={$departmentColor}]{$department}[/color] department to play this role.
+role-timer-department-too-high = You require [color=yellow]{$time}[/color] less playtime in the [color={$departmentColor}]{$department}[/color] department to play this role. (Are you trying to play a trainee role?)
+role-timer-overall-insufficient = You require [color=yellow]{$time}[/color] more overall playtime to play this role.
+role-timer-overall-too-high = You require [color=yellow]{$time}[/color] less overall playtime to play this role. (Are you trying to play a trainee role?)
+role-timer-role-insufficient = You require [color=yellow]{$time}[/color] more playtime with [color={$departmentColor}]{$job}[/color] to play this role.
+role-timer-role-too-high = You require[color=yellow] {$time}[/color] less playtime with [color={$departmentColor}]{$job}[/color] to play this role. (Are you trying to play a trainee role?)
+role-timer-time-format = %h\H\ %m\M
+role-timer-age-too-old = Your character must be under the age of [color=yellow]{$age}[/color] to play this role.
+role-timer-age-too-young = Your character must be over the age of [color=yellow]{$age}[/color] to play this role.
 role-timer-whitelisted-species = Your character must be one of the following species to play this role:
 role-timer-blacklisted-species = Your character must not be one of the following species to play this role:
 role-timer-whitelisted-traits = Your character must have one of the following traits: