removes beforeserialization hook (#12319)

This commit is contained in:
Paul Ritter
2022-11-03 02:41:12 +01:00
committed by GitHub
parent 6eca66a637
commit c5e5729bd4
14 changed files with 199 additions and 229 deletions

View File

@@ -1,8 +1,8 @@
using Content.Shared.Damage;
using Content.Shared.Tools;
using JetBrains.Annotations;
using Robust.Shared.Audio;
using Robust.Shared.GameStates;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
@@ -146,26 +146,27 @@ public sealed class DoorComponent : Component, ISerializationHooks
/// Time until next state change. Because apparently <see cref="IGameTiming.CurTime"/> might not get saved/restored.
/// </summary>
[DataField("SecondsUntilStateChange")]
private float? _secondsUntilStateChange;
void ISerializationHooks.BeforeSerialization()
private float? SecondsUntilStateChange
{
if (NextStateChange == null)
[UsedImplicitly]
get
{
_secondsUntilStateChange = null;
return;
};
if (NextStateChange == null)
{
return null;
}
var curTime = IoCManager.Resolve<IGameTiming>().CurTime;
_secondsUntilStateChange = (float) (NextStateChange.Value - curTime).TotalSeconds;
}
var curTime = IoCManager.Resolve<IGameTiming>().CurTime;
return (float) (NextStateChange.Value - curTime).TotalSeconds;
}
set
{
if (value == null || value.Value > 0)
return;
void ISerializationHooks.AfterDeserialization()
{
if (_secondsUntilStateChange == null || _secondsUntilStateChange.Value > 0)
return;
NextStateChange = IoCManager.Resolve<IGameTiming>().CurTime + TimeSpan.FromSeconds(value.Value);
NextStateChange = IoCManager.Resolve<IGameTiming>().CurTime + TimeSpan.FromSeconds(_secondsUntilStateChange.Value);
}
}
#endregion