Magboots ECS and Cleanup (#9245)

Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
This commit is contained in:
Nemanja
2022-07-06 07:46:35 -04:00
committed by GitHub
parent f6da17d7d9
commit 6d9bc04487
8 changed files with 141 additions and 168 deletions

View File

@@ -0,0 +1,26 @@
using Content.Shared.Actions.ActionTypes;
using Robust.Shared.GameStates;
using Robust.Shared.Serialization;
namespace Content.Shared.Clothing;
[RegisterComponent, NetworkedComponent()]
public sealed class MagbootsComponent : Component
{
[DataField("toggleAction", required: true)]
public InstantAction ToggleAction = new();
[ViewVariables]
public bool On;
[Serializable, NetSerializable]
public sealed class MagbootsComponentState : ComponentState
{
public bool On { get; }
public MagbootsComponentState(bool @on)
{
On = on;
}
}
}

View File

@@ -1,33 +0,0 @@
using Content.Shared.Actions;
using Content.Shared.Actions.ActionTypes;
using Robust.Shared.GameStates;
using Robust.Shared.Serialization;
namespace Content.Shared.Clothing
{
[NetworkedComponent()]
public abstract class SharedMagbootsComponent : Component
{
[DataField("toggleAction", required: true)]
public InstantAction ToggleAction = new();
public abstract bool On { get; set; }
protected void OnChanged()
{
EntitySystem.Get<SharedActionsSystem>().SetToggled(ToggleAction, On);
EntitySystem.Get<ClothingSpeedModifierSystem>().SetClothingSpeedModifierEnabled(Owner, On);
}
[Serializable, NetSerializable]
public sealed class MagbootsComponentState : ComponentState
{
public bool On { get; }
public MagbootsComponentState(bool @on)
{
On = on;
}
}
}
}

View File

@@ -7,17 +7,25 @@ namespace Content.Shared.Clothing;
public abstract class SharedMagbootsSystem : EntitySystem
{
[Dependency] private readonly SharedActionsSystem _sharedActions = default!;
[Dependency] private readonly ClothingSpeedModifierSystem _clothingSpeedModifier = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<SharedMagbootsComponent, GetVerbsEvent<ActivationVerb>>(AddToggleVerb);
SubscribeLocalEvent<SharedMagbootsComponent, SlipAttemptEvent>(OnSlipAttempt);
SubscribeLocalEvent<SharedMagbootsComponent, GetItemActionsEvent>(OnGetActions);
SubscribeLocalEvent<SharedMagbootsComponent, ToggleActionEvent>(OnToggleAction);
SubscribeLocalEvent<MagbootsComponent, GetVerbsEvent<ActivationVerb>>(AddToggleVerb);
SubscribeLocalEvent<MagbootsComponent, SlipAttemptEvent>(OnSlipAttempt);
SubscribeLocalEvent<MagbootsComponent, GetItemActionsEvent>(OnGetActions);
}
private void AddToggleVerb(EntityUid uid, SharedMagbootsComponent component, GetVerbsEvent<ActivationVerb> args)
protected void OnChanged(MagbootsComponent component)
{
_sharedActions.SetToggled(component.ToggleAction, component.On);
_clothingSpeedModifier.SetClothingSpeedModifierEnabled(component.Owner, component.On);
}
private void AddToggleVerb(EntityUid uid, MagbootsComponent component, GetVerbsEvent<ActivationVerb> args)
{
if (!args.CanAccess || !args.CanInteract)
return;
@@ -29,24 +37,14 @@ public abstract class SharedMagbootsSystem : EntitySystem
args.Verbs.Add(verb);
}
private void OnSlipAttempt(EntityUid uid, SharedMagbootsComponent component, SlipAttemptEvent args)
private void OnSlipAttempt(EntityUid uid, MagbootsComponent component, SlipAttemptEvent args)
{
if (component.On)
args.Cancel();
}
private void OnGetActions(EntityUid uid, SharedMagbootsComponent component, GetItemActionsEvent args)
private void OnGetActions(EntityUid uid, MagbootsComponent component, GetItemActionsEvent args)
{
args.Actions.Add(component.ToggleAction);
}
private void OnToggleAction(EntityUid uid, SharedMagbootsComponent component, ToggleActionEvent args)
{
if (args.Handled)
return;
component.On = !component.On;
args.Handled = true;
}
}

View File

@@ -60,7 +60,7 @@ namespace Content.Shared.Movement.Components
if (invSys.TryGetSlotEntity(entity, "shoes", out var ent))
{
if (entityManager.TryGetComponent<SharedMagbootsComponent>(ent, out var boots) && boots.On)
if (entityManager.TryGetComponent<MagbootsComponent>(ent, out var boots) && boots.On)
return false;
}