removes beforeserialization hook (#12319)
This commit is contained in:
@@ -1,77 +1,25 @@
|
||||
using System.Collections;
|
||||
using Content.Shared.Research.Prototypes;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.List;
|
||||
|
||||
namespace Content.Shared.Research.Components
|
||||
{
|
||||
[NetworkedComponent()]
|
||||
public abstract class SharedTechnologyDatabaseComponent : Component, IEnumerable<TechnologyPrototype>, ISerializationHooks
|
||||
public abstract class SharedTechnologyDatabaseComponent : Component
|
||||
{
|
||||
[DataField("technologies")] private List<string> _technologyIds = new();
|
||||
|
||||
public List<TechnologyPrototype> Technologies = new();
|
||||
|
||||
void ISerializationHooks.BeforeSerialization()
|
||||
{
|
||||
var techIds = new List<string>();
|
||||
|
||||
foreach (var tech in Technologies)
|
||||
{
|
||||
techIds.Add(tech.ID);
|
||||
}
|
||||
|
||||
_technologyIds = techIds;
|
||||
}
|
||||
|
||||
void ISerializationHooks.AfterDeserialization()
|
||||
{
|
||||
var prototypeManager = IoCManager.Resolve<IPrototypeManager>();
|
||||
|
||||
foreach (var id in _technologyIds)
|
||||
{
|
||||
if (prototypeManager.TryIndex(id, out TechnologyPrototype? tech))
|
||||
{
|
||||
Technologies.Add(tech);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerator<TechnologyPrototype> GetEnumerator()
|
||||
{
|
||||
return Technologies.GetEnumerator();
|
||||
}
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
return GetEnumerator();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a list with the IDs of all unlocked technologies.
|
||||
/// </summary>
|
||||
/// <returns>A list of technology IDs</returns>
|
||||
public List<string> GetTechnologyIdList()
|
||||
{
|
||||
List<string> techIds = new List<string>();
|
||||
|
||||
foreach (var tech in Technologies)
|
||||
{
|
||||
techIds.Add(tech.ID);
|
||||
}
|
||||
|
||||
return techIds;
|
||||
}
|
||||
[DataField("technologies", customTypeSerializer: typeof(PrototypeIdListSerializer<TechnologyPrototype>))]
|
||||
public readonly List<string> TechnologyIds = new();
|
||||
|
||||
/// <summary>
|
||||
/// Returns whether a technology is unlocked on this database or not.
|
||||
/// </summary>
|
||||
/// <param name="technology">The technology to be checked</param>
|
||||
/// <returns>Whether it is unlocked or not</returns>
|
||||
public bool IsTechnologyUnlocked(TechnologyPrototype technology)
|
||||
public bool IsTechnologyUnlocked(string technologyId)
|
||||
{
|
||||
return Technologies.Contains(technology);
|
||||
return TechnologyIds.Contains(technologyId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -82,7 +30,7 @@ namespace Content.Shared.Research.Components
|
||||
/// <returns>Whether it could be unlocked or not</returns>
|
||||
public bool CanUnlockTechnology(TechnologyPrototype technology)
|
||||
{
|
||||
if (technology == null || IsTechnologyUnlocked(technology)) return false;
|
||||
if (IsTechnologyUnlocked(technology.ID)) return false;
|
||||
var protoMan = IoCManager.Resolve<IPrototypeManager>();
|
||||
foreach (var technologyId in technology.RequiredTechnologies)
|
||||
{
|
||||
@@ -90,7 +38,7 @@ namespace Content.Shared.Research.Components
|
||||
if (requiredTechnology == null)
|
||||
return false;
|
||||
|
||||
if (!IsTechnologyUnlocked(requiredTechnology))
|
||||
if (!IsTechnologyUnlocked(requiredTechnology.ID))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user