Implement Cargo Console (#413)

* Implement Cargo Console

Add to CargoConsoleComponent GalacticBank information for syncing Bank Account Balance.

Implement CargoOrderDatabase on the server side and a list of orders in the CargoOrderDatabaseComponent on the client side. This makes it easier to change data on the server side but also utilize the state syncing between components.

Implement GalacticMarketComponent.
Only productIds get sent. Both client and server create their lists from YAML.

Implement basic spawning of items from approved orders in CargoOrderDatabase.

* Finish Cargo Console

Add validation to make sure Order Amount is one or more.

Implement approve and cancel buttons to CargoConsoleMenu orders list row.

Add price to CargoConsoleMenu product list row.

Implement CargoOrderDataManager to consolidate CargoOrder lists.

Refactor CargoOrderDatabaseComponent to use CargoOrderDataManager instead of storing duplicate lists.

Implement canceling orders.
Implement approving orders.

Fix sprite links.

Implement Cargo Request Console.
This commit is contained in:
ShadowCommander
2019-11-21 16:37:15 -08:00
committed by Pieter-Jan Briers
parent 58709d2d26
commit 1580750606
29 changed files with 1867 additions and 12 deletions

View File

@@ -0,0 +1,104 @@
using Content.Shared.Prototypes.Cargo;
using System.Collections.Generic;
using System.Linq;
namespace Content.Server.Cargo
{
public class CargoOrderDatabase
{
private Dictionary<int, CargoOrderData> _orders = new Dictionary<int, CargoOrderData>();
private int _orderNumber = 0;
public CargoOrderDatabase(int id)
{
Id = id;
}
public int Id { get; private set; }
/// <summary>
/// Removes all orders from the database.
/// </summary>
public void Clear()
{
_orders.Clear();
}
/// <summary>
/// Returns a list of all orders.
/// </summary>
/// <returns>A list of orders</returns>
public List<CargoOrderData> GetOrders()
{
return _orders.Values.ToList();
}
public bool TryGetOrder(int id, out CargoOrderData order)
{
if (_orders.TryGetValue(id, out var _order))
{
order = _order;
return true;
}
order = null;
return false;
}
public List<CargoOrderData> SpliceApproved()
{
var orders = _orders.Values.Where(order => order.Approved).ToList();
foreach (var order in orders)
_orders.Remove(order.OrderNumber);
return orders;
}
/// <summary>
/// Adds an order to the database.
/// </summary>
/// <param name="requester">The person who requested the item.</param>
/// <param name="reason">The reason the product was requested.</param>
/// <param name="productId">The ID of the product requested.</param>
/// <param name="amount">The amount of the products requested.</param>
/// <param name="payingAccountId">The ID of the bank account paying for the order.</param>
/// <param name="approved">Whether the order will be bought when the orders are processed.</param>
public void AddOrder(string requester, string reason, string productId, int amount, int payingAccountId)
{
var order = new CargoOrderData(_orderNumber, requester, reason, productId, amount, payingAccountId);
if (Contains(order))
return;
_orders.Add(_orderNumber, order);
_orderNumber += 1;
}
/// <summary>
/// Removes an order from the database.
/// </summary>
/// <param name="order">The order to be removed.</param>
/// <returns>Whether it could be removed or not</returns>
public bool RemoveOrder(int orderNumber)
{
return _orders.Remove(orderNumber);
}
/// <summary>
/// Approves an order in the database.
/// </summary>
/// <param name="order">The order to be approved.</param>
public void ApproveOrder(int orderNumber)
{
if (!_orders.TryGetValue(orderNumber, out var order))
return;
order.Approved = true;
}
/// <summary>
/// Returns whether the database contains the order or not.
/// </summary>
/// <param name="order">The order to check</param>
/// <returns>Whether the database contained the order or not.</returns>
public bool Contains(CargoOrderData order)
{
return _orders.ContainsValue(order);
}
}
}