using Content.Shared.Guidebook;
using Robust.Shared.Network;
namespace Content.Client.Guidebook;
///
/// Client system for storing and retrieving values extracted from entity prototypes
/// for display in the guidebook ().
/// Requests data from the server on .
/// Can also be pushed new data when the server reloads prototypes.
///
public sealed class GuidebookDataSystem : EntitySystem
{
[Dependency] private readonly INetManager _netManager = default!;
private GuidebookData? _data;
public override void Initialize()
{
base.Initialize();
SubscribeNetworkEvent(OnServerUpdated);
// Request data from the server
_netManager.Connected += OnConnected;
}
private async void OnConnected(object? sender, NetChannelArgs e)
{
RaiseNetworkEvent(new RequestGuidebookDataEvent());
}
private void OnServerUpdated(UpdateGuidebookDataEvent args)
{
// Got new data from the server, either in response to our request, or because prototypes reloaded on the server
_data = args.Data;
_data.Freeze();
}
///
/// Attempts to retrieve a value using the given identifiers.
/// See for more information.
///
public bool TryGetValue(string prototype, string component, string field, out object? value)
{
if (_data == null)
{
value = null;
return false;
}
return _data.TryGetValue(prototype, component, field, out value);
}
}