--- /dev/null
+using Content.Shared.MassMedia.Systems;
+
+namespace Content.Client.MassMedia;
+
+public sealed class NewsSystem : SharedNewsSystem
+{
+
+}
-using Robust.Shared.Timing;
using JetBrains.Annotations;
-using Robust.Client.GameObjects;
-using Content.Shared.MassMedia.Systems;
using Content.Shared.MassMedia.Components;
-using Content.Client.GameTicking.Managers;
+using Content.Shared.MassMedia.Systems;
using Robust.Shared.Utility;
namespace Content.Client.MassMedia.Ui
[ViewVariables]
private NewsWriteMenu? _menu;
- [Dependency] private readonly IEntitySystemManager _entitySystem = default!;
- [Dependency] private readonly IGameTiming _gameTiming = default!;
- private ClientGameTicker? _gameTicker;
-
[ViewVariables]
private string _windowName = Loc.GetString("news-read-ui-default-title");
public NewsWriteBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
{
-
}
protected override void Open()
_menu.ShareButtonPressed += OnShareButtonPressed;
_menu.DeleteButtonPressed += OnDeleteButtonPressed;
- _gameTicker = _entitySystem.GetEntitySystem<ClientGameTicker>();
-
SendMessage(new NewsWriteArticlesRequestMessage());
}
var stringContent = Rope.Collapse(_menu.ContentInput.TextRope);
- if (stringContent == null || stringContent.Length == 0)
+ if (stringContent.Length == 0)
return;
- var stringName = _menu.NameInput.Text;
- var name = (stringName.Length <= 25 ? stringName.Trim() : $"{stringName.Trim().Substring(0, 25)}...");
+ var stringName = _menu.NameInput.Text.Trim();
+ var name = stringName[..(SharedNewsSystem.MaxNameLength)];
+ var content = stringContent[..(SharedNewsSystem.MaxArticleLength)];
_menu.ContentInput.TextRope = new Rope.Leaf(string.Empty);
_menu.NameInput.Text = string.Empty;
- SendMessage(new NewsWriteShareMessage(name, stringContent));
+ SendMessage(new NewsWriteShareMessage(name, content));
}
private void OnDeleteButtonPressed(int articleNum)
{
- if (_menu == null) return;
+ if (_menu == null)
+ return;
SendMessage(new NewsWriteDeleteMessage(articleNum));
}
namespace Content.Server.MassMedia.Systems;
-public sealed class NewsSystem : EntitySystem
+public sealed class NewsSystem : SharedNewsSystem
{
[Dependency] private readonly IGameTiming _timing = default!;
[Dependency] private readonly UserInterfaceSystem _ui = default!;
[Dependency] private readonly StationRecordsSystem _stationRecords = default!;
// TODO remove this. Dont store data on systems
+ // Honestly NewsSystem just needs someone to rewrite it entirely.
private readonly List<NewsArticle> _articles = new List<NewsArticle>();
public override void Initialize()
private void OnRoundRestart(RoundRestartCleanupEvent ev)
{
- _articles?.Clear();
+ _articles.Clear();
}
public void ToggleUi(EntityUid user, EntityUid deviceEnt, NewsWriteComponent? component)
if (!_accessReader.FindAccessItemsInventory(author, out var items))
return;
- if (!_accessReader.FindStationRecordKeys(author, out var stationRecordKeys, items))
+ if (!_accessReader.FindStationRecordKeys(author, out _, items))
return;
string? authorName = null;
+
+ // TODO: There is a dedicated helper for this.
foreach (var item in items)
{
// ID Card
}
}
- NewsArticle article = new NewsArticle
+ var trimmedName = msg.Name.Trim();
+ var trimmedContent = msg.Content.Trim();
+
+ var article = new NewsArticle
{
Author = authorName,
- Name = (msg.Name.Length <= 25 ? msg.Name.Trim() : $"{msg.Name.Trim().Substring(0, 25)}..."),
- Content = msg.Content,
+ Name = trimmedName.Length <= MaxNameLength ? trimmedName : $"{trimmedName[..MaxNameLength]}...",
+ Content = trimmedContent.Length <= MaxArticleLength ? trimmedContent : $"{trimmedContent[..MaxArticleLength]}...",
ShareTime = _ticker.RoundDuration()
-
};
_audio.PlayPvs(component.ConfirmSound, uid);
namespace Content.Shared.MassMedia.Systems;
+public abstract class SharedNewsSystem : EntitySystem
+{
+ public const int MaxNameLength = 25;
+ public const int MaxArticleLength = 2048;
+}
+
[Serializable, NetSerializable]
public struct NewsArticle
{