itemcooldown auto gen comp state (#15305)

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

View File

@@ -6,10 +6,11 @@ namespace Content.Shared.Cooldown
/// <summary>
/// Stores a visual "cooldown" for items, that gets displayed in the hands GUI.
/// </summary>
[RegisterComponent]
[NetworkedComponent()]
public sealed class ItemCooldownComponent : Component
[RegisterComponent, NetworkedComponent]
[AutoGenerateComponentState]
public sealed partial class ItemCooldownComponent : Component
{
// TODO: access and system setting and dirtying not this funny stuff
private TimeSpan? _cooldownEnd;
private TimeSpan? _cooldownStart;
@@ -19,7 +20,7 @@ namespace Content.Shared.Cooldown
/// <remarks>
/// If null, no cooldown is displayed.
/// </remarks>
[ViewVariables]
[ViewVariables, AutoNetworkedField]
public TimeSpan? CooldownEnd
{
get => _cooldownEnd;
@@ -36,7 +37,7 @@ namespace Content.Shared.Cooldown
/// <remarks>
/// If null, no cooldown is displayed.
/// </remarks>
[ViewVariables]
[ViewVariables, AutoNetworkedField]
public TimeSpan? CooldownStart
{
get => _cooldownStart;
@@ -46,35 +47,5 @@ namespace Content.Shared.Cooldown
Dirty();
}
}
public override ComponentState GetComponentState()
{
return new ItemCooldownComponentState
{
CooldownEnd = CooldownEnd,
CooldownStart = CooldownStart
};
}
public override void HandleComponentState(ComponentState? curState, ComponentState? nextState)
{
base.HandleComponentState(curState, nextState);
if (curState is not ItemCooldownComponentState cast)
return;
CooldownStart = cast.CooldownStart;
CooldownEnd = cast.CooldownEnd;
}
[Serializable, NetSerializable]
private sealed class ItemCooldownComponentState : ComponentState
{
public TimeSpan? CooldownStart { get; set; }
public TimeSpan? CooldownEnd { get; set; }
public ItemCooldownComponentState() {
}
}
}
}