Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make UseDelay SetLength do EnsureComp #27601

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Content.Server/Fluids/EntitySystems/SpraySystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ private void OnAfterInteract(Entity<SprayComponent> entity, ref AfterInteractEve

_audio.PlayPvs(entity.Comp.SpraySound, entity, entity.Comp.SpraySound.Params.WithVariation(0.125f));

_useDelay.SetLength((entity, useDelay), TimeSpan.FromSeconds(cooldownTime));
_useDelay.SetLength(entity.Owner, TimeSpan.FromSeconds(cooldownTime));
_useDelay.TryResetDelay((entity, useDelay));
}
}
Expand Down
7 changes: 2 additions & 5 deletions Content.Shared/Storage/EntitySystems/SharedStorageSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,8 @@ public override void Initialize()

private void OnMapInit(Entity<StorageComponent> entity, ref MapInitEvent args)
{
if (TryComp<UseDelayComponent>(entity, out var useDelayComp))
{
UseDelay.SetLength((entity, useDelayComp), entity.Comp.QuickInsertCooldown, QuickInsertUseDelayID);
UseDelay.SetLength((entity, useDelayComp), entity.Comp.OpenUiCooldown, OpenUiUseDelayID);
}
UseDelay.SetLength(entity.Owner, entity.Comp.QuickInsertCooldown, QuickInsertUseDelayID);
UseDelay.SetLength(entity.Owner, entity.Comp.OpenUiCooldown, OpenUiUseDelayID);
}

private void OnStorageGetState(EntityUid uid, StorageComponent component, ref ComponentGetState args)
Expand Down
13 changes: 9 additions & 4 deletions Content.Shared/Timing/UseDelaySystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ private void OnMapInit(Entity<UseDelayComponent> ent, ref MapInitEvent args)
{
// Set default delay length from the prototype
// This makes it easier for simple use cases that only need a single delay
SetLength(ent, ent.Comp.Delay, DefaultId);
SetLength((ent, ent.Comp), ent.Comp.Delay, DefaultId);
}

private void OnUnpaused(Entity<UseDelayComponent> ent, ref EntityUnpausedEvent args)
Expand All @@ -62,9 +62,14 @@ private void OnUnpaused(Entity<UseDelayComponent> ent, ref EntityUnpausedEvent a
/// <summary>
/// Sets the length of the delay with the specified ID.
/// </summary>
public bool SetLength(Entity<UseDelayComponent> ent, TimeSpan length, string id = DefaultId)
/// <remarks>
/// This will add a UseDelay component to the entity if it doesn't have one.
/// </remarks>
public bool SetLength(Entity<UseDelayComponent?> ent, TimeSpan length, string id = DefaultId)
{
if (ent.Comp.Delays.TryGetValue(id, out var entry))
EnsureComp<UseDelayComponent>(ent.Owner, out var comp);

if (comp.Delays.TryGetValue(id, out var entry))
{
if (entry.Length == length)
return true;
Expand All @@ -73,7 +78,7 @@ public bool SetLength(Entity<UseDelayComponent> ent, TimeSpan length, string id
}
else
{
ent.Comp.Delays.Add(id, new UseDelayInfo(length));
comp.Delays.Add(id, new UseDelayInfo(length));
}

Dirty(ent);
Expand Down
Loading