Universal weldable component (#7955)

* Weldable component for door

* Content update

* Examine message

* Universal visualizer

* Small fix

* Entity storage

* Content

* Fixed test

* Update Content.Shared/Storage/SharedStorageComponent.cs

Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>

* Fixed loc string

* Add public API to change welding time

Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
This commit is contained in:
Alex Evgrashin
2022-05-09 08:51:52 +03:00
committed by GitHub
parent 02de328d9c
commit df49c2fd57
29 changed files with 367 additions and 215 deletions

View File

@@ -29,7 +29,7 @@ namespace Content.Server.Storage.Components
[Virtual]
[ComponentReference(typeof(IActivate))]
[ComponentReference(typeof(IStorageComponent))]
public class EntityStorageComponent : Component, IActivate, IStorageComponent, IInteractUsing
public class EntityStorageComponent : Component, IActivate, IStorageComponent
{
[Dependency] private readonly IEntityManager _entMan = default!;
@@ -72,15 +72,6 @@ namespace Content.Server.Storage.Components
[DataField("open")]
public bool Open;
[DataField("weldingQuality", customTypeSerializer:typeof(PrototypeIdSerializer<ToolQualityPrototype>))]
private string _weldingQuality = "Welding";
[DataField("CanWeldShut")]
private bool _canWeldShut = true;
[DataField("IsWeldedShut")]
private bool _isWeldedShut;
[DataField("closeSound")]
private SoundSpecifier _closeSound = new SoundPathSpecifier("/Audio/Effects/closetclose.ogg");
@@ -116,32 +107,7 @@ namespace Content.Server.Storage.Components
}
[ViewVariables(VVAccess.ReadWrite)]
public bool IsWeldedShut
{
get => _isWeldedShut;
set
{
if (_isWeldedShut == value) return;
_isWeldedShut = value;
UpdateAppearance();
}
}
private bool _beingWelded;
[ViewVariables(VVAccess.ReadWrite)]
public bool CanWeldShut
{
get => _canWeldShut;
set
{
if (_canWeldShut == value) return;
_canWeldShut = value;
UpdateAppearance();
}
}
public bool IsWeldedShut;
[ViewVariables(VVAccess.ReadWrite)]
public float EnteringRange
@@ -165,8 +131,6 @@ namespace Content.Server.Storage.Components
{
EntitySystem.Get<PlaceableSurfaceSystem>().SetPlaceable(Owner, Open, surface);
}
UpdateAppearance();
}
public virtual void Activate(ActivateEventArgs eventArgs)
@@ -296,15 +260,6 @@ namespace Content.Server.Storage.Components
SoundSystem.Play(Filter.Pvs(Owner), _openSound.GetSound(), Owner);
}
private void UpdateAppearance()
{
if (_entMan.TryGetComponent(Owner, out AppearanceComponent? appearance))
{
appearance.SetData(StorageVisuals.CanWeld, _canWeldShut);
appearance.SetData(StorageVisuals.Welded, _isWeldedShut);
}
}
private void ModifyComponents()
{
if (!_isCollidableWhenOpen && _entMan.TryGetComponent<FixturesComponent?>(Owner, out var manager)
@@ -409,48 +364,6 @@ namespace Content.Server.Storage.Components
return Contents.CanInsert(entity);
}
async Task<bool> IInteractUsing.InteractUsing(InteractUsingEventArgs eventArgs)
{
if (_beingWelded)
return false;
if (Open)
{
_beingWelded = false;
return false;
}
if (!CanWeldShut)
{
_beingWelded = false;
return false;
}
if (Contents.Contains(eventArgs.User))
{
_beingWelded = false;
Owner.PopupMessage(eventArgs.User, Loc.GetString("entity-storage-component-already-contains-user-message"));
return false;
}
if (_beingWelded)
return false;
_beingWelded = true;
var toolSystem = EntitySystem.Get<ToolSystem>();
if (!await toolSystem.UseTool(eventArgs.Using, eventArgs.User, Owner, 1f, 1f, _weldingQuality))
{
_beingWelded = false;
return false;
}
_beingWelded = false;
IsWeldedShut ^= true;
return true;
}
protected virtual IEnumerable<EntityUid> DetermineCollidingEntities()
{
var entityLookup = EntitySystem.Get<EntityLookupSystem>();