Light verb is now predicted (#33622)

Fix
This commit is contained in:
beck-thompson
2024-11-28 05:41:01 -08:00
committed by GitHub
parent f6813e39c7
commit a790955b76
3 changed files with 43 additions and 22 deletions

View File

@@ -3,9 +3,11 @@ using Content.Shared.Clothing.EntitySystems;
using Content.Shared.Item;
using Content.Shared.Light.Components;
using Content.Shared.Toggleable;
using Content.Shared.Verbs;
using Robust.Shared.Audio;
using Robust.Shared.Audio.Systems;
using Robust.Shared.GameStates;
using Robust.Shared.Utility;
namespace Content.Shared.Light;
@@ -22,6 +24,8 @@ public abstract class SharedHandheldLightSystem : EntitySystem
base.Initialize();
SubscribeLocalEvent<HandheldLightComponent, ComponentInit>(OnInit);
SubscribeLocalEvent<HandheldLightComponent, ComponentHandleState>(OnHandleState);
SubscribeLocalEvent<HandheldLightComponent, GetVerbsEvent<ActivationVerb>>(AddToggleLightVerb);
}
private void OnInit(EntityUid uid, HandheldLightComponent component, ComponentInit args)
@@ -78,4 +82,25 @@ public abstract class SharedHandheldLightSystem : EntitySystem
_appearance.SetData(uid, ToggleableLightVisuals.Enabled, component.Activated, appearance);
}
private void AddToggleLightVerb(Entity<HandheldLightComponent> ent, ref GetVerbsEvent<ActivationVerb> args)
{
if (!args.CanAccess || !args.CanInteract || !ent.Comp.ToggleOnInteract)
return;
var @event = args;
ActivationVerb verb = new()
{
Text = Loc.GetString("verb-common-toggle-light"),
Icon = new SpriteSpecifier.Texture(new ("/Textures/Interface/VerbIcons/light.svg.192dpi.png")),
Act = ent.Comp.Activated
? () => TurnOff(ent)
: () => TurnOn(@event.User, ent)
};
args.Verbs.Add(verb);
}
public abstract bool TurnOff(Entity<HandheldLightComponent> ent, bool makeNoise = true);
public abstract bool TurnOn(EntityUid user, Entity<HandheldLightComponent> uid);
}