2020-08-13 14:40:27 +02:00
|
|
|
|
using System;
|
2021-06-09 22:19:39 +02:00
|
|
|
|
using Content.Shared.Cargo;
|
|
|
|
|
|
using Content.Shared.Cargo.Components;
|
2019-11-21 16:37:15 -08:00
|
|
|
|
using Robust.Shared.GameObjects;
|
|
|
|
|
|
using Robust.Shared.IoC;
|
|
|
|
|
|
using Robust.Shared.Prototypes;
|
|
|
|
|
|
|
2021-06-09 22:19:39 +02:00
|
|
|
|
namespace Content.Client.Cargo.Components
|
2019-11-21 16:37:15 -08:00
|
|
|
|
{
|
|
|
|
|
|
[RegisterComponent]
|
2022-02-16 00:23:23 -07:00
|
|
|
|
public sealed class GalacticMarketComponent : SharedGalacticMarketComponent
|
2019-11-21 16:37:15 -08:00
|
|
|
|
{
|
2020-08-24 14:10:28 +02:00
|
|
|
|
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
2019-11-21 16:37:15 -08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Event called when the database is updated.
|
|
|
|
|
|
/// </summary>
|
2021-03-10 14:48:29 +01:00
|
|
|
|
public event Action? OnDatabaseUpdated;
|
2019-11-21 16:37:15 -08:00
|
|
|
|
|
2021-03-10 14:48:29 +01:00
|
|
|
|
public override void HandleComponentState(ComponentState? curState, ComponentState? nextState)
|
2019-11-21 16:37:15 -08:00
|
|
|
|
{
|
|
|
|
|
|
base.HandleComponentState(curState, nextState);
|
2020-11-26 14:33:31 +01:00
|
|
|
|
if (curState is not GalacticMarketState state)
|
2019-11-21 16:37:15 -08:00
|
|
|
|
return;
|
2021-03-05 01:08:38 +01:00
|
|
|
|
_productIds.Clear();
|
2019-11-21 16:37:15 -08:00
|
|
|
|
foreach (var productId in state.Products)
|
|
|
|
|
|
{
|
2021-03-10 14:48:29 +01:00
|
|
|
|
if (!_prototypeManager.TryIndex(productId, out CargoProductPrototype? product))
|
2019-11-21 16:37:15 -08:00
|
|
|
|
continue;
|
|
|
|
|
|
_products.Add(product);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
OnDatabaseUpdated?.Invoke();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|