Fix playtime formatting (#32974)
This commit is contained in:
committed by
Vasilis The Pikachu
parent
a4717556e1
commit
0468c0f6bb
@@ -36,6 +36,7 @@ namespace Content.Shared.Localizations
|
||||
_loc.AddFunction(culture, "LOC", FormatLoc);
|
||||
_loc.AddFunction(culture, "NATURALFIXED", FormatNaturalFixed);
|
||||
_loc.AddFunction(culture, "NATURALPERCENT", FormatNaturalPercent);
|
||||
_loc.AddFunction(culture, "PLAYTIME", FormatPlaytime);
|
||||
|
||||
|
||||
/*
|
||||
@@ -141,6 +142,16 @@ namespace Content.Shared.Localizations
|
||||
return Loc.GetString($"zzzz-fmt-direction-{dir.ToString()}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Formats playtime as hours and minutes.
|
||||
/// </summary>
|
||||
public static string FormatPlaytime(TimeSpan time)
|
||||
{
|
||||
var hours = (int)time.TotalHours;
|
||||
var minutes = time.Minutes;
|
||||
return Loc.GetString($"zzzz-fmt-playtime", ("hours", hours), ("minutes", minutes));
|
||||
}
|
||||
|
||||
private static ILocValue FormatLoc(LocArgs args)
|
||||
{
|
||||
var id = ((LocValueString) args.Args[0]).Value;
|
||||
@@ -229,5 +240,15 @@ namespace Content.Shared.Localizations
|
||||
|
||||
return new LocValueString(res);
|
||||
}
|
||||
|
||||
private static ILocValue FormatPlaytime(LocArgs args)
|
||||
{
|
||||
var time = TimeSpan.Zero;
|
||||
if (args.Args is { Count: > 0 } && args.Args[0].Value is TimeSpan timeArg)
|
||||
{
|
||||
time = timeArg;
|
||||
}
|
||||
return new LocValueString(FormatPlaytime(time));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Content.Shared.Localizations;
|
||||
using Content.Shared.Preferences;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.Prototypes;
|
||||
@@ -49,7 +50,7 @@ public sealed partial class DepartmentTimeRequirement : JobRequirement
|
||||
|
||||
var deptDiffSpan = Time - playtime;
|
||||
var deptDiff = deptDiffSpan.TotalMinutes;
|
||||
var formattedDeptDiff = deptDiffSpan.ToString(Loc.GetString("role-timer-time-format"));
|
||||
var formattedDeptDiff = ContentLocalizationManager.FormatPlaytime(deptDiffSpan);
|
||||
var nameDepartment = "role-timer-department-unknown";
|
||||
|
||||
if (protoManager.TryIndex(Department, out var departmentIndexed))
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Content.Shared.Localizations;
|
||||
using Content.Shared.Players.PlayTimeTracking;
|
||||
using Content.Shared.Preferences;
|
||||
using JetBrains.Annotations;
|
||||
@@ -27,7 +28,7 @@ public sealed partial class OverallPlaytimeRequirement : JobRequirement
|
||||
var overallTime = playTimes.GetValueOrDefault(PlayTimeTrackingShared.TrackerOverall);
|
||||
var overallDiffSpan = Time - overallTime;
|
||||
var overallDiff = overallDiffSpan.TotalMinutes;
|
||||
var formattedOverallDiff = overallDiffSpan.ToString(Loc.GetString("role-timer-time-format"));
|
||||
var formattedOverallDiff = ContentLocalizationManager.FormatPlaytime(overallDiffSpan);
|
||||
|
||||
if (!Inverted)
|
||||
{
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Content.Shared.Localizations;
|
||||
using Content.Shared.Players.PlayTimeTracking;
|
||||
using Content.Shared.Preferences;
|
||||
using Content.Shared.Roles.Jobs;
|
||||
@@ -36,7 +37,7 @@ public sealed partial class RoleTimeRequirement : JobRequirement
|
||||
playTimes.TryGetValue(proto, out var roleTime);
|
||||
var roleDiffSpan = Time - roleTime;
|
||||
var roleDiff = roleDiffSpan.TotalMinutes;
|
||||
var formattedRoleDiff = roleDiffSpan.ToString(Loc.GetString("role-timer-time-format"));
|
||||
var formattedRoleDiff = ContentLocalizationManager.FormatPlaytime(roleDiffSpan);
|
||||
var departmentColor = Color.Yellow;
|
||||
|
||||
if (entManager.EntitySysManager.TryGetEntitySystem(out SharedJobSystem? jobSystem))
|
||||
|
||||
Reference in New Issue
Block a user