2020-08-13 14:40:27 +02:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
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;
|
|
|
|
|
|
|
2021-06-09 22:19:39 +02:00
|
|
|
|
namespace Content.Client.Cargo.Components
|
2019-11-21 16:37:15 -08:00
|
|
|
|
{
|
|
|
|
|
|
[RegisterComponent]
|
|
|
|
|
|
public class CargoOrderDatabaseComponent : SharedCargoOrderDatabaseComponent
|
|
|
|
|
|
{
|
2020-11-27 11:00:49 +01:00
|
|
|
|
private readonly List<CargoOrderData> _orders = new();
|
2019-11-21 16:37:15 -08:00
|
|
|
|
|
|
|
|
|
|
public IReadOnlyList<CargoOrderData> Orders => _orders;
|
|
|
|
|
|
/// <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
|
|
|
|
|
|
|
|
|
|
// TODO add account selector menu
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Removes all orders from the database.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public virtual void Clear()
|
|
|
|
|
|
{
|
|
|
|
|
|
_orders.Clear();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Adds an order to the database.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="order">The order to be added.</param>
|
|
|
|
|
|
public virtual void AddOrder(CargoOrderData order)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!_orders.Contains(order))
|
|
|
|
|
|
_orders.Add(order);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
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 CargoOrderDatabaseState state)
|
2019-11-21 16:37:15 -08:00
|
|
|
|
return;
|
|
|
|
|
|
Clear();
|
|
|
|
|
|
if (state.Orders == null)
|
|
|
|
|
|
return;
|
|
|
|
|
|
foreach (var order in state.Orders)
|
|
|
|
|
|
{
|
|
|
|
|
|
AddOrder(order);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
OnDatabaseUpdated?.Invoke();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|