Partial lathe ECS, fix cursed lathe visualizer, a bit more audiovisual feedback for lathes (#7238)

* Prototype that's mostly borked rather than completely borked

* ECS inserting mats

* Partial ECS mostly done, needs cleanup and visualizer

* Replace timers

* Power visualizes at least

* First ""working"" version

* Clean up all lathes

* Colors

* Fix animation timing

* Fixes greyscale, adds a bunch of colors

* Give every (used) material a color

* Made most lathes take long enough you can at least see there's some sort of animation

* Insertion feedback popup

* Sound for circuit printer and uniform printer

* Fix queueing, optimize update

* Remove mono crash

* cleanup

* Fix test failure

* Techfab inserting sprite

* Cleanup and commenting

* Fix bug in CanProduce check

* Fix UI resolves

* Mirror review stuff
This commit is contained in:
Rane
2022-04-17 03:34:14 -04:00
committed by GitHub
parent 5f9cb8271d
commit 93cdca4f82
70 changed files with 781 additions and 1183 deletions

View File

@@ -0,0 +1,15 @@
namespace Content.Client.Lathe;
/// <summary>
/// Holds the idle and running state for machines to control
/// playing animtions on the client.
/// </summary>
[RegisterComponent]
public sealed class LatheVisualsComponent : Component
{
[DataField("idleState", required: true)]
public string IdleState = default!;
[DataField("runningState", required: true)]
public string RunningState = default!;
}

View File

@@ -0,0 +1,43 @@
using Robust.Client.GameObjects;
using Content.Shared.Lathe;
using Content.Shared.Power;
using Content.Client.Power;
using Content.Client.Wires.Visualizers;
using Content.Shared.Wires;
namespace Content.Client.Lathe
{
public sealed class LatheSystem : VisualizerSystem<LatheVisualsComponent>
{
protected override void OnAppearanceChange(EntityUid uid, LatheVisualsComponent component, ref AppearanceChangeEvent args)
{
if (TryComp(uid, out SpriteComponent? sprite))
{
if (args.Component.TryGetData(PowerDeviceVisuals.Powered, out bool powered))
sprite.LayerSetVisible(PowerDeviceVisualLayers.Powered, powered);
if (args.Component.TryGetData(SharedWiresComponent.WiresVisuals.MaintenancePanelState, out bool panel))
sprite.LayerSetVisible(WiresVisualizer.WiresVisualLayers.MaintenancePanel, panel);
// Lathe specific stuff
if (args.Component.TryGetData(LatheVisuals.IsRunning, out bool isRunning))
{
var state = isRunning ? component.RunningState : component.IdleState;
sprite.LayerSetAnimationTime(LatheVisualLayers.IsRunning, 0f);
sprite.LayerSetState(LatheVisualLayers.IsRunning, state);
}
if (args.Component.TryGetData(LatheVisuals.IsInserting, out bool isInserting))
{
if (args.Component.TryGetData(LatheVisuals.InsertingColor, out Color color))
sprite.LayerSetColor(LatheVisualLayers.IsInserting, color);
sprite.LayerSetAnimationTime(LatheVisualLayers.IsInserting, 0f);
sprite.LayerSetVisible(LatheVisualLayers.IsInserting, isInserting);
}
}
}
}
}
public enum LatheVisualLayers : byte
{
IsRunning,
IsInserting
}

View File

@@ -1,134 +0,0 @@
using System;
using Content.Shared.Lathe;
using Content.Shared.Power;
using JetBrains.Annotations;
using Robust.Client.Animations;
using Robust.Client.GameObjects;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
namespace Content.Client.Lathe.Visualizers
{
[UsedImplicitly]
public sealed class AutolatheVisualizer : AppearanceVisualizer
{
[Dependency] private readonly IEntityManager _entMan = default!;
private const string AnimationKey = "inserting_animation";
private Animation _buildingAnimation;
private Animation _insertingMetalAnimation;
private Animation _insertingGlassAnimation;
private Animation _insertingGoldAnimation;
private Animation _insertingPlasmaAnimation;
private Animation _insertingPlasticAnimation;
public AutolatheVisualizer()
{
_buildingAnimation = PopulateAnimation("building", "building_unlit", 0.5f);
_insertingMetalAnimation = PopulateAnimation("inserting_metal", "inserting_unlit", 0.5f);
_insertingGlassAnimation = PopulateAnimation("inserting_glass", "inserting_unlit", 0.5f);
_insertingGoldAnimation = PopulateAnimation("inserting_gold", "inserting_unlit", 0.5f);
_insertingPlasmaAnimation = PopulateAnimation("inserting_plasma", "inserting_unlit", 0.5f);
_insertingPlasticAnimation = PopulateAnimation("inserting_plastic", "inserting_unlit", 0.5f);
}
private Animation PopulateAnimation(string sprite, string spriteUnlit, float length)
{
var animation = new Animation {Length = TimeSpan.FromSeconds(length)};
var flick = new AnimationTrackSpriteFlick();
animation.AnimationTracks.Add(flick);
flick.LayerKey = AutolatheVisualLayers.Base;
flick.KeyFrames.Add(new AnimationTrackSpriteFlick.KeyFrame(sprite, 0f));
var flickUnlit = new AnimationTrackSpriteFlick();
animation.AnimationTracks.Add(flickUnlit);
flickUnlit.LayerKey = AutolatheVisualLayers.BaseUnlit;
flickUnlit.KeyFrames.Add(new AnimationTrackSpriteFlick.KeyFrame(spriteUnlit, 0f));
return animation;
}
public override void InitializeEntity(EntityUid entity)
{
IoCManager.InjectDependencies(this);
_entMan.EnsureComponent<AnimationPlayerComponent>(entity);
}
public override void OnChangeData(AppearanceComponent component)
{
base.OnChangeData(component);
var sprite = _entMan.GetComponent<ISpriteComponent>(component.Owner);
var animPlayer = _entMan.GetComponent<AnimationPlayerComponent>(component.Owner);
if (!component.TryGetData(PowerDeviceVisuals.VisualState, out LatheVisualState state))
{
state = LatheVisualState.Idle;
}
sprite.LayerSetVisible(AutolatheVisualLayers.AnimationLayer, true);
switch (state)
{
case LatheVisualState.Idle:
if (animPlayer.HasRunningAnimation(AnimationKey))
{
animPlayer.Stop(AnimationKey);
}
sprite.LayerSetState(AutolatheVisualLayers.Base, "icon");
sprite.LayerSetState(AutolatheVisualLayers.BaseUnlit, "unlit");
sprite.LayerSetVisible(AutolatheVisualLayers.AnimationLayer, false);
break;
case LatheVisualState.Producing:
if (!animPlayer.HasRunningAnimation(AnimationKey))
{
animPlayer.Play(_buildingAnimation, AnimationKey);
}
break;
case LatheVisualState.InsertingMetal:
if (!animPlayer.HasRunningAnimation(AnimationKey))
{
animPlayer.Play(_insertingMetalAnimation, AnimationKey);
}
break;
case LatheVisualState.InsertingGlass:
if (!animPlayer.HasRunningAnimation(AnimationKey))
{
animPlayer.Play(_insertingGlassAnimation, AnimationKey);
}
break;
case LatheVisualState.InsertingGold:
if (!animPlayer.HasRunningAnimation(AnimationKey))
{
animPlayer.Play(_insertingGoldAnimation, AnimationKey);
}
break;
case LatheVisualState.InsertingPlasma:
if (!animPlayer.HasRunningAnimation(AnimationKey))
{
animPlayer.Play(_insertingPlasmaAnimation, AnimationKey);
}
break;
case LatheVisualState.InsertingPlastic:
if (!animPlayer.HasRunningAnimation(AnimationKey))
{
animPlayer.Play(_insertingPlasticAnimation, AnimationKey);
}
break;
default:
throw new ArgumentOutOfRangeException();
}
var glowingPartsVisible = !(component.TryGetData(PowerDeviceVisuals.Powered, out bool powered) && !powered);
sprite.LayerSetVisible(AutolatheVisualLayers.BaseUnlit, glowingPartsVisible);
}
public enum AutolatheVisualLayers : byte
{
Base,
BaseUnlit,
AnimationLayer
}
}
}

View File

@@ -1,134 +0,0 @@
using System;
using Content.Shared.Lathe;
using Content.Shared.Power;
using JetBrains.Annotations;
using Robust.Client.Animations;
using Robust.Client.GameObjects;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
namespace Content.Client.Lathe.Visualizers
{
[UsedImplicitly]
public sealed class ProtolatheVisualizer : AppearanceVisualizer
{
[Dependency] private readonly IEntityManager _entMan = default!;
private const string AnimationKey = "inserting_animation";
private Animation _buildingAnimation;
private Animation _insertingMetalAnimation;
private Animation _insertingGlassAnimation;
private Animation _insertingGoldAnimation;
private Animation _insertingPlasmaAnimation;
private Animation _insertingPlasticAnimation;
public ProtolatheVisualizer()
{
_buildingAnimation = PopulateAnimation("building", "building_unlit", 0.8f);
_insertingMetalAnimation = PopulateAnimation("inserting_metal", "inserting_unlit", 0.8f);
_insertingGlassAnimation = PopulateAnimation("inserting_glass", "inserting_unlit", 0.8f);
_insertingGoldAnimation = PopulateAnimation("inserting_gold", "inserting_unlit", 0.8f);
_insertingPlasmaAnimation = PopulateAnimation("inserting_plasma", "inserting_unlit", 0.8f);
_insertingPlasticAnimation = PopulateAnimation("inserting_plastic", "inserting_unlit", 0.8f);
}
private Animation PopulateAnimation(string sprite, string spriteUnlit, float length)
{
var animation = new Animation { Length = TimeSpan.FromSeconds(length) };
var flick = new AnimationTrackSpriteFlick();
animation.AnimationTracks.Add(flick);
flick.LayerKey = ProtolatheVisualLayers.Base;
flick.KeyFrames.Add(new AnimationTrackSpriteFlick.KeyFrame(sprite, 0f));
var flickUnlit = new AnimationTrackSpriteFlick();
animation.AnimationTracks.Add(flickUnlit);
flickUnlit.LayerKey = ProtolatheVisualLayers.BaseUnlit;
flickUnlit.KeyFrames.Add(new AnimationTrackSpriteFlick.KeyFrame(spriteUnlit, 0f));
return animation;
}
public override void InitializeEntity(EntityUid entity)
{
IoCManager.InjectDependencies(this);
_entMan.EnsureComponent<AnimationPlayerComponent>(entity);
}
public override void OnChangeData(AppearanceComponent component)
{
base.OnChangeData(component);
var sprite = _entMan.GetComponent<ISpriteComponent>(component.Owner);
var animPlayer = _entMan.GetComponent<AnimationPlayerComponent>(component.Owner);
if (!component.TryGetData(PowerDeviceVisuals.VisualState, out LatheVisualState state))
{
state = LatheVisualState.Idle;
}
sprite.LayerSetVisible(ProtolatheVisualLayers.AnimationLayer, true);
switch (state)
{
case LatheVisualState.Idle:
if (animPlayer.HasRunningAnimation(AnimationKey))
{
animPlayer.Stop(AnimationKey);
}
sprite.LayerSetState(ProtolatheVisualLayers.Base, "icon");
sprite.LayerSetState(ProtolatheVisualLayers.BaseUnlit, "unlit");
sprite.LayerSetVisible(ProtolatheVisualLayers.AnimationLayer, false);
break;
case LatheVisualState.Producing:
if (!animPlayer.HasRunningAnimation(AnimationKey))
{
animPlayer.Play(_buildingAnimation, AnimationKey);
}
break;
case LatheVisualState.InsertingMetal:
if (!animPlayer.HasRunningAnimation(AnimationKey))
{
animPlayer.Play(_insertingMetalAnimation, AnimationKey);
}
break;
case LatheVisualState.InsertingGlass:
if (!animPlayer.HasRunningAnimation(AnimationKey))
{
animPlayer.Play(_insertingGlassAnimation, AnimationKey);
}
break;
case LatheVisualState.InsertingGold:
if (!animPlayer.HasRunningAnimation(AnimationKey))
{
animPlayer.Play(_insertingGoldAnimation, AnimationKey);
}
break;
case LatheVisualState.InsertingPlasma:
if (!animPlayer.HasRunningAnimation(AnimationKey))
{
animPlayer.Play(_insertingPlasmaAnimation, AnimationKey);
}
break;
case LatheVisualState.InsertingPlastic:
if (!animPlayer.HasRunningAnimation(AnimationKey))
{
animPlayer.Play(_insertingPlasticAnimation, AnimationKey);
}
break;
default:
throw new ArgumentOutOfRangeException();
}
var glowingPartsVisible = !(component.TryGetData(PowerDeviceVisuals.Powered, out bool powered) && !powered);
sprite.LayerSetVisible(ProtolatheVisualLayers.BaseUnlit, glowingPartsVisible);
}
public enum ProtolatheVisualLayers : byte
{
Base,
BaseUnlit,
AnimationLayer
}
}
}