mirror of
https://github.com/space-syndicate/space-station-14.git
synced 2026-10-09 10:21:18 +03:00
Unpredict handheld grinder audio (#44574)
* modern * unpredict audio * prediction't
This commit is contained in:
parent
c3ccd7e42a
commit
0401683a9c
1 changed files with 14 additions and 14 deletions
|
|
@ -9,6 +9,7 @@ using Content.Shared.Popups;
|
|||
using Content.Shared.Stacks;
|
||||
using Robust.Shared.Audio.Systems;
|
||||
using Robust.Shared.Containers;
|
||||
using Robust.Shared.Network;
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
namespace Content.Shared.Kitchen.EntitySystems;
|
||||
|
|
@ -23,18 +24,11 @@ public sealed partial class HandheldGrinderSystem : EntitySystem
|
|||
[Dependency] private SharedAudioSystem _audio = default!;
|
||||
[Dependency] private SharedPuddleSystem _puddle = default!;
|
||||
[Dependency] private SharedPopupSystem _popup = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<HandheldGrinderComponent, EntRemovedFromContainerMessage>(OnGrinderRemoved);
|
||||
SubscribeLocalEvent<HandheldGrinderComponent, InteractUsingEvent>(OnInteractUsing);
|
||||
SubscribeLocalEvent<HandheldGrinderComponent, HandheldGrinderDoAfterEvent>(OnHandheldDoAfter);
|
||||
}
|
||||
[Dependency] private INetManager _net = default!;
|
||||
|
||||
// prevent the infamous UdderSystem debug assert, see https://github.com/space-wizards/space-station-14/pull/35314
|
||||
// TODO: find a better solution than copy pasting this into every shared system that caches solution entities
|
||||
[SubscribeLocalEvent]
|
||||
private void OnGrinderRemoved(Entity<HandheldGrinderComponent> entity, ref EntRemovedFromContainerMessage args)
|
||||
{
|
||||
// Make sure the removed entity was our contained solution and set it to null
|
||||
|
|
@ -44,6 +38,7 @@ public sealed partial class HandheldGrinderSystem : EntitySystem
|
|||
entity.Comp.GrinderSolution = null;
|
||||
}
|
||||
|
||||
[SubscribeLocalEvent]
|
||||
private void OnInteractUsing(Entity<HandheldGrinderComponent> ent, ref InteractUsingEvent args)
|
||||
{
|
||||
if (args.Handled)
|
||||
|
|
@ -55,7 +50,7 @@ public sealed partial class HandheldGrinderSystem : EntitySystem
|
|||
|
||||
if (!CanGrinderBeUsed(ent, item, out var reason))
|
||||
{
|
||||
_popup.PopupClient(reason, ent, args.User);
|
||||
_popup.PopupEntity(reason, ent, args.User);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -65,6 +60,11 @@ public sealed partial class HandheldGrinderSystem : EntitySystem
|
|||
if (!_solution.ResolveSolution(ent.Owner, ent.Comp.SolutionName, ref ent.Comp.GrinderSolution))
|
||||
return;
|
||||
|
||||
ent.Comp.AudioStream = _audio.Stop(ent.Comp.AudioStream);
|
||||
|
||||
if (_net.IsServer) // Cannot correctly cancel predicted audio.
|
||||
ent.Comp.AudioStream = _audio.PlayPvs(ent.Comp.Sound, ent)?.Entity;
|
||||
|
||||
var doAfter = new DoAfterArgs(EntityManager, args.User, ent.Comp.DoAfterDuration, new HandheldGrinderDoAfterEvent(), ent, ent, item)
|
||||
{
|
||||
NeedHand = true,
|
||||
|
|
@ -74,10 +74,10 @@ public sealed partial class HandheldGrinderSystem : EntitySystem
|
|||
BreakOnMove = true
|
||||
};
|
||||
|
||||
if (_doAfter.TryStartDoAfter(doAfter))
|
||||
ent.Comp.AudioStream = _audio.PlayPredicted(ent.Comp.Sound, ent, args.User)?.Entity ?? ent.Comp.AudioStream;
|
||||
_doAfter.TryStartDoAfter(doAfter);
|
||||
}
|
||||
|
||||
[SubscribeLocalEvent]
|
||||
private void OnHandheldDoAfter(Entity<HandheldGrinderComponent> ent, ref HandheldGrinderDoAfterEvent args)
|
||||
{
|
||||
ent.Comp.AudioStream = _audio.Stop(ent.Comp.AudioStream);
|
||||
|
|
@ -90,7 +90,7 @@ public sealed partial class HandheldGrinderSystem : EntitySystem
|
|||
|
||||
if (!CanGrinderBeUsed(ent, item, out var reason))
|
||||
{
|
||||
_popup.PopupClient(reason, ent, args.User);
|
||||
_popup.PopupEntity(reason, ent, args.User);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -110,7 +110,7 @@ public sealed partial class HandheldGrinderSystem : EntitySystem
|
|||
else
|
||||
_destructibleSystem.DestroyEntity(item);
|
||||
|
||||
_popup.PopupClient(Loc.GetString(ent.Comp.FinishedPopup, ("item", item)), ent, args.User);
|
||||
_popup.PopupEntity(Loc.GetString(ent.Comp.FinishedPopup, ("item", item)), ent, args.User);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue