From 71c9894903c8a47f13c227dadec42cadea4bf7ac Mon Sep 17 00:00:00 2001 From: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> Date: Mon, 14 Oct 2024 14:54:31 +1100 Subject: [PATCH] Jobreq format (#32806) * Format job requirements as hours and minutes * Use TimeSpan.ToString for playtime instead of custom method * wehflicts --------- Co-authored-by: jmcb --- .../Info/PlaytimeStats/PlaytimeStatsWindow.cs | 11 +---------- .../Roles/JobRequirement/AgeRequirement.cs | 4 ++-- .../JobRequirement/DepartmentTimeRequirement.cs | 10 ++++++---- .../OverallPlaytimeRequirement.cs | 8 +++++--- .../Roles/JobRequirement/RoleTimeRequirement.cs | 10 ++++++---- Resources/Locale/en-US/info/playtime-stats.ftl | 2 +- .../Locale/en-US/job/role-requirements.ftl | 17 +++++++++-------- 7 files changed, 30 insertions(+), 32 deletions(-) diff --git a/Content.Client/Info/PlaytimeStats/PlaytimeStatsWindow.cs b/Content.Client/Info/PlaytimeStats/PlaytimeStatsWindow.cs index 3b54bf82da..1a530d950f 100644 --- a/Content.Client/Info/PlaytimeStats/PlaytimeStatsWindow.cs +++ b/Content.Client/Info/PlaytimeStats/PlaytimeStatsWindow.cs @@ -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; - } } diff --git a/Content.Shared/Roles/JobRequirement/AgeRequirement.cs b/Content.Shared/Roles/JobRequirement/AgeRequirement.cs index 75a77ae155..30f607adf7 100644 --- a/Content.Shared/Roles/JobRequirement/AgeRequirement.cs +++ b/Content.Shared/Roles/JobRequirement/AgeRequirement.cs @@ -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) diff --git a/Content.Shared/Roles/JobRequirement/DepartmentTimeRequirement.cs b/Content.Shared/Roles/JobRequirement/DepartmentTimeRequirement.cs index 56b7d8ba81..78c6bd2517 100644 --- a/Content.Shared/Roles/JobRequirement/DepartmentTimeRequirement.cs +++ b/Content.Shared/Roles/JobRequirement/DepartmentTimeRequirement.cs @@ -15,7 +15,7 @@ public sealed partial class DepartmentTimeRequirement : JobRequirement /// Which department needs the required amount of time. /// [DataField(required: true)] - public ProtoId Department = default!; + public ProtoId Department; /// /// 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; diff --git a/Content.Shared/Roles/JobRequirement/OverallPlaytimeRequirement.cs b/Content.Shared/Roles/JobRequirement/OverallPlaytimeRequirement.cs index acbb8f2b4d..ed985cadfb 100644 --- a/Content.Shared/Roles/JobRequirement/OverallPlaytimeRequirement.cs +++ b/Content.Shared/Roles/JobRequirement/OverallPlaytimeRequirement.cs @@ -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; } diff --git a/Content.Shared/Roles/JobRequirement/RoleTimeRequirement.cs b/Content.Shared/Roles/JobRequirement/RoleTimeRequirement.cs index 658db95ab5..23498ab91a 100644 --- a/Content.Shared/Roles/JobRequirement/RoleTimeRequirement.cs +++ b/Content.Shared/Roles/JobRequirement/RoleTimeRequirement.cs @@ -17,7 +17,7 @@ public sealed partial class RoleTimeRequirement : JobRequirement /// What particular role they need the time requirement with. /// [DataField(required: true)] - public ProtoId Role = default!; + public ProtoId Role; /// [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; diff --git a/Resources/Locale/en-US/info/playtime-stats.ftl b/Resources/Locale/en-US/info/playtime-stats.ftl index 44ba39c25e..85508c1d09 100644 --- a/Resources/Locale/en-US/info/playtime-stats.ftl +++ b/Resources/Locale/en-US/info/playtime-stats.ftl @@ -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 diff --git a/Resources/Locale/en-US/job/role-requirements.ftl b/Resources/Locale/en-US/job/role-requirements.ftl index 00281fa6cd..79a216fcca 100644 --- a/Resources/Locale/en-US/job/role-requirements.ftl +++ b/Resources/Locale/en-US/job/role-requirements.ftl @@ -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: -- 2.52.0