Puddle refactor 2: Spillastic boogaloo (#4784)

* Refactor PuddleComponent

* Move puddle effects into separate RSIs

Basically egg/tomato/powder puddle will be moved into separate
/Textures/Fluids RSIs

* Fix YAML for puddles

* Fix issues sloth pointed out.

* Ensure Puddle Component are properly added when spawned

* Remove unnecessary method init puddle with starting maxVolume

* Addressed ElectroSr comments

* Add Resolves

* Try fix error in ensureSolution

* Puddle unanchoring

* Address some issues with puddles

* Fix continue -> return
This commit is contained in:
Ygg01
2021-10-27 09:24:18 +01:00
committed by GitHub
parent 03b1fed47d
commit 14b401f9b3
30 changed files with 753 additions and 564 deletions

View File

@@ -0,0 +1,73 @@
using System;
using System.Linq;
using Content.Shared.Fluids;
using JetBrains.Annotations;
using Robust.Client.GameObjects;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Log;
using Robust.Shared.Maths;
using Robust.Shared.Random;
using Robust.Shared.Serialization.Manager.Attributes;
namespace Content.Client.Fluids
{
[UsedImplicitly]
public class PuddleVisualizer : AppearanceVisualizer
{
[Dependency] private readonly IRobustRandom _random = default!;
// Whether the underlying solution color should be used
[DataField("recolor")] public bool Recolor;
public override void InitializeEntity(IEntity entity)
{
base.InitializeEntity(entity);
if (!entity.TryGetComponent(out SpriteComponent? spriteComponent))
{
Logger.Warning($"Missing SpriteComponent for PuddleVisualizer on entityUid = {entity.Uid}");
return;
}
IoCManager.InjectDependencies(this);
var maxStates = spriteComponent.BaseRSI?.ToArray();
if (maxStates is not { Length: > 0 }) return;
var variant = _random.Next(0, maxStates.Length - 1);
spriteComponent.LayerSetState(0, maxStates[variant].StateId);
spriteComponent.Rotation = Angle.FromDegrees(_random.Next(0, 359));
}
public override void OnChangeData(AppearanceComponent component)
{
base.OnChangeData(component);
if (component.TryGetData<float>(PuddleVisuals.VolumeScale, out var volumeScale) &&
component.Owner.TryGetComponent<SpriteComponent>(out var spriteComponent))
{
var cappedScale = Math.Min(1.0f, volumeScale * 0.75f +0.25f);
UpdateVisual(component, spriteComponent, cappedScale);
}
}
private void UpdateVisual(AppearanceComponent component, SpriteComponent spriteComponent, float cappedScale)
{
Color newColor;
if (Recolor && component.TryGetData<Color>(PuddleVisuals.SolutionColor, out var solutionColor))
{
newColor = solutionColor.WithAlpha(cappedScale);
}
else
{
newColor = spriteComponent.Color.WithAlpha(cappedScale);
}
spriteComponent.Color = newColor;
}
}
}