Doors are now automated.

This commit is contained in:
Pieter-Jan Briers
2019-03-17 13:24:26 +01:00
parent 53b59bd6f3
commit f779755c11
2 changed files with 93 additions and 25 deletions

View File

@@ -1,29 +1,48 @@
using System;
using Content.Shared.GameObjects.Components.Doors;
using SS14.Client.Animations;
using SS14.Client.GameObjects;
using SS14.Client.GameObjects.Components.Animations;
using SS14.Client.Interfaces.GameObjects.Components;
using SS14.Shared.Interfaces.GameObjects;
namespace Content.Client.GameObjects.Components.Doors
{
public class AirlockVisualizer2D : AppearanceVisualizer
{
private const string AnimationKey = "airlock_animation";
public override void InitializeEntity(IEntity entity)
{
if (!entity.HasComponent<AnimationPlayerComponent>())
{
entity.AddComponent<AnimationPlayerComponent>();
}
}
public override void OnChangeData(AppearanceComponent component)
{
base.OnChangeData(component);
var sprite = component.Owner.GetComponent<ISpriteComponent>();
var animPlayer = component.Owner.GetComponent<AnimationPlayerComponent>();
if (!component.TryGetData(DoorVisuals.VisualState, out DoorVisualState state))
{
state = DoorVisualState.Closed;
}
// TODO: need some sorta state to prevent resetting the animation if it's already playing.
// Because right now that could happen.
animPlayer.Stop(AnimationKey);
switch (state)
{
case DoorVisualState.Closed:
case DoorVisualState.Closing:
sprite.LayerSetState(DoorVisualLayers.Base, "closed");
break;
case DoorVisualState.Closing:
animPlayer.Play(CloseAnimation, AnimationKey);
break;
case DoorVisualState.Opening:
animPlayer.Play(OpenAnimation, AnimationKey);
break;
case DoorVisualState.Open:
sprite.LayerSetState(DoorVisualLayers.Base, "open");
break;
@@ -31,6 +50,28 @@ namespace Content.Client.GameObjects.Components.Doors
throw new ArgumentOutOfRangeException();
}
}
private static readonly Animation CloseAnimation;
private static readonly Animation OpenAnimation;
static AirlockVisualizer2D()
{
CloseAnimation = new Animation {Length = TimeSpan.FromSeconds(1.2f)};
{
var flick = new AnimationTrackSpriteFlick();
CloseAnimation.AnimationTracks.Add(flick);
flick.LayerKey = DoorVisualLayers.Base;
flick.KeyFrames.Add(new AnimationTrackSpriteFlick.KeyFrame("closing", 0f));
}
OpenAnimation = new Animation {Length = TimeSpan.FromSeconds(1.2f)};
{
var flick = new AnimationTrackSpriteFlick();
OpenAnimation.AnimationTracks.Add(flick);
flick.LayerKey = DoorVisualLayers.Base;
flick.KeyFrames.Add(new AnimationTrackSpriteFlick.KeyFrame("opening", 0f));
}
}
}
public enum DoorVisualLayers