2019-09-03 22:51:19 +02:00
|
|
|
using System;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Content.Shared.Lathe;
|
|
|
|
|
using Content.Shared.Research.Prototypes;
|
2019-09-03 22:51:19 +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-09-03 22:51:19 +02:00
|
|
|
{
|
|
|
|
|
[RegisterComponent]
|
|
|
|
|
[ComponentReference(typeof(SharedLatheDatabaseComponent))]
|
2022-02-16 00:23:23 -07:00
|
|
|
public sealed class ProtolatheDatabaseComponent : SharedProtolatheDatabaseComponent
|
2019-09-03 22:51:19 +02:00
|
|
|
{
|
2020-09-13 14:23:52 +02:00
|
|
|
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
2019-09-03 22:51:19 +02:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Invoked when the database gets updated.
|
|
|
|
|
/// </summary>
|
2021-03-10 14:48:29 +01:00
|
|
|
public event Action? OnDatabaseUpdated;
|
2019-09-03 22:51:19 +02:00
|
|
|
|
2021-03-10 14:48:29 +01:00
|
|
|
public override void HandleComponentState(ComponentState? curState, ComponentState? nextState)
|
2019-09-03 22:51:19 +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 ProtolatheDatabaseState state) return;
|
2021-03-10 14:48:29 +01:00
|
|
|
|
2019-09-03 22:51:19 +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-09-03 22:51:19 +02:00
|
|
|
{
|
2022-01-09 20:10:36 -08:00
|
|
|
if(!_prototypeManager.TryIndex(id, out LatheRecipePrototype? recipe)) continue;
|
2019-09-03 22:51:19 +02:00
|
|
|
AddRecipe(recipe);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
OnDatabaseUpdated?.Invoke();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|