diff --git a/Content.Shared/SS220/CCVars/CCVars220.cs b/Content.Shared/SS220/CCVars/CCVars220.cs index d3db5c577f95..c03fed725852 100644 --- a/Content.Shared/SS220/CCVars/CCVars220.cs +++ b/Content.Shared/SS220/CCVars/CCVars220.cs @@ -112,4 +112,10 @@ public sealed class CCVars220 /// public static readonly CVarDef DiscordLinkApiKey = CVarDef.Create("discord_auth.link_key", "", CVar.SERVERONLY | CVar.CONFIDENTIAL); + + /// + /// How different is the game year from the real one + /// + public static readonly CVarDef GameYearDelta = + CVarDef.Create("date.game_year_delta", 544, CVar.SERVER | CVar.REPLICATED); } diff --git a/Content.Shared/SS220/Paper/PaperAutoFormDatasetPrototype.cs b/Content.Shared/SS220/Paper/PaperAutoFormDatasetPrototype.cs new file mode 100644 index 000000000000..56808b3f8957 --- /dev/null +++ b/Content.Shared/SS220/Paper/PaperAutoFormDatasetPrototype.cs @@ -0,0 +1,15 @@ +// © SS220, An EULA/CLA with a hosting restriction, full text: https://raw.githubusercontent.com/SerbiaStrong-220/space-station-14/master/CLA.txt +using Robust.Shared.Prototypes; + +namespace Content.Shared.SS220.Paper; + +[Prototype("paperAutoFormDataset")] +public sealed partial class PaperAutoFormDatasetPrototype : IPrototype +{ + [ViewVariables] + [IdDataField] + public string ID { get; private set; } = default!; + + [DataField] + public Dictionary KeyWordsReplace = []; +} diff --git a/Content.Shared/SS220/Paper/PaperAutoFormSystem.cs b/Content.Shared/SS220/Paper/PaperAutoFormSystem.cs index cacf8644735c..4370de93cde0 100644 --- a/Content.Shared/SS220/Paper/PaperAutoFormSystem.cs +++ b/Content.Shared/SS220/Paper/PaperAutoFormSystem.cs @@ -1,10 +1,12 @@ // © SS220, An EULA/CLA with a hosting restriction, full text: https://raw.githubusercontent.com/SerbiaStrong-220/space-station-14/master/CLA.txt using Content.Shared.Access.Components; -using Content.Shared.Access.Systems; using Content.Shared.GameTicking; using Content.Shared.Inventory; using Content.Shared.Paper; using Content.Shared.PDA; +using Content.Shared.SS220.CCVars; +using Robust.Shared.Configuration; +using Robust.Shared.Prototypes; using Robust.Shared.Timing; using System.Text.RegularExpressions; @@ -12,24 +14,34 @@ namespace Content.Shared.SS220.Paper; public sealed partial class PaperAutoFormSystem : EntitySystem { + [Dependency] private readonly IConfigurationManager _configurationManager = default!; [Dependency] private readonly IGameTiming _gameTiming = default!; + [Dependency] private readonly IPrototypeManager _prototypeManager = default!; [Dependency] private readonly SharedGameTicker _gameTicker = default!; [Dependency] private readonly InventorySystem _inventorySystem = default!; - private readonly Dictionary _keyWordsReplace = new() + private const string AutoFormDatasetId = "PaperAutoFormDataset"; + + private readonly Dictionary _keyWordsReplace = []; + + private int _spaceYearDelta; + + public override void Initialize() { - { "%date", ReplacedData.Date }, - { "%дата", ReplacedData.Date }, - { "%time", ReplacedData.Time }, - { "%время", ReplacedData.Time }, - { "%name", ReplacedData.Name }, - { "%имя", ReplacedData.Name }, - { "%job", ReplacedData.Job }, - { "%должность", ReplacedData.Job } - }; + base.Initialize(); + _spaceYearDelta = _configurationManager.GetCVar(CCVars220.GameYearDelta); + + var dataset = _prototypeManager.Index(AutoFormDatasetId); + foreach (var (key, value) in dataset.KeyWordsReplace) + { + var locKey = Loc.GetString(key); + _keyWordsReplace.Add(locKey, value); + } + } public string ReplaceKeyWords(Entity ent, string content) { + // GenerateRegexAttribute cause errors on the client side and doesn't work return Regex.Replace(content, "\\u0025\\b(\\w+)\\b", match => { var word = match.Value.ToLower(); @@ -37,65 +49,69 @@ public string ReplaceKeyWords(Entity ent, string content) return word; var writer = ent.Comp.Writer; - switch (replacedData) + return replacedData switch { - case ReplacedData.Date: - { - var day = DateTime.UtcNow.AddHours(3).Day; - var month = DateTime.UtcNow.AddHours(3).Month; - var year = 2568; - return $"{day:00}.{month:00}.{year}"; - } - - case ReplacedData.Time: - { - var stationTime = _gameTiming.CurTime.Subtract(_gameTicker.RoundStartTimeSpan); - return stationTime.ToString("hh\\:mm\\:ss"); - } - - case ReplacedData.Name when writer != null: - { - if (TryComp(writer.Value, out var metaData)) - return metaData.EntityName; - break; - } - - case ReplacedData.Job when writer != null: - { - if (_inventorySystem.TryGetSlotEntity(writer.Value, "id", out var idUid)) - { - // PDA - if (EntityManager.TryGetComponent(idUid, out PdaComponent? pda) && - TryComp(pda.ContainedId, out var id) && - id.LocalizedJobTitle != null) - { - return id.LocalizedJobTitle; - } - - // ID Card - if (EntityManager.TryGetComponent(idUid, out id) && - id.LocalizedJobTitle != null) - { - return id.LocalizedJobTitle; - } - } - - break; - } - - default: - break; - } - - return word; + ReplacedData.Date => GetCurrentDate(), + ReplacedData.Time => GetStationTime(), + ReplacedData.Name => GetWriterName(writer) ?? word, + ReplacedData.Job => GetWriterJobByID(writer) ?? word, + _ => word + }; }); } - private enum ReplacedData : byte + private string GetCurrentDate() { - Date, - Time, - Name, - Job, + var day = DateTime.UtcNow.AddHours(3).Day; + var month = DateTime.UtcNow.AddHours(3).Month; + var year = DateTime.UtcNow.AddHours(3).Year + _spaceYearDelta; + return $"{day:00}.{month:00}.{year}"; } + + private string GetStationTime() + { + var stationTime = _gameTiming.CurTime.Subtract(_gameTicker.RoundStartTimeSpan); + return stationTime.ToString("hh\\:mm\\:ss"); + } + + private string? GetWriterName(EntityUid? writer) + { + if (writer is null || + !TryComp(writer.Value, out var metaData)) + return null; + + return metaData.EntityName; + } + + private string? GetWriterJobByID(EntityUid? writer) + { + if (writer is null || + !_inventorySystem.TryGetSlotEntity(writer.Value, "id", out var idUid)) + return null; + + string? job = null; + // PDA + if (EntityManager.TryGetComponent(idUid, out PdaComponent? pda) && + TryComp(pda.ContainedId, out var id) && + id.LocalizedJobTitle != null) + { + job = id.LocalizedJobTitle; + } + // ID Card + else if (EntityManager.TryGetComponent(idUid, out id) && + id.LocalizedJobTitle != null) + { + job = id.LocalizedJobTitle; + } + + return job; + } +} + +public enum ReplacedData : byte +{ + Date, + Time, + Name, + Job, } diff --git a/Resources/Locale/ru-RU/ss220/datasets/paper_auto_form.ftl b/Resources/Locale/ru-RU/ss220/datasets/paper_auto_form.ftl new file mode 100644 index 000000000000..153ec529a208 --- /dev/null +++ b/Resources/Locale/ru-RU/ss220/datasets/paper_auto_form.ftl @@ -0,0 +1,11 @@ +paper_auto_form_date_1 = %date +paper_auto_form_date_2 = %дата + +paper_auto_form_time_1 = %time +paper_auto_form_time_2 = %время + +paper_auto_form_name_1 = %name +paper_auto_form_name_2 = %имя + +paper_auto_form_job_1 = %job +paper_auto_form_job_2 = %должность diff --git a/Resources/Prototypes/SS220/Datasets/paper_auto_form.yml b/Resources/Prototypes/SS220/Datasets/paper_auto_form.yml new file mode 100644 index 000000000000..ab534e481608 --- /dev/null +++ b/Resources/Prototypes/SS220/Datasets/paper_auto_form.yml @@ -0,0 +1,11 @@ +- type: paperAutoFormDataset + id: PaperAutoFormDataset + keyWordsReplace: + paper_auto_form_date_1: Date + paper_auto_form_date_2: Date + paper_auto_form_time_1: Time + paper_auto_form_time_2: Time + paper_auto_form_name_1: Name + paper_auto_form_name_2: Name + paper_auto_form_job_1: Job + paper_auto_form_job_2: Job