Re-organize all projects (#4166)
This commit is contained in:
29
Content.Shared/Cooldown/Cooldowns.cs
Normal file
29
Content.Shared/Cooldown/Cooldowns.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
#nullable enable
|
||||
using System;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Timing;
|
||||
|
||||
namespace Content.Shared.Cooldown
|
||||
{
|
||||
/// <summary>
|
||||
/// Utilities for working with cooldowns.
|
||||
/// </summary>
|
||||
public static class Cooldowns
|
||||
{
|
||||
/// <param name="gameTiming">game timing to use, otherwise will resolve using IoCManager.</param>
|
||||
/// <returns>a cooldown interval starting at GameTiming.Curtime and ending at (offset) from CurTime.
|
||||
/// For example, passing TimeSpan.FromSeconds(5) will create an interval
|
||||
/// from now to 5 seconds from now.</returns>
|
||||
public static (TimeSpan start, TimeSpan end) FromNow(TimeSpan offset, IGameTiming? gameTiming = null)
|
||||
{
|
||||
var now = (gameTiming ?? IoCManager.Resolve<IGameTiming>()).CurTime;
|
||||
return (now, now + offset);
|
||||
}
|
||||
|
||||
/// <see cref="FromNow"/>
|
||||
public static (TimeSpan start, TimeSpan end) SecondsFromNow(double seconds, IGameTiming? gameTiming = null)
|
||||
{
|
||||
return FromNow(TimeSpan.FromSeconds(seconds), gameTiming);
|
||||
}
|
||||
}
|
||||
}
|
||||
88
Content.Shared/Cooldown/ItemCooldownComponent.cs
Normal file
88
Content.Shared/Cooldown/ItemCooldownComponent.cs
Normal file
@@ -0,0 +1,88 @@
|
||||
#nullable enable
|
||||
using System;
|
||||
using Content.Shared.NetIDs;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Players;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
namespace Content.Shared.Cooldown
|
||||
{
|
||||
/// <summary>
|
||||
/// Stores a visual "cooldown" for items, that gets displayed in the hands GUI.
|
||||
/// </summary>
|
||||
[RegisterComponent]
|
||||
public sealed class ItemCooldownComponent : Component
|
||||
{
|
||||
public override string Name => "ItemCooldown";
|
||||
public override uint? NetID => ContentNetIDs.ITEMCOOLDOWN;
|
||||
|
||||
private TimeSpan? _cooldownEnd;
|
||||
private TimeSpan? _cooldownStart;
|
||||
|
||||
/// <summary>
|
||||
/// The time when this cooldown ends.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// If null, no cooldown is displayed.
|
||||
/// </remarks>
|
||||
[ViewVariables]
|
||||
public TimeSpan? CooldownEnd
|
||||
{
|
||||
get => _cooldownEnd;
|
||||
set
|
||||
{
|
||||
_cooldownEnd = value;
|
||||
Dirty();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The time when this cooldown started.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// If null, no cooldown is displayed.
|
||||
/// </remarks>
|
||||
[ViewVariables]
|
||||
public TimeSpan? CooldownStart
|
||||
{
|
||||
get => _cooldownStart;
|
||||
set
|
||||
{
|
||||
_cooldownStart = value;
|
||||
Dirty();
|
||||
}
|
||||
}
|
||||
|
||||
public override ComponentState GetComponentState(ICommonSession player)
|
||||
{
|
||||
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() : base(ContentNetIDs.ITEMCOOLDOWN)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user