Airlocks get opening sounds now.

This commit is contained in:
Pieter-Jan Briers
2019-03-20 00:42:52 +01:00
parent f83876e8f8
commit d5559e44bb
7 changed files with 54 additions and 27 deletions

View File

@@ -5,6 +5,8 @@ using SS14.Client.GameObjects;
using SS14.Client.GameObjects.Components.Animations; using SS14.Client.GameObjects.Components.Animations;
using SS14.Client.Interfaces.GameObjects.Components; using SS14.Client.Interfaces.GameObjects.Components;
using SS14.Shared.Interfaces.GameObjects; using SS14.Shared.Interfaces.GameObjects;
using SS14.Shared.Utility;
using YamlDotNet.RepresentationModel;
namespace Content.Client.GameObjects.Components.Doors namespace Content.Client.GameObjects.Components.Doors
{ {
@@ -12,6 +14,41 @@ namespace Content.Client.GameObjects.Components.Doors
{ {
private const string AnimationKey = "airlock_animation"; private const string AnimationKey = "airlock_animation";
private Animation CloseAnimation;
private Animation OpenAnimation;
public override void LoadData(YamlMappingNode node)
{
base.LoadData(node);
var openSound = node.GetNode("open_sound").AsString();
var closeSound = node.GetNode("close_sound").AsString();
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));
var sound = new AnimationTrackPlaySound();
CloseAnimation.AnimationTracks.Add(sound);
sound.KeyFrames.Add(new AnimationTrackPlaySound.KeyFrame(closeSound, 0));
}
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));
var sound = new AnimationTrackPlaySound();
OpenAnimation.AnimationTracks.Add(sound);
sound.KeyFrames.Add(new AnimationTrackPlaySound.KeyFrame(openSound, 0));
}
}
public override void InitializeEntity(IEntity entity) public override void InitializeEntity(IEntity entity)
{ {
if (!entity.HasComponent<AnimationPlayerComponent>()) if (!entity.HasComponent<AnimationPlayerComponent>())
@@ -29,19 +66,23 @@ namespace Content.Client.GameObjects.Components.Doors
state = DoorVisualState.Closed; 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) switch (state)
{ {
case DoorVisualState.Closed: case DoorVisualState.Closed:
sprite.LayerSetState(DoorVisualLayers.Base, "closed"); sprite.LayerSetState(DoorVisualLayers.Base, "closed");
break; break;
case DoorVisualState.Closing: case DoorVisualState.Closing:
animPlayer.Play(CloseAnimation, AnimationKey); if (!animPlayer.HasRunningAnimation(AnimationKey))
{
animPlayer.Play(CloseAnimation, AnimationKey);
}
break; break;
case DoorVisualState.Opening: case DoorVisualState.Opening:
animPlayer.Play(OpenAnimation, AnimationKey); if (!animPlayer.HasRunningAnimation(AnimationKey))
{
animPlayer.Play(OpenAnimation, AnimationKey);
}
break; break;
case DoorVisualState.Open: case DoorVisualState.Open:
sprite.LayerSetState(DoorVisualLayers.Base, "open"); sprite.LayerSetState(DoorVisualLayers.Base, "open");
@@ -50,28 +91,6 @@ namespace Content.Client.GameObjects.Components.Doors
throw new ArgumentOutOfRangeException(); 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 public enum DoorVisualLayers

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -27,6 +27,8 @@
- type: Appearance - type: Appearance
visuals: visuals:
- type: AirlockVisualizer2D - type: AirlockVisualizer2D
open_sound: /Audio/machines/airlock_open.ogg
close_sound: /Audio/machines/airlock_close.ogg
placement: placement:
mode: SnapgridBorder mode: SnapgridBorder
@@ -42,6 +44,12 @@
- type: Icon - type: Icon
sprite: Buildings/airlock_external.rsi sprite: Buildings/airlock_external.rsi
- type: Appearance
visuals:
- type: AirlockVisualizer2D
open_sound: /Audio/machines/airlock_ext_open.ogg
close_sound: /Audio/machines/airlock_ext_close.ogg
- type: entity - type: entity
parent: airlock parent: airlock
id: airlock_engineering id: airlock_engineering