using System.Linq; using Content.Shared.Examine; using Content.Shared.GameTicking; namespace Content.Shared.Clock; public abstract class SharedClockSystem : EntitySystem { [Dependency] private readonly SharedGameTicker _ticker = default!; /// public override void Initialize() { SubscribeLocalEvent(OnExamined); } private void OnExamined(Entity ent, ref ExaminedEvent args) { if (!args.IsInDetailsRange) return; args.PushMarkup(Loc.GetString("clock-examine", ("time", GetClockTimeText(ent)))); } public string GetClockTimeText(Entity ent) { var time = GetClockTime(ent); switch (ent.Comp.ClockType) { case ClockType.TwelveHour: return time.ToString(@"h\:mm"); case ClockType.TwentyFourHour: return time.ToString(@"hh\:mm"); default: throw new ArgumentOutOfRangeException(); } } private TimeSpan GetGlobalTime() { return (EntityQuery().FirstOrDefault()?.TimeOffset ?? TimeSpan.Zero) + _ticker.RoundDuration(); } public TimeSpan GetClockTime(Entity ent) { var comp = ent.Comp; if (comp.StuckTime != null) return comp.StuckTime.Value; var time = GetGlobalTime(); switch (comp.ClockType) { case ClockType.TwelveHour: var adjustedHours = time.Hours % 12; if (adjustedHours == 0) adjustedHours = 12; return new TimeSpan(adjustedHours, time.Minutes, time.Seconds); case ClockType.TwentyFourHour: return time; default: throw new ArgumentOutOfRangeException(); } } }