Add Smoke and Foam chemical reaction effects. (#2913)
* Adds smoke reaction effect * smoke tweaks * address reviews * Smoke fix * Refactor smoke and add foam * Fix stuff * Remove thing * Little things * Address some comments * Address more things * More addressing * License stuff * Address refactor request * Small things * Add nullability * Update Content.Server/GameObjects/EntitySystems/SolutionAreaEffectSystem.cs Co-authored-by: Paul Ritter <ritter.paul1@googlemail.com>
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
#nullable enable
|
||||
using System;
|
||||
using Content.Shared.GameObjects.Components.Chemistry;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Client.Animations;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Client.GameObjects.Components.Animations;
|
||||
using Robust.Client.Interfaces.GameObjects.Components;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Utility;
|
||||
using YamlDotNet.RepresentationModel;
|
||||
|
||||
namespace Content.Client.GameObjects.Components.Chemistry
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public class FoamVisualizer : AppearanceVisualizer
|
||||
{
|
||||
private const string AnimationKey = "foamdissolve_animation";
|
||||
private Animation _foamDissolve = new();
|
||||
public override void LoadData(YamlMappingNode node)
|
||||
{
|
||||
base.LoadData(node);
|
||||
|
||||
var delay = 0.6f;
|
||||
var state = "foam-dissolve";
|
||||
|
||||
if (node.TryGetNode("animationTime", out var delayNode))
|
||||
{
|
||||
delay = delayNode.AsFloat();
|
||||
}
|
||||
|
||||
if (node.TryGetNode("animationState", out var stateNode))
|
||||
{
|
||||
state = stateNode.AsString();
|
||||
}
|
||||
|
||||
_foamDissolve = new Animation {Length = TimeSpan.FromSeconds(delay)};
|
||||
var flick = new AnimationTrackSpriteFlick();
|
||||
_foamDissolve.AnimationTracks.Add(flick);
|
||||
flick.LayerKey = FoamVisualLayers.Base;
|
||||
flick.KeyFrames.Add(new AnimationTrackSpriteFlick.KeyFrame(state, 0f));
|
||||
}
|
||||
|
||||
public override void OnChangeData(AppearanceComponent component)
|
||||
{
|
||||
base.OnChangeData(component);
|
||||
|
||||
if (component.TryGetData<bool>(FoamVisuals.State, out var state))
|
||||
{
|
||||
if (state)
|
||||
{
|
||||
if (component.Owner.TryGetComponent(out AnimationPlayerComponent? animPlayer))
|
||||
{
|
||||
if (!animPlayer.HasRunningAnimation(AnimationKey))
|
||||
animPlayer.Play(_foamDissolve, AnimationKey);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (component.TryGetData<Color>(FoamVisuals.Color, out var color))
|
||||
{
|
||||
if (component.Owner.TryGetComponent(out ISpriteComponent? sprite))
|
||||
{
|
||||
sprite.Color = color;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public enum FoamVisualLayers : byte
|
||||
{
|
||||
Base
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
#nullable enable
|
||||
using Content.Shared.GameObjects.Components.Chemistry;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Client.Interfaces.GameObjects.Components;
|
||||
using Robust.Shared.Maths;
|
||||
|
||||
namespace Content.Client.GameObjects.Components.Chemistry
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public class SmokeVisualizer : AppearanceVisualizer
|
||||
{
|
||||
public override void OnChangeData(AppearanceComponent component)
|
||||
{
|
||||
base.OnChangeData(component);
|
||||
|
||||
if (component.TryGetData<Color>(SmokeVisuals.Color, out var color))
|
||||
{
|
||||
if (component.Owner.TryGetComponent(out ISpriteComponent? sprite))
|
||||
{
|
||||
sprite.Color = color;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -236,6 +236,8 @@ namespace Content.Client
|
||||
"SliceableFood",
|
||||
"DamageOtherOnHit",
|
||||
"DamageOnLand",
|
||||
"SmokeSolutionAreaEffect",
|
||||
"FoamSolutionAreaEffect",
|
||||
"GasFilter",
|
||||
"Recyclable",
|
||||
"SecretStash",
|
||||
|
||||
Reference in New Issue
Block a user