Makes PlaceableSurface ECS

This commit is contained in:
Vera Aguilera Puerto
2021-08-20 10:21:39 +02:00
parent 3610abecbd
commit fd8872cc4e
9 changed files with 207 additions and 297 deletions

View File

@@ -1,104 +0,0 @@
using System.Threading.Tasks;
using Content.Server.Hands.Components;
using Content.Shared.Interaction;
using Content.Shared.Placeable;
using Robust.Shared.GameObjects;
using Robust.Shared.Maths;
using Robust.Shared.Players;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.ViewVariables;
namespace Content.Server.Placeable
{
[RegisterComponent]
[ComponentReference(typeof(SharedPlaceableSurfaceComponent))]
public class PlaceableSurfaceComponent : SharedPlaceableSurfaceComponent, IInteractUsing
{
[DataField("placeCentered")]
private bool _placeCentered;
[DataField("positionOffset")]
private Vector2 _positionOffset;
[DataField("IsPlaceable")]
private bool _isPlaceable = true;
[ViewVariables(VVAccess.ReadWrite)]
public override bool IsPlaceable
{
get => _isPlaceable;
set
{
if (_isPlaceable == value)
{
return;
}
_isPlaceable = value;
Dirty();
}
}
[ViewVariables(VVAccess.ReadWrite)]
public override bool PlaceCentered
{
get => _placeCentered;
set
{
if (_placeCentered == value)
{
return;
}
_placeCentered = value;
Dirty();
}
}
[ViewVariables(VVAccess.ReadWrite)]
public override Vector2 PositionOffset
{
get => _positionOffset;
set
{
if (_positionOffset.EqualsApprox(value))
{
return;
}
_positionOffset = value;
Dirty();
}
}
[ViewVariables]
int IInteractUsing.Priority => -10;
public override ComponentState GetComponentState(ICommonSession session)
{
return new PlaceableSurfaceComponentState(_isPlaceable,_placeCentered,_positionOffset);
}
async Task<bool> IInteractUsing.InteractUsing(InteractUsingEventArgs eventArgs)
{
if (!IsPlaceable)
return false;
if(!eventArgs.User.TryGetComponent<HandsComponent>(out var handComponent))
{
return false;
}
handComponent.Drop(eventArgs.Using);
if (_placeCentered)
eventArgs.Using.Transform.LocalPosition = eventArgs.Target.Transform.LocalPosition + _positionOffset;
else
eventArgs.Using.Transform.Coordinates = eventArgs.ClickLocation;
return true;
}
}
}

View File

@@ -3,7 +3,6 @@ using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Content.Server.Hands.Components;
using Content.Server.Placeable;
using Content.Server.Tools.Components;
using Content.Shared.ActionBlocker;
using Content.Shared.Acts;
@@ -13,6 +12,7 @@ using Content.Shared.Item;
using Content.Shared.Movement;
using Content.Shared.Notification.Managers;
using Content.Shared.Physics;
using Content.Shared.Placeable;
using Content.Shared.Sound;
using Content.Shared.Storage;
using Content.Shared.Tool;
@@ -151,9 +151,9 @@ namespace Content.Server.Storage.Components
Contents.ShowContents = _showContents;
Contents.OccludesLight = _occludesLight;
if (Owner.TryGetComponent<PlaceableSurfaceComponent>(out var placeableSurfaceComponent))
if (Owner.TryGetComponent<PlaceableSurfaceComponent>(out var surface))
{
placeableSurfaceComponent.IsPlaceable = Open;
EntitySystem.Get<PlaceableSurfaceSystem>().SetPlaceable(surface, Open);
}
UpdateAppearance();
@@ -267,9 +267,9 @@ namespace Content.Server.Storage.Components
}
}
if (Owner.TryGetComponent<PlaceableSurfaceComponent>(out var placeableSurfaceComponent))
if (Owner.TryGetComponent<PlaceableSurfaceComponent>(out var surface))
{
placeableSurfaceComponent.IsPlaceable = Open;
EntitySystem.Get<PlaceableSurfaceSystem>().SetPlaceable(surface, Open);
}
if (Owner.TryGetComponent(out AppearanceComponent? appearance))

View File

@@ -6,12 +6,12 @@ using System.Threading.Tasks;
using Content.Server.DoAfter;
using Content.Server.Hands.Components;
using Content.Server.Items;
using Content.Server.Placeable;
using Content.Shared.Acts;
using Content.Shared.Interaction;
using Content.Shared.Interaction.Helpers;
using Content.Shared.Item;
using Content.Shared.Notification.Managers;
using Content.Shared.Placeable;
using Content.Shared.Sound;
using Content.Shared.Storage;
using Content.Shared.Whitelist;