2019-09-03 22:51:19 +02:00
|
|
|
using System;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Content.Shared.Research.Components;
|
|
|
|
|
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.Research
|
2019-09-03 22:51:19 +02:00
|
|
|
{
|
|
|
|
|
[RegisterComponent]
|
|
|
|
|
public class TechnologyDatabaseComponent : SharedTechnologyDatabaseComponent
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Event called when the database is 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 TechnologyDatabaseState state) return;
|
2021-03-10 14:48:29 +01:00
|
|
|
|
2019-09-03 22:51:19 +02:00
|
|
|
_technologies.Clear();
|
2021-03-10 14:48:29 +01:00
|
|
|
|
2019-09-03 22:51:19 +02:00
|
|
|
var protoManager = IoCManager.Resolve<IPrototypeManager>();
|
2021-03-10 14:48:29 +01:00
|
|
|
|
2019-09-03 22:51:19 +02:00
|
|
|
foreach (var techID in state.Technologies)
|
|
|
|
|
{
|
2021-03-10 14:48:29 +01:00
|
|
|
if (!protoManager.TryIndex(techID, out TechnologyPrototype? technology)) continue;
|
2019-09-03 22:51:19 +02:00
|
|
|
_technologies.Add(technology);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
OnDatabaseUpdated?.Invoke();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|