* Add nullable to some Content.Shared files. * Use [NotNullWhen(true)] * Undo adding now redundant !'s * Forgot one * Add a ton more nullable * You can guess * Fix some issues * It actually compiles now * Auto stash before merge of "null2" and "origin/master" * I lied * enable annotations -> enable * Revert ActionBlockerSystem.cs to original * Fix ActionBlockerSystem.cs * More nullable * Undo some added exclamation marks * Fix issues * Update Content.Shared/Maps/ContentTileDefinition.cs Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> * Resolve some issues * Remove unused method * Fix more issues * Fix more issues * Fix more issues * Fix more issues * Fix issue, rollback SharedGhostComponent.cs * Update submodule * Fix issue, invert some if-statements to reduce nesting * Revert RobustToolbox * FIx things broken by merge * Some fixes - Replaced with string.Empty - Remove some exclamation marks - Revert file * Some fixes * Trivial #nullable enable * Fix null ables Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> Co-authored-by: Metal Gear Sloth <metalgearsloth@gmail.com>
101 lines
3.0 KiB
C#
101 lines
3.0 KiB
C#
#nullable enable
|
|
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using Content.Shared.Prototypes.Cargo;
|
|
using Robust.Shared.GameObjects;
|
|
using Robust.Shared.IoC;
|
|
using Robust.Shared.Prototypes;
|
|
using Robust.Shared.Serialization;
|
|
|
|
namespace Content.Shared.GameObjects.Components.Cargo
|
|
{
|
|
public class SharedGalacticMarketComponent : Component, IEnumerable<CargoProductPrototype>
|
|
{
|
|
public sealed override string Name => "GalacticMarket";
|
|
public sealed override uint? NetID => ContentNetIDs.GALACTIC_MARKET;
|
|
|
|
protected List<CargoProductPrototype> _products = new();
|
|
|
|
/// <summary>
|
|
/// A read-only list of products.
|
|
/// </summary>
|
|
public IReadOnlyList<CargoProductPrototype> Products => _products;
|
|
|
|
public IEnumerator<CargoProductPrototype> GetEnumerator()
|
|
{
|
|
return _products.GetEnumerator();
|
|
}
|
|
|
|
IEnumerator IEnumerable.GetEnumerator()
|
|
{
|
|
return GetEnumerator();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Returns a product from the string id;
|
|
/// </summary>
|
|
/// <returns>Product</returns>
|
|
public CargoProductPrototype? GetProduct(string productId)
|
|
{
|
|
var prototypeManager = IoCManager.Resolve<IPrototypeManager>();
|
|
if (!prototypeManager.TryIndex(productId, out CargoProductPrototype? product) || !_products.Contains(product))
|
|
{
|
|
return null;
|
|
}
|
|
return product;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Returns a list with the IDs of all products.
|
|
/// </summary>
|
|
/// <returns>A list of product IDs</returns>
|
|
public List<string> GetProductIdList()
|
|
{
|
|
List<string> productIds = new List<string>();
|
|
|
|
foreach (var product in _products)
|
|
{
|
|
productIds.Add(product.ID);
|
|
}
|
|
|
|
return productIds;
|
|
}
|
|
|
|
public override void ExposeData(ObjectSerializer serializer)
|
|
{
|
|
base.ExposeData(serializer);
|
|
|
|
serializer.DataReadWriteFunction(
|
|
"products",
|
|
new List<string>(),
|
|
products =>
|
|
{
|
|
var prototypeManager = IoCManager.Resolve<IPrototypeManager>();
|
|
|
|
_products.Clear();
|
|
foreach (var id in products)
|
|
{
|
|
if (!prototypeManager.TryIndex(id, out CargoProductPrototype? product))
|
|
{
|
|
continue;
|
|
}
|
|
|
|
_products.Add(product);
|
|
}
|
|
},
|
|
GetProductIdList);
|
|
}
|
|
}
|
|
|
|
[Serializable, NetSerializable]
|
|
public class GalacticMarketState : ComponentState
|
|
{
|
|
public List<string> Products;
|
|
public GalacticMarketState(List<string> technologies) : base(ContentNetIDs.GALACTIC_MARKET)
|
|
{
|
|
Products = technologies;
|
|
}
|
|
}
|
|
}
|