* Fix exception in ReagentPrototype Due to client trying to access concrete implementations of IMetabolizable that are in Content.Server. This fix checks to see if the prototype is being loaded by the client through reflection. I don't want to move the prototype completely into Content.Server since it's useful for the client to view descriptions and values of reagents without needing to send that data from the server. * Make fix slightly more explicit Now it will only load the metabolizable when in Robust.Server, instead of it being anything that's not Robust.Client. * Add IModuleManager and ModuleManager Provide simple way to check if shared code is being run by the server or the client * Change ModuleManager implementations to not require assembly name comparison Now just has ClientModuleManager registered to client, and ServerModuleManager registered to server. * Change IModuleManager functions to properties * Fix failing tests. This was failing because the tests weren't initializing IoC. Simply using RobustUnitTest wasn't enough because that doesn't initialize content either. I did some cleaning up so now content IoC is registered via ContentUnitTest.
53 lines
1.8 KiB
C#
53 lines
1.8 KiB
C#
using System.Collections.Generic;
|
|
using Content.Shared.Interfaces;
|
|
using Content.Shared.Interfaces.Chemistry;
|
|
using Robust.Shared.IoC;
|
|
using Robust.Shared.Maths;
|
|
using Robust.Shared.Prototypes;
|
|
using Robust.Shared.Serialization;
|
|
using YamlDotNet.RepresentationModel;
|
|
|
|
namespace Content.Shared.Chemistry
|
|
{
|
|
[Prototype("reagent")]
|
|
public class ReagentPrototype : IPrototype, IIndexedPrototype
|
|
{
|
|
#pragma warning disable 649
|
|
[Dependency] private readonly IModuleManager _moduleManager;
|
|
#pragma warning restore 649
|
|
|
|
private string _id;
|
|
private string _name;
|
|
private string _description;
|
|
private Color _substanceColor;
|
|
private List<IMetabolizable> _metabolism;
|
|
|
|
public string ID => _id;
|
|
public string Name => _name;
|
|
public string Description => _description;
|
|
public Color SubstanceColor => _substanceColor;
|
|
//List of metabolism effects this reagent has, should really only be used server-side.
|
|
public List<IMetabolizable> Metabolism => _metabolism;
|
|
|
|
public ReagentPrototype()
|
|
{
|
|
IoCManager.InjectDependencies(this);
|
|
}
|
|
|
|
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 _description, "desc", string.Empty);
|
|
serializer.DataField(ref _substanceColor, "color", Color.White);
|
|
|
|
if (_moduleManager.IsServerModule)
|
|
serializer.DataField(ref _metabolism, "metabolism", new List<IMetabolizable> {new DefaultMetabolizable()});
|
|
else
|
|
_metabolism = new List<IMetabolizable> { new DefaultMetabolizable() };
|
|
}
|
|
}
|
|
}
|