singulo distortion auto gen comp state (#15306)

Co-authored-by: deltanedas <@deltanedas:kde.org>
This commit is contained in:
deltanedas
2023-04-14 19:47:32 +00:00
committed by GitHub
parent 84ab1e8f26
commit d6273edaed

View File

@@ -1,60 +1,31 @@
using Robust.Shared.GameStates;
using Robust.Shared.Serialization;
namespace Content.Shared.Singularity.Components
{
[RegisterComponent]
[NetworkedComponent]
public sealed class SingularityDistortionComponent : Component
[RegisterComponent, NetworkedComponent]
[AutoGenerateComponentState]
public sealed partial class SingularityDistortionComponent : Component
{
// TODO: use access and remove this funny stuff
[DataField("intensity")]
private float _intensity = 31.25f;
[DataField("falloffPower")]
private float _falloffPower = MathF.Sqrt(2f);
[ViewVariables(VVAccess.ReadWrite)]
[ViewVariables(VVAccess.ReadWrite), AutoNetworkedField]
public float Intensity
{
get => _intensity;
set => this.SetAndDirtyIfChanged(ref _intensity, value);
}
[ViewVariables(VVAccess.ReadWrite)]
[ViewVariables(VVAccess.ReadWrite), AutoNetworkedField]
public float FalloffPower
{
get => _falloffPower;
set => this.SetAndDirtyIfChanged(ref _falloffPower, value);
}
public override ComponentState GetComponentState()
{
return new SingularityDistortionComponentState(Intensity, FalloffPower);
}
public override void HandleComponentState(ComponentState? curState, ComponentState? nextState)
{
base.HandleComponentState(curState, nextState);
if (curState is not SingularityDistortionComponentState state)
{
return;
}
Intensity = state.Intensity;
FalloffPower = state.Falloff;
}
}
[Serializable, NetSerializable]
public sealed class SingularityDistortionComponentState : ComponentState
{
public SingularityDistortionComponentState(float intensity, float falloff)
{
Intensity = intensity;
Falloff = falloff;
}
public float Intensity { get; }
public float Falloff { get; }
}
}