2020-08-13 14:40:27 +02:00
|
|
|
|
using System;
|
|
|
|
|
|
using Content.Shared.GameObjects.Components.Cargo;
|
2019-11-21 16:37:15 -08:00
|
|
|
|
using Content.Shared.Prototypes.Cargo;
|
|
|
|
|
|
using Robust.Shared.GameObjects;
|
|
|
|
|
|
using Robust.Shared.IoC;
|
|
|
|
|
|
using Robust.Shared.Prototypes;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Content.Client.GameObjects.Components.Cargo
|
|
|
|
|
|
{
|
|
|
|
|
|
[RegisterComponent]
|
|
|
|
|
|
public class GalacticMarketComponent : SharedGalacticMarketComponent
|
|
|
|
|
|
{
|
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>
|
|
|
|
|
|
public event Action OnDatabaseUpdated;
|
|
|
|
|
|
|
|
|
|
|
|
public override void HandleComponentState(ComponentState curState, ComponentState nextState)
|
|
|
|
|
|
{
|
|
|
|
|
|
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;
|
|
|
|
|
|
_products.Clear();
|
|
|
|
|
|
foreach (var productId in state.Products)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!_prototypeManager.TryIndex(productId, out CargoProductPrototype product))
|
|
|
|
|
|
continue;
|
|
|
|
|
|
_products.Add(product);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
OnDatabaseUpdated?.Invoke();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|