Add text coloring for inspected solution containers, code cleanup (#2010)

* Initial commit

* remove helper

* fixes

* small fix
This commit is contained in:
nuke
2020-09-09 18:32:31 -04:00
committed by GitHub
parent f7a5bad839
commit 753a627c75
56 changed files with 981 additions and 726 deletions

View File

@@ -24,17 +24,17 @@ namespace Content.Server.GameObjects.Components.Fluids
public ReagentUnit MaxVolume
{
get => Owner.TryGetComponent(out SolutionComponent? solution) ? solution.MaxVolume : ReagentUnit.Zero;
get => Owner.TryGetComponent(out SolutionContainerComponent? solution) ? solution.MaxVolume : ReagentUnit.Zero;
set
{
if (Owner.TryGetComponent(out SolutionComponent? solution))
if (Owner.TryGetComponent(out SolutionContainerComponent? solution))
{
solution.MaxVolume = value;
}
}
}
public ReagentUnit CurrentVolume => Owner.TryGetComponent(out SolutionComponent? solution)
public ReagentUnit CurrentVolume => Owner.TryGetComponent(out SolutionContainerComponent? solution)
? solution.CurrentVolume
: ReagentUnit.Zero;
@@ -50,12 +50,12 @@ namespace Content.Server.GameObjects.Components.Fluids
public override void Initialize()
{
base.Initialize();
Owner.EnsureComponent<SolutionComponent>();
Owner.EnsureComponent<SolutionContainerComponent>();
}
private bool TryGiveToMop(MopComponent mopComponent)
{
if (!Owner.TryGetComponent(out SolutionComponent? contents))
if (!Owner.TryGetComponent(out SolutionContainerComponent? contents))
{
return false;
}
@@ -88,7 +88,7 @@ namespace Content.Server.GameObjects.Components.Fluids
public async Task<bool> InteractUsing(InteractUsingEventArgs eventArgs)
{
if (!Owner.TryGetComponent(out SolutionComponent? contents))
if (!Owner.TryGetComponent(out SolutionContainerComponent? contents))
{
return false;
}

View File

@@ -1,48 +0,0 @@
using Content.Server.GameObjects.Components.Chemistry;
using Content.Shared.Chemistry;
using Content.Shared.GameObjects.EntitySystems;
using Content.Shared.GameObjects.Verbs;
using Robust.Shared.GameObjects;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.Localization;
namespace Content.Server.GameObjects.Components.Fluids
{
[RegisterComponent]
public class CanSpillComponent : Component
{
public override string Name => "CanSpill";
// TODO: If the Owner doesn't have a SolutionComponent straight up just have this remove itself?
/// <summary>
/// Transfers solution from the held container to the target container.
/// </summary>
[Verb]
private sealed class FillTargetVerb : Verb<CanSpillComponent>
{
protected override void GetData(IEntity user, CanSpillComponent component, VerbData data)
{
if (!ActionBlockerSystem.CanInteract(user) ||
!component.Owner.TryGetComponent(out SolutionComponent solutionComponent))
{
data.Visibility = VerbVisibility.Invisible;
return;
}
data.Text = Loc.GetString("Spill liquid");
data.Visibility = solutionComponent.CurrentVolume > ReagentUnit.Zero
? VerbVisibility.Visible
: VerbVisibility.Disabled;
}
protected override void Activate(IEntity user, CanSpillComponent component)
{
var solutionComponent = component.Owner.GetComponent<SolutionComponent>();
// Need this as when we split the component's owner may be deleted
var entityLocation = component.Owner.Transform.Coordinates;
var solution = solutionComponent.SplitSolution(solutionComponent.CurrentVolume);
solution.SpillAt(entityLocation, "PuddleSmear");
}
}
}
}

View File

@@ -22,14 +22,14 @@ namespace Content.Server.GameObjects.Components.Fluids
{
public override string Name => "Mop";
public SolutionComponent? Contents => Owner.GetComponentOrNull<SolutionComponent>();
public SolutionContainerComponent? Contents => Owner.GetComponentOrNull<SolutionContainerComponent>();
public ReagentUnit MaxVolume
{
get => Owner.GetComponentOrNull<SolutionComponent>()?.MaxVolume ?? ReagentUnit.Zero;
get => Owner.GetComponentOrNull<SolutionContainerComponent>()?.MaxVolume ?? ReagentUnit.Zero;
set
{
if (Owner.TryGetComponent(out SolutionComponent? solution))
if (Owner.TryGetComponent(out SolutionContainerComponent? solution))
{
solution.MaxVolume = value;
}
@@ -37,7 +37,7 @@ namespace Content.Server.GameObjects.Components.Fluids
}
public ReagentUnit CurrentVolume =>
Owner.GetComponentOrNull<SolutionComponent>()?.CurrentVolume ?? ReagentUnit.Zero;
Owner.GetComponentOrNull<SolutionContainerComponent>()?.CurrentVolume ?? ReagentUnit.Zero;
// Currently there's a separate amount for pickup and dropoff so
// Picking up a puddle requires multiple clicks
@@ -60,15 +60,15 @@ namespace Content.Server.GameObjects.Components.Fluids
{
base.Initialize();
if (!Owner.EnsureComponent(out SolutionComponent _))
if (!Owner.EnsureComponent(out SolutionContainerComponent _))
{
Logger.Warning($"Entity {Owner.Name} at {Owner.Transform.MapPosition} didn't have a {nameof(SolutionComponent)}");
Logger.Warning($"Entity {Owner.Name} at {Owner.Transform.MapPosition} didn't have a {nameof(SolutionContainerComponent)}");
}
}
void IAfterInteract.AfterInteract(AfterInteractEventArgs eventArgs)
{
if (!Owner.TryGetComponent(out SolutionComponent? contents)) return;
if (!Owner.TryGetComponent(out SolutionContainerComponent? contents)) return;
if (!eventArgs.InRangeUnobstructed(ignoreInsideBlocker: true, popup: true)) return;
if (CurrentVolume <= 0)
@@ -76,7 +76,6 @@ namespace Content.Server.GameObjects.Components.Fluids
return;
}
//Solution solution;
if (eventArgs.Target == null)
{
// Drop the liquid on the mop on to the ground
@@ -98,7 +97,7 @@ namespace Content.Server.GameObjects.Components.Fluids
if (transferAmount == 0)
{
if(puddleComponent.EmptyHolder) //The puddle doesn't actually *have* reagents, for example vomit because there's no "vomit" reagent.
if (puddleComponent.EmptyHolder) //The puddle doesn't actually *have* reagents, for example vomit because there's no "vomit" reagent.
{
puddleComponent.Owner.Delete();
transferAmount = ReagentUnit.Min(ReagentUnit.New(5), CurrentVolume);

View File

@@ -94,7 +94,7 @@ namespace Content.Server.GameObjects.Components.Fluids
private ReagentUnit _overflowVolume;
private ReagentUnit OverflowLeft => CurrentVolume - OverflowVolume;
private SolutionComponent _contents;
private SolutionContainerComponent _contents;
public bool EmptyHolder => _contents.ReagentList.Count == 0;
private int _spriteVariants;
// Whether the underlying solution color should be used
@@ -118,13 +118,13 @@ namespace Content.Server.GameObjects.Components.Fluids
{
base.Initialize();
if (Owner.TryGetComponent(out SolutionComponent solutionComponent))
if (Owner.TryGetComponent(out SolutionContainerComponent solutionComponent))
{
_contents = solutionComponent;
}
else
{
_contents = Owner.AddComponent<SolutionComponent>();
_contents = Owner.AddComponent<SolutionContainerComponent>();
}
_snapGrid = Owner.EnsureComponent<SnapGridComponent>();

View File

@@ -0,0 +1,59 @@
using Content.Server.GameObjects.Components.Chemistry;
using Content.Shared.Chemistry;
using Content.Shared.GameObjects.EntitySystems;
using Content.Shared.GameObjects.Verbs;
using Content.Shared.Interfaces;
using Robust.Shared.GameObjects;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.Localization;
namespace Content.Server.GameObjects.Components.Fluids
{
[RegisterComponent]
public class SpillableComponent : Component
{
public override string Name => "Spillable";
/// <summary>
/// Transfers solution from the held container to the floor.
/// </summary>
[Verb]
private sealed class SpillTargetVerb : Verb<SpillableComponent>
{
protected override void GetData(IEntity user, SpillableComponent component, VerbData data)
{
if (!ActionBlockerSystem.CanInteract(user) ||
!component.Owner.TryGetComponent(out SolutionContainerComponent solutionComponent) ||
!solutionComponent.CanRemoveSolutions)
{
data.Visibility = VerbVisibility.Invisible;
return;
}
data.Text = Loc.GetString("Spill liquid");
data.Visibility = solutionComponent.CurrentVolume > ReagentUnit.Zero ? VerbVisibility.Visible : VerbVisibility.Disabled;
}
protected override void Activate(IEntity user, SpillableComponent component)
{
if (component.Owner.TryGetComponent<SolutionContainerComponent>(out var solutionComponent))
{
if (!solutionComponent.CanRemoveSolutions)
{
user.PopupMessage(user, Loc.GetString("You can't pour anything from {0:theName}!", component.Owner));
}
if (solutionComponent.CurrentVolume.Float() <= 0)
{
user.PopupMessage(user, Loc.GetString("{0:theName} is empty!", component.Owner));
}
// Need this as when we split the component's owner may be deleted
var entityLocation = component.Owner.Transform.Coordinates;
var solution = solutionComponent.SplitSolution(solutionComponent.CurrentVolume);
solution.SpillAt(entityLocation, "PuddleSmear");
}
}
}
}
}

View File

@@ -45,16 +45,16 @@ namespace Content.Server.GameObjects.Components.Fluids
set => _sprayVelocity = value;
}
public ReagentUnit CurrentVolume => Owner.GetComponentOrNull<SolutionComponent>()?.CurrentVolume ?? ReagentUnit.Zero;
public ReagentUnit CurrentVolume => Owner.GetComponentOrNull<SolutionContainerComponent>()?.CurrentVolume ?? ReagentUnit.Zero;
public override void Initialize()
{
base.Initialize();
if (!Owner.EnsureComponent(out SolutionComponent _))
if (!Owner.EnsureComponent(out SolutionContainerComponent _))
{
Logger.Warning(
$"Entity {Owner.Name} at {Owner.Transform.MapPosition} didn't have a {nameof(SolutionComponent)}");
$"Entity {Owner.Name} at {Owner.Transform.MapPosition} didn't have a {nameof(SolutionContainerComponent)}");
}
}
@@ -78,7 +78,7 @@ namespace Content.Server.GameObjects.Components.Fluids
if (eventArgs.ClickLocation.GetGridId(_serverEntityManager) != playerPos.GetGridId(_serverEntityManager))
return;
if (!Owner.TryGetComponent(out SolutionComponent contents))
if (!Owner.TryGetComponent(out SolutionContainerComponent contents))
return;
var direction = (eventArgs.ClickLocation.Position - playerPos.Position).Normalized;