using System.Collections.Generic;
using Content.Server.Interfaces.Chemistry;
using Content.Shared.Interfaces;
using Robust.Shared.Interfaces.Serialization;
using Robust.Shared.IoC;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization;
using YamlDotNet.RepresentationModel;
namespace Content.Shared.Chemistry
{
///
/// Prototype for chemical reaction definitions
///
[Prototype("reaction")]
public class ReactionPrototype : IPrototype, IIndexedPrototype
{
private string _id;
private string _name;
private Dictionary _reactants;
private Dictionary _products;
private List _effects;
public string ID => _id;
public string Name => _name;
///
/// Reactants required for the reaction to occur.
///
public IReadOnlyDictionary Reactants => _reactants;
///
/// Reagents created when the reaction occurs.
///
public IReadOnlyDictionary Products => _products;
///
/// Effects to be triggered when the reaction occurs.
///
public IReadOnlyList Effects => _effects;
[Dependency] private readonly IModuleManager _moduleManager = default!;
public void LoadFrom(YamlMappingNode mapping)
{
var serializer = YamlObjectSerializer.NewReader(mapping);
serializer.DataField(ref _id, "id", string.Empty);
serializer.DataField(ref _name, "name", string.Empty);
serializer.DataField(ref _reactants, "reactants", new Dictionary());
serializer.DataField(ref _products, "products", new Dictionary());
if (_moduleManager.IsServerModule)
{
//TODO: Don't have a check for if this is the server
//Some implementations of IReactionEffect can't currently be moved to shared, so this is here to prevent the client from breaking when reading server-only IReactionEffects.
serializer.DataField(ref _effects, "effects", new List());
}
}
}
///
/// Prototype for chemical reaction reactants.
///
public class ReactantPrototype : IExposeData
{
private ReagentUnit _amount;
private bool _catalyst;
///
/// Minimum amount of the reactant needed for the reaction to occur.
///
public ReagentUnit Amount => _amount;
///
/// Whether or not the reactant is a catalyst. Catalysts aren't removed when a reaction occurs.
///
public bool Catalyst => _catalyst;
public void ExposeData(ObjectSerializer serializer)
{
serializer.DataField(ref _amount, "amount", ReagentUnit.New(1));
serializer.DataField(ref _catalyst, "catalyst", false);
}
}
}