#3898 open sprite field for drink comp (#4235)

* temp

* #3898 some progress on DrinkCanVisualizer

* Fixed implementation

* Moved drink can sprite layer definition to abstract parent

* Added open drink can sprites

* #3898 - fixes for drink cans' sprite field after merge + moved UpdateAppeareance from DrinkComponent to DrinkSystem

* Update Content.Server/Nutrition/EntitySystems/DrinkSystem.cs

* #3898 removed obsolete comment

Co-authored-by: Javier Guardia Fernández <DrSmugleaf@users.noreply.github.com>
This commit is contained in:
Galactic Chimp
2021-10-03 06:56:29 +02:00
committed by GitHub
parent 539045dcce
commit 61f1c8a05c
27 changed files with 169 additions and 44 deletions

View File

@@ -1,5 +1,3 @@
using System.Linq;
using System.Threading.Tasks;
using Content.Server.Body.Behavior;
using Content.Server.Fluids.Components;
using Content.Shared.Body.Components;
@@ -21,6 +19,8 @@ using Robust.Shared.Player;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.Utility;
using Robust.Shared.ViewVariables;
using System.Linq;
using System.Threading.Tasks;
namespace Content.Server.Nutrition.Components
{
@@ -61,7 +61,7 @@ namespace Content.Server.Nutrition.Components
}
_opened = value;
OpenedChanged();
OnOpenedChanged();
}
}
@@ -81,7 +81,7 @@ namespace Content.Server.Nutrition.Components
[DataField("burstSound")] public SoundSpecifier BurstSound = new SoundPathSpecifier("/Audio/Effects/flash_bang.ogg");
private void OpenedChanged()
private void OnOpenedChanged()
{
var solutionSys = EntitySystem.Get<SolutionContainerSystem>();
if (!solutionSys.TryGetSolution(Owner, SolutionName, out _))
@@ -89,6 +89,11 @@ namespace Content.Server.Nutrition.Components
return;
}
if (Owner.TryGetComponent(out AppearanceComponent? appearance))
{
appearance.SetData(DrinkCanStateVisual.Opened, Opened);
}
if (Opened)
{
var refillable = Owner.EnsureComponent<RefillableSolutionComponent>();
@@ -103,19 +108,6 @@ namespace Content.Server.Nutrition.Components
}
}
// TODO move to DrinkSystem
public void UpdateAppearance()
{
if (!Owner.TryGetComponent(out AppearanceComponent? appearance) ||
!Owner.HasComponent<SolutionContainerManagerComponent>())
{
return;
}
var drainAvailable = EntitySystem.Get<SolutionContainerSystem>().DrainAvailable(Owner);
appearance.SetData(SharedFoodComponent.FoodVisuals.Visual, drainAvailable.Float());
}
bool IUse.UseEntity(UseEntityEventArgs args)
{
if (!Opened)
@@ -218,7 +210,6 @@ namespace Content.Server.Nutrition.Components
SoundSystem.Play(Filter.Pvs(target), _useSound.GetSound(), target, AudioParams.Default.WithVolume(-2f));
target.PopupMessage(Loc.GetString("drink-component-try-use-drink-success-slurp"));
UpdateAppearance();
// TODO: Account for partial transfer.

View File

@@ -1,9 +1,11 @@
using Content.Server.Fluids.Components;
using Content.Server.Fluids.Components;
using Content.Server.Nutrition.Components;
using Content.Shared.Chemistry.Components.SolutionManager;
using Content.Shared.Chemistry.EntitySystems;
using Content.Shared.Nutrition.Components;
using Content.Shared.Throwing;
using JetBrains.Annotations;
using Robust.Server.GameObjects;
using Robust.Shared.Audio;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
@@ -35,6 +37,7 @@ namespace Content.Server.Nutrition.EntitySystems
_solutionContainerSystem.TryGetDrainableSolution(uid, out var interactions))
{
component.Opened = true;
UpdateAppearance(component);
var entity = EntityManager.GetEntity(uid);
@@ -60,13 +63,25 @@ namespace Content.Server.Nutrition.EntitySystems
_solutionContainerSystem.EnsureSolution(owner, component.SolutionName);
}
component.UpdateAppearance();
UpdateAppearance(component);
}
private void OnSolutionChange(EntityUid uid, DrinkComponent component, SolutionChangedEvent args)
{
component.UpdateAppearance();
UpdateAppearance(component);
}
public void UpdateAppearance(DrinkComponent component)
{
if (!component.Owner.TryGetComponent(out AppearanceComponent? appearance) ||
!component.Owner.HasComponent<SolutionContainerManagerComponent>())
{
return;
}
var drainAvailable = Get<SolutionContainerSystem>().DrainAvailable(component.Owner);
appearance.SetData(FoodVisuals.Visual, drainAvailable.Float());
appearance.SetData(DrinkCanStateVisual.Opened, component.Opened);
}
}
}