Move Anchorable to shared. (#7361)

Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
This commit is contained in:
Leon Friedrich
2022-04-02 16:52:44 +13:00
committed by GitHub
parent 2884de06b6
commit 39c4d8be1f
25 changed files with 80 additions and 60 deletions

View File

@@ -1,42 +1,22 @@
using System.Threading.Tasks;
using Content.Server.Administration.Logs;
using Content.Server.Construction.Components;
using Content.Server.Coordinates.Helpers;
using Content.Server.Pulling;
using Content.Server.Tools;
using Content.Server.Tools.Components;
using Content.Shared.Construction.Components;
using Content.Shared.Construction.EntitySystems;
using Content.Shared.Database;
using Content.Shared.Interaction;
using Content.Shared.Pulling.Components;
using Content.Shared.Tools.Components;
namespace Content.Server.Construction
{
public sealed class AnchorableSystem : EntitySystem
public sealed class AnchorableSystem : SharedAnchorableSystem
{
[Dependency] private readonly AdminLogSystem _adminLogs = default!;
[Dependency] private readonly ToolSystem _toolSystem = default!;
[Dependency] private readonly PullingSystem _pullingSystem = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<AnchorableComponent, InteractUsingEvent>(OnInteractUsing, after:new []{typeof(ConstructionSystem)});
}
private async void OnInteractUsing(EntityUid uid, AnchorableComponent anchorable, InteractUsingEvent args)
{
if (args.Handled)
return;
// If the used entity doesn't have a tool, return early.
if (!TryComp(args.Used, out ToolComponent? usedTool) || !usedTool.Qualities.Contains(anchorable.Tool))
return;
args.Handled = true;
await TryToggleAnchor(uid, args.User, args.Used, anchorable, usingTool:usedTool);
}
/// <summary>
/// Checks if a tool can change the anchored status.
/// </summary>
@@ -154,7 +134,7 @@ namespace Content.Server.Construction
/// Tries to toggle the anchored status of this component's owner.
/// </summary>
/// <returns>true if toggled, false otherwise</returns>
public async Task<bool> TryToggleAnchor(EntityUid uid, EntityUid userUid, EntityUid usingUid,
public override async Task<bool> TryToggleAnchor(EntityUid uid, EntityUid userUid, EntityUid usingUid,
AnchorableComponent? anchorable = null,
TransformComponent? transform = null,
SharedPullableComponent? pullable = null,

View File

@@ -1,105 +0,0 @@
using Content.Shared.Tools;
using Robust.Shared.Analyzers;
using Robust.Shared.GameObjects;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
using Robust.Shared.ViewVariables;
namespace Content.Server.Construction.Components
{
[RegisterComponent, Friend(typeof(AnchorableSystem))]
public sealed class AnchorableComponent : Component
{
[DataField("tool", customTypeSerializer:typeof(PrototypeIdSerializer<ToolQualityPrototype>))]
public string Tool { get; private set; } = "Anchoring";
[DataField("snap")]
[ViewVariables(VVAccess.ReadWrite)]
public bool Snap { get; private set; } = true;
/// <summary>
/// Base delay to use for anchoring.
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
[DataField("delay")]
public float Delay = 0.5f;
}
public abstract class BaseAnchoredAttemptEvent : CancellableEntityEventArgs
{
public EntityUid User { get; }
public EntityUid Tool { get; }
/// <summary>
/// Extra delay to add to the do_after.
/// Add to this, don't replace it.
/// Output parameter.
/// </summary>
public float Delay { get; set; } = 0f;
protected BaseAnchoredAttemptEvent(EntityUid user, EntityUid tool)
{
User = user;
Tool = tool;
}
}
public sealed class AnchorAttemptEvent : BaseAnchoredAttemptEvent
{
public AnchorAttemptEvent(EntityUid user, EntityUid tool) : base(user, tool) { }
}
public sealed class UnanchorAttemptEvent : BaseAnchoredAttemptEvent
{
public UnanchorAttemptEvent(EntityUid user, EntityUid tool) : base(user, tool) { }
}
public abstract class BaseAnchoredEvent : EntityEventArgs
{
public EntityUid User { get; }
public EntityUid Tool { get; }
protected BaseAnchoredEvent(EntityUid user, EntityUid tool)
{
User = user;
Tool = tool;
}
}
/// <summary>
/// Raised just before the entity's body type is changed.
/// </summary>
public sealed class BeforeAnchoredEvent : BaseAnchoredEvent
{
public BeforeAnchoredEvent(EntityUid user, EntityUid tool) : base(user, tool) { }
}
/// <summary>
/// Raised when an entity with an anchorable component is anchored. Note that you may instead want the more
/// general <see cref="AnchorStateChangedEvent"/>. This event has the benefit of having user & tool information,
/// as a result of interactions mediated by the <see cref="AnchorableSystem"/>.
/// </summary>
public sealed class UserAnchoredEvent : BaseAnchoredEvent
{
public UserAnchoredEvent(EntityUid user, EntityUid tool) : base(user, tool) { }
}
/// <summary>
/// Raised just before the entity's body type is changed.
/// </summary>
public sealed class BeforeUnanchoredEvent : BaseAnchoredEvent
{
public BeforeUnanchoredEvent(EntityUid user, EntityUid tool) : base(user, tool) { }
}
/// <summary>
/// Raised when an entity with an anchorable component is unanchored. Note that you will probably also need to
/// subscribe to the more general <see cref="AnchorStateChangedEvent"/>, which gets raised BEFORE this one. This
/// event has the benefit of having user & tool information, whereas the more general event may be due to
/// explosions or grid-destruction or other interactions not mediated by the <see cref="AnchorableSystem"/>.
/// </summary>
public sealed class UserUnanchoredEvent : BaseAnchoredEvent
{
public UserUnanchoredEvent(EntityUid user, EntityUid tool) : base(user, tool) { }
}
}

View File

@@ -2,9 +2,9 @@ using System.Collections.Generic;
using System.Threading.Tasks;
using Content.Server.Stack;
using Content.Server.Tools;
using Content.Server.Tools.Components;
using Content.Shared.Interaction;
using Content.Shared.Tools;
using Content.Shared.Tools.Components;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Serialization.Manager.Attributes;