diff --git a/Content.Client/Foldable/FoldableSystem.cs b/Content.Client/Foldable/FoldableSystem.cs deleted file mode 100644 index 4071f7cd3d..0000000000 --- a/Content.Client/Foldable/FoldableSystem.cs +++ /dev/null @@ -1,10 +0,0 @@ -using Content.Shared.Foldable; -using JetBrains.Annotations; - -namespace Content.Client.Foldable; - -[UsedImplicitly] -public sealed class FoldableSystem : SharedFoldableSystem -{ - // classic. -} diff --git a/Content.Server/Foldable/FoldableSystem.cs b/Content.Server/Foldable/FoldableSystem.cs deleted file mode 100644 index 7b5b2577dd..0000000000 --- a/Content.Server/Foldable/FoldableSystem.cs +++ /dev/null @@ -1,89 +0,0 @@ -using System.Linq; -using Content.Server.Storage.Components; -using Content.Shared.Buckle; -using Content.Shared.Buckle.Components; -using Content.Shared.Foldable; -using Content.Shared.Verbs; -using JetBrains.Annotations; -using Robust.Shared.Containers; -using Robust.Shared.Utility; - -namespace Content.Server.Foldable -{ - [UsedImplicitly] - public sealed class FoldableSystem : SharedFoldableSystem - { - [Dependency] private readonly SharedContainerSystem _container = default!; - - public override void Initialize() - { - base.Initialize(); - - SubscribeLocalEvent>(AddFoldVerb); - - } - public bool TryToggleFold(EntityUid uid, FoldableComponent comp) - { - return TrySetFolded(uid, comp, !comp.IsFolded); - } - - public bool CanToggleFold(EntityUid uid, FoldableComponent? fold = null) - { - if (!Resolve(uid, ref fold)) - return false; - - // Can't un-fold in any container (locker, hands, inventory, whatever). - if (_container.IsEntityInContainer(uid)) - return false; - - // If an entity is buckled to the object we can't pick it up or fold it - if (TryComp(uid, out StrapComponent? strap) && strap.BuckledEntities.Any()) - return false; - - if (!TryComp(uid, out EntityStorageComponent? storage)) - return true; - - if (storage.Open) - return false; - - return !storage.Contents.ContainedEntities.Any(); - } - - /// - /// Try to fold/unfold - /// - public bool TrySetFolded(EntityUid uid, FoldableComponent comp, bool state) - { - if (state == comp.IsFolded) - return false; - - if (!CanToggleFold(uid, comp)) - return false; - - SetFolded(uid, comp, state); - return true; - } - - #region Verb - - private void AddFoldVerb(EntityUid uid, FoldableComponent component, GetVerbsEvent args) - { - if (!args.CanAccess || !args.CanInteract || args.Hands == null || !CanToggleFold(uid, component)) - return; - - AlternativeVerb verb = new() - { - Act = () => TryToggleFold(uid, component), - Text = component.IsFolded ? Loc.GetString("unfold-verb") : Loc.GetString("fold-verb"), - Icon = new SpriteSpecifier.Texture(new ("/Textures/Interface/VerbIcons/fold.svg.192dpi.png")), - - // If the object is unfolded and they click it, they want to fold it, if it's folded, they want to pick it up - Priority = component.IsFolded ? 0 : 2, - }; - - args.Verbs.Add(verb); - } - - #endregion - } -} diff --git a/Content.Shared/Foldable/FoldableComponent.cs b/Content.Shared/Foldable/FoldableComponent.cs index eb166f786a..7303f64fdb 100644 --- a/Content.Shared/Foldable/FoldableComponent.cs +++ b/Content.Shared/Foldable/FoldableComponent.cs @@ -11,7 +11,7 @@ namespace Content.Shared.Foldable; /// [RegisterComponent] [NetworkedComponent] -[Access(typeof(SharedFoldableSystem))] +[Access(typeof(FoldableSystem))] public sealed partial class FoldableComponent : Component { [DataField("folded")] diff --git a/Content.Shared/Foldable/FoldableSystem.cs b/Content.Shared/Foldable/FoldableSystem.cs new file mode 100644 index 0000000000..1a0a9bd112 --- /dev/null +++ b/Content.Shared/Foldable/FoldableSystem.cs @@ -0,0 +1,163 @@ +using System.Linq; +using Content.Shared.Buckle; +using Content.Shared.Buckle.Components; +using Content.Shared.Storage.Components; +using Content.Shared.Verbs; +using Robust.Shared.Containers; +using Robust.Shared.GameStates; +using Robust.Shared.Serialization; +using Robust.Shared.Utility; + +namespace Content.Shared.Foldable; + +public sealed class FoldableSystem : EntitySystem +{ + [Dependency] private readonly SharedAppearanceSystem _appearance = default!; + [Dependency] private readonly SharedBuckleSystem _buckle = default!; + [Dependency] private readonly SharedContainerSystem _container = default!; + + public override void Initialize() + { + base.Initialize(); + + SubscribeLocalEvent>(AddFoldVerb); + SubscribeLocalEvent(OnGetState); + SubscribeLocalEvent(OnHandleState); + + SubscribeLocalEvent(OnFoldableInit); + SubscribeLocalEvent(OnInsertEvent); + SubscribeLocalEvent(OnStoreThisAttempt); + SubscribeLocalEvent(OnFoldableOpenAttempt); + } + + private void OnGetState(EntityUid uid, FoldableComponent component, ref ComponentGetState args) + { + args.State = new FoldableComponentState(component.IsFolded); + } + + private void OnHandleState(EntityUid uid, FoldableComponent component, ref ComponentHandleState args) + { + if (args.Current is not FoldableComponentState state) + return; + + if (state.IsFolded != component.IsFolded) + SetFolded(uid, component, state.IsFolded); + } + + private void OnFoldableInit(EntityUid uid, FoldableComponent component, ComponentInit args) + { + SetFolded(uid, component, component.IsFolded); + } + + private void OnFoldableOpenAttempt(EntityUid uid, FoldableComponent component, ref StorageOpenAttemptEvent args) + { + if (component.IsFolded) + args.Cancelled = true; + } + + public void OnStoreThisAttempt(EntityUid uid, FoldableComponent comp, ref StoreMobInItemContainerAttemptEvent args) + { + args.Handled = true; + + if (comp.IsFolded) + args.Cancelled = true; + } + + /// + /// Returns false if the entity isn't foldable. + /// + public bool IsFolded(EntityUid uid, FoldableComponent? component = null) + { + if (!Resolve(uid, ref component)) + return false; + + return component.IsFolded; + } + + /// + /// Set the folded state of the given + /// + public void SetFolded(EntityUid uid, FoldableComponent component, bool folded) + { + component.IsFolded = folded; + Dirty(uid, component); + _appearance.SetData(uid, FoldedVisuals.State, folded); + _buckle.StrapSetEnabled(uid, !component.IsFolded); + } + + private void OnInsertEvent(EntityUid uid, FoldableComponent component, ContainerGettingInsertedAttemptEvent args) + { + if (!component.IsFolded) + args.Cancel(); + } + + public bool TryToggleFold(EntityUid uid, FoldableComponent comp) + { + return TrySetFolded(uid, comp, !comp.IsFolded); + } + + public bool CanToggleFold(EntityUid uid, FoldableComponent? fold = null) + { + if (!Resolve(uid, ref fold)) + return false; + + // Can't un-fold in any container (locker, hands, inventory, whatever). + if (_container.IsEntityInContainer(uid)) + return false; + + // If an entity is buckled to the object we can't pick it up or fold it + if (TryComp(uid, out StrapComponent? strap) && strap.BuckledEntities.Any()) + return false; + + if (TryComp(uid, out SharedEntityStorageComponent? storage)) + { + if (storage.Open || storage.Contents.ContainedEntities.Any()) + return false; + } + + return true; + } + + /// + /// Try to fold/unfold + /// + public bool TrySetFolded(EntityUid uid, FoldableComponent comp, bool state) + { + if (state == comp.IsFolded) + return false; + + if (!CanToggleFold(uid, comp)) + return false; + + SetFolded(uid, comp, state); + return true; + } + + #region Verb + + private void AddFoldVerb(EntityUid uid, FoldableComponent component, GetVerbsEvent args) + { + if (!args.CanAccess || !args.CanInteract || args.Hands == null || !CanToggleFold(uid, component)) + return; + + AlternativeVerb verb = new() + { + Act = () => TryToggleFold(uid, component), + Text = component.IsFolded ? Loc.GetString("unfold-verb") : Loc.GetString("fold-verb"), + Icon = new SpriteSpecifier.Texture(new ("/Textures/Interface/VerbIcons/fold.svg.192dpi.png")), + + // If the object is unfolded and they click it, they want to fold it, if it's folded, they want to pick it up + Priority = component.IsFolded ? 0 : 2, + }; + + args.Verbs.Add(verb); + } + + #endregion + + [Serializable, NetSerializable] + public enum FoldedVisuals : byte + { + State + } +} diff --git a/Content.Shared/Foldable/SharedFoldableSystem.cs b/Content.Shared/Foldable/SharedFoldableSystem.cs deleted file mode 100644 index 78e8d158db..0000000000 --- a/Content.Shared/Foldable/SharedFoldableSystem.cs +++ /dev/null @@ -1,95 +0,0 @@ -using Content.Shared.Buckle; -using Content.Shared.Storage.Components; -using JetBrains.Annotations; -using Robust.Shared.Containers; -using Robust.Shared.GameStates; -using Robust.Shared.Serialization; - -namespace Content.Shared.Foldable; - -[UsedImplicitly] -public abstract class SharedFoldableSystem : EntitySystem -{ - [Dependency] protected readonly SharedAppearanceSystem Appearance = default!; - [Dependency] private readonly SharedBuckleSystem _buckle = default!; - - public override void Initialize() - { - base.Initialize(); - - SubscribeLocalEvent(OnGetState); - SubscribeLocalEvent(OnHandleState); - - SubscribeLocalEvent(OnFoldableInit); - SubscribeLocalEvent(OnInsertEvent); - SubscribeLocalEvent(OnStoreThisAttempt); - SubscribeLocalEvent(OnFoldableOpenAttempt); - } - - private void OnGetState(EntityUid uid, FoldableComponent component, ref ComponentGetState args) - { - args.State = new FoldableComponentState(component.IsFolded); - } - - private void OnHandleState(EntityUid uid, FoldableComponent component, ref ComponentHandleState args) - { - if (args.Current is not FoldableComponentState state) - return; - - if (state.IsFolded != component.IsFolded) - SetFolded(uid, component, state.IsFolded); - } - - private void OnFoldableInit(EntityUid uid, FoldableComponent component, ComponentInit args) - { - SetFolded(uid, component, component.IsFolded); - } - - private void OnFoldableOpenAttempt(EntityUid uid, FoldableComponent component, ref StorageOpenAttemptEvent args) - { - if (component.IsFolded) - args.Cancelled = true; - } - - public void OnStoreThisAttempt(EntityUid uid, FoldableComponent comp, ref StoreMobInItemContainerAttemptEvent args) - { - args.Handled = true; - - if (comp.IsFolded) - args.Cancelled = true; - } - - /// - /// Returns false if the entity isn't foldable. - /// - public bool IsFolded(EntityUid uid, FoldableComponent? component = null) - { - if (!Resolve(uid, ref component)) - return false; - - return component.IsFolded; - } - - /// - /// Set the folded state of the given - /// - public virtual void SetFolded(EntityUid uid, FoldableComponent component, bool folded) - { - component.IsFolded = folded; - Dirty(component); - Appearance.SetData(uid, FoldedVisuals.State, folded); - _buckle.StrapSetEnabled(uid, !component.IsFolded); - } - - private void OnInsertEvent(EntityUid uid, FoldableComponent component, ContainerGettingInsertedAttemptEvent args) - { - if (!component.IsFolded) - args.Cancel(); - } - - [Serializable, NetSerializable] - public enum FoldedVisuals : byte - { - State - } -} diff --git a/Content.Shared/Salvage/Fulton/SharedFultonSystem.cs b/Content.Shared/Salvage/Fulton/SharedFultonSystem.cs index 7efa782c51..2c338a9aa5 100644 --- a/Content.Shared/Salvage/Fulton/SharedFultonSystem.cs +++ b/Content.Shared/Salvage/Fulton/SharedFultonSystem.cs @@ -23,7 +23,7 @@ public abstract partial class SharedFultonSystem : EntitySystem [Dependency] private readonly MetaDataSystem _metadata = default!; [Dependency] protected readonly SharedAudioSystem Audio = default!; [Dependency] private readonly SharedDoAfterSystem _doAfter = default!; - [Dependency] private readonly SharedFoldableSystem _foldable = default!; + [Dependency] private readonly FoldableSystem _foldable = default!; [Dependency] private readonly SharedPopupSystem _popup = default!; [Dependency] private readonly SharedStackSystem _stack = default!; [Dependency] protected readonly SharedTransformSystem TransformSystem = default!;