Skip to content

Commit

Permalink
return date & tine tags
Browse files Browse the repository at this point in the history
  • Loading branch information
Kirus59 committed Jan 17, 2025
1 parent 3353a5a commit 4d8a5a0
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
6 changes: 5 additions & 1 deletion Content.Shared/Paper/PaperSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public sealed class PaperSystem : EntitySystem
[Dependency] private readonly SharedUserInterfaceSystem _uiSystem = default!;
[Dependency] private readonly MetaDataSystem _metaSystem = default!;
[Dependency] private readonly SharedAudioSystem _audio = default!;
[Dependency] private readonly SharedDocumentHelperSystem _documentHelper = default!;

public override void Initialize()
{
Expand Down Expand Up @@ -203,7 +204,10 @@ public bool TryStamp(Entity<PaperComponent> entity, StampDisplayInfo stampInfo,

public void SetContent(Entity<PaperComponent> entity, string content)
{
entity.Comp.Content = content;
// SS220 Add document tags begin
//entity.Comp.Content = content;
entity.Comp.Content = _documentHelper.ParseTags(entity, content);
// SS220 Add document tags end
Dirty(entity);
UpdateUserInterface(entity);

Expand Down
31 changes: 29 additions & 2 deletions Content.Shared/SS220/Paper/SharedDocumentHelperSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
using Content.Shared.Access.Components;
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.Serialization;
using Robust.Shared.Timing;
using System.Linq;
using System.Text.RegularExpressions;

namespace Content.Shared.SS220.Paper;

Expand All @@ -19,15 +21,40 @@ public abstract partial class SharedDocumentHelperSystem : EntitySystem
[Dependency] private readonly InventorySystem _inventorySystem = default!;

private int _gameYearDelta;
private readonly Dictionary<string, DocumentHelperOptions> _allowedTags = new()
{
{"%date", DocumentHelperOptions.Date},
{"%time", DocumentHelperOptions.Time},
};

public override void Initialize()
{
base.Initialize();
_gameYearDelta = _configurationManager.GetCVar(CCVars220.GameYearDelta);
}

#region Paper
public virtual string ParseTags(Entity<PaperComponent> 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();
if (!_allowedTags.TryGetValue(word, out var replacedData))
return word;

return replacedData switch
{
DocumentHelperOptions.Date => GetGameDate(),
DocumentHelperOptions.Time => GetStationTime(),
_ => word
};
});
}
#endregion

#region Date
public string GetCurrentDate()
public string GetGameDate()
{
var day = DateTime.UtcNow.AddHours(3).Day;
var month = DateTime.UtcNow.AddHours(3).Month;
Expand Down Expand Up @@ -145,7 +172,7 @@ public virtual List<string> GetValuesByOption(DocumentHelperOptions option, Enti
switch (option)
{
case DocumentHelperOptions.Date:
values.Add(GetCurrentDate());
values.Add(GetGameDate());
break;
case DocumentHelperOptions.Time:
values.Add(GetStationTime());
Expand Down

0 comments on commit 4d8a5a0

Please sign in to comment.