2021-06-09 22:19:39 +02:00
|
|
|
using Content.Shared.Lathe;
|
|
|
|
|
using Content.Shared.Research.Prototypes;
|
2019-04-26 15:51:05 +02:00
|
|
|
using Robust.Shared.GameObjects;
|
|
|
|
|
using Robust.Shared.IoC;
|
|
|
|
|
using Robust.Shared.Prototypes;
|
|
|
|
|
|
2021-06-09 22:19:39 +02:00
|
|
|
namespace Content.Client.Lathe.Components
|
2019-04-26 15:51:05 +02:00
|
|
|
{
|
2019-07-31 15:02:36 +02:00
|
|
|
[RegisterComponent]
|
|
|
|
|
[ComponentReference(typeof(SharedLatheDatabaseComponent))]
|
2022-02-16 00:23:23 -07:00
|
|
|
public sealed class LatheDatabaseComponent : SharedLatheDatabaseComponent
|
2019-04-26 15:51:05 +02:00
|
|
|
{
|
2020-08-24 14:10:28 +02:00
|
|
|
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
2019-04-26 15:51:05 +02:00
|
|
|
|
2021-03-10 14:48:29 +01:00
|
|
|
public override void HandleComponentState(ComponentState? curState, ComponentState? nextState)
|
2019-04-26 15:51:05 +02:00
|
|
|
{
|
|
|
|
|
base.HandleComponentState(curState, nextState);
|
2021-03-10 14:48:29 +01:00
|
|
|
|
2020-11-26 14:33:31 +01:00
|
|
|
if (curState is not LatheDatabaseState state) return;
|
2021-03-10 14:48:29 +01:00
|
|
|
|
2019-04-26 15:51:05 +02:00
|
|
|
Clear();
|
2021-03-10 14:48:29 +01:00
|
|
|
|
2022-01-09 20:10:36 -08:00
|
|
|
foreach (var id in state.Recipes)
|
2019-04-26 15:51:05 +02:00
|
|
|
{
|
2022-01-09 20:10:36 -08:00
|
|
|
if (!_prototypeManager.TryIndex(id, out LatheRecipePrototype? recipe)) continue;
|
2019-04-26 15:51:05 +02:00
|
|
|
AddRecipe(recipe);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|