Vending machine uplift (#1549)
* Let there be (vending machine) light Cut up vending machines to have unshaded layers. I scripted the cutting up so there might need to be minor tweaks to some of them. Added the eris vending machine sound (I liked it more than tg's, fight me). * Tweak sound reduction * Mark vending as abstract Appearance is done on each vending based on what sprite states they have (at the moment) and the vendingmachine shouldn't be spawned on its own anyway. * Add screen layer back in * Unstuff what was stuffed * Removed the Soviet and USA vending machines * Added proper licensing Co-authored-by: Metal Gear Sloth <metalgearsloth@gmail.com> Co-authored-by: Swept <jamesurquhartwebb@gmail.com>
This commit is contained in:
@@ -1,44 +1,109 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
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.Interfaces.GameObjects;
|
||||
using Robust.Shared.Utility;
|
||||
using YamlDotNet.RepresentationModel;
|
||||
using static Content.Shared.GameObjects.Components.VendingMachines.SharedVendingMachineComponent;
|
||||
|
||||
namespace Content.Client.GameObjects.Components.VendingMachines
|
||||
{
|
||||
public class VendingMachineVisualizer : AppearanceVisualizer
|
||||
[UsedImplicitly]
|
||||
public sealed class VendingMachineVisualizer : AppearanceVisualizer
|
||||
{
|
||||
// TODO: Should default to off or broken if damaged
|
||||
//
|
||||
|
||||
// TODO: The length of these animations is supposed to be dictated
|
||||
// by the vending machine's pack prototype's `AnimationDuration`
|
||||
// but we have no good way of passing that data from the server
|
||||
// to the client at the moment. Rework Visualizers?
|
||||
private const string DeniedAnimationKey = "deny";
|
||||
private const string EjectAnimationKey = "eject";
|
||||
|
||||
private Animation _deniedAnimation;
|
||||
private Animation _ejectAnimation;
|
||||
private Dictionary<string, bool> _baseStates;
|
||||
|
||||
private static readonly Dictionary<string, VendingMachineVisualLayers> LayerMap =
|
||||
new Dictionary<string, VendingMachineVisualLayers>
|
||||
{
|
||||
{"off", VendingMachineVisualLayers.Unlit},
|
||||
{"screen", VendingMachineVisualLayers.Screen},
|
||||
{"normal", VendingMachineVisualLayers.Base},
|
||||
{"normal-unshaded", VendingMachineVisualLayers.BaseUnshaded},
|
||||
{"eject", VendingMachineVisualLayers.Base},
|
||||
{"eject-unshaded", VendingMachineVisualLayers.BaseUnshaded},
|
||||
{"deny", VendingMachineVisualLayers.Base},
|
||||
{"deny-unshaded", VendingMachineVisualLayers.BaseUnshaded},
|
||||
{"broken", VendingMachineVisualLayers.Unlit},
|
||||
};
|
||||
|
||||
private Dictionary<string, Animation> _animations = new Dictionary<string, Animation>();
|
||||
|
||||
public override void LoadData(YamlMappingNode node)
|
||||
{
|
||||
base.LoadData(node);
|
||||
_deniedAnimation = new Animation {Length = TimeSpan.FromSeconds(1.2f)};
|
||||
|
||||
_baseStates = new Dictionary<string, bool>
|
||||
{
|
||||
var flick = new AnimationTrackSpriteFlick();
|
||||
_deniedAnimation.AnimationTracks.Add(flick);
|
||||
flick.LayerKey = VendingMachineVisualLayers.Base;
|
||||
flick.KeyFrames.Add(new AnimationTrackSpriteFlick.KeyFrame("deny", 0f));
|
||||
{"off", true},
|
||||
};
|
||||
|
||||
// Used a dictionary so the yaml can adhere to the style-guide and the texture states can be clear
|
||||
var states = new Dictionary<string, string>
|
||||
{
|
||||
{"screen", "screen"},
|
||||
{"normal", "normal"},
|
||||
{"normalUnshaded", "normal-unshaded"},
|
||||
{"eject", "eject"},
|
||||
{"ejectUnshaded", "eject-unshaded"},
|
||||
{"deny", "deny"},
|
||||
{"denyUnshaded", "deny-unshaded"},
|
||||
{"broken", "broken"},
|
||||
{"brokenUnshaded", "broken-unshaded"},
|
||||
};
|
||||
|
||||
foreach (var (state, textureState) in states)
|
||||
{
|
||||
if (!node.TryGetNode(state, out var yamlNode))
|
||||
{
|
||||
_baseStates[textureState] = false;
|
||||
continue;
|
||||
}
|
||||
|
||||
_baseStates.Add(textureState, yamlNode.AsBool());
|
||||
}
|
||||
|
||||
_ejectAnimation = new Animation {Length = TimeSpan.FromSeconds(1.2f)};
|
||||
if (_baseStates["deny"])
|
||||
{
|
||||
var flick = new AnimationTrackSpriteFlick();
|
||||
_ejectAnimation.AnimationTracks.Add(flick);
|
||||
flick.LayerKey = VendingMachineVisualLayers.Base;
|
||||
flick.KeyFrames.Add(new AnimationTrackSpriteFlick.KeyFrame("eject", 0f));
|
||||
InitializeAnimation("deny");
|
||||
}
|
||||
|
||||
if (_baseStates["deny-unshaded"])
|
||||
{
|
||||
InitializeAnimation("deny-unshaded", true);
|
||||
}
|
||||
|
||||
if (_baseStates["eject"])
|
||||
{
|
||||
InitializeAnimation("eject");
|
||||
}
|
||||
|
||||
if (_baseStates["eject-unshaded"])
|
||||
{
|
||||
InitializeAnimation("eject-unshaded", true);
|
||||
}
|
||||
}
|
||||
|
||||
private void InitializeAnimation(string key, bool unshaded = false)
|
||||
{
|
||||
_animations.Add(key, new Animation {Length = TimeSpan.FromSeconds(1.2f)});
|
||||
|
||||
var flick = new AnimationTrackSpriteFlick();
|
||||
_animations[key].AnimationTracks.Add(flick);
|
||||
flick.LayerKey = unshaded ? VendingMachineVisualLayers.BaseUnshaded : VendingMachineVisualLayers.Base;
|
||||
flick.KeyFrames.Add(new AnimationTrackSpriteFlick.KeyFrame(key, 0f));
|
||||
}
|
||||
|
||||
public override void InitializeEntity(IEntity entity)
|
||||
@@ -51,6 +116,16 @@ namespace Content.Client.GameObjects.Components.VendingMachines
|
||||
}
|
||||
}
|
||||
|
||||
private void HideLayers(ISpriteComponent spriteComponent)
|
||||
{
|
||||
foreach (var layer in spriteComponent.AllLayers)
|
||||
{
|
||||
layer.Visible = false;
|
||||
}
|
||||
|
||||
spriteComponent.LayerSetVisible(VendingMachineVisualLayers.Unlit, true);
|
||||
}
|
||||
|
||||
public override void OnChangeData(AppearanceComponent component)
|
||||
{
|
||||
var sprite = component.Owner.GetComponent<ISpriteComponent>();
|
||||
@@ -59,40 +134,81 @@ namespace Content.Client.GameObjects.Components.VendingMachines
|
||||
{
|
||||
state = VendingMachineVisualState.Normal;
|
||||
}
|
||||
|
||||
// Hide last state
|
||||
HideLayers(sprite);
|
||||
ActivateState(sprite, "off");
|
||||
|
||||
switch (state)
|
||||
{
|
||||
case VendingMachineVisualState.Normal:
|
||||
sprite.LayerSetState(VendingMachineVisualLayers.Base, "normal");
|
||||
ActivateState(sprite, "screen");
|
||||
ActivateState(sprite, "normal-unshaded");
|
||||
ActivateState(sprite, "normal");
|
||||
break;
|
||||
|
||||
case VendingMachineVisualState.Off:
|
||||
sprite.LayerSetState(VendingMachineVisualLayers.Base, "off");
|
||||
break;
|
||||
|
||||
case VendingMachineVisualState.Broken:
|
||||
sprite.LayerSetState(VendingMachineVisualLayers.Base, "broken");
|
||||
ActivateState(sprite, "broken-unshaded");
|
||||
ActivateState(sprite, "broken");
|
||||
|
||||
break;
|
||||
case VendingMachineVisualState.Deny:
|
||||
if (!animPlayer.HasRunningAnimation(DeniedAnimationKey))
|
||||
{
|
||||
animPlayer.Play(_deniedAnimation, DeniedAnimationKey);
|
||||
}
|
||||
ActivateState(sprite, "screen");
|
||||
ActivateAnimation(sprite, animPlayer, "deny-unshaded");
|
||||
ActivateAnimation(sprite, animPlayer, "deny");
|
||||
|
||||
break;
|
||||
case VendingMachineVisualState.Eject:
|
||||
if (!animPlayer.HasRunningAnimation(EjectAnimationKey))
|
||||
{
|
||||
animPlayer.Play(_ejectAnimation, EjectAnimationKey);
|
||||
}
|
||||
ActivateState(sprite, "screen");
|
||||
ActivateAnimation(sprite, animPlayer, "eject-unshaded");
|
||||
ActivateAnimation(sprite, animPlayer, "eject");
|
||||
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
}
|
||||
|
||||
// Helper methods just to avoid all of that hard-to-read-indented code
|
||||
private void ActivateState(ISpriteComponent spriteComponent, string stateId)
|
||||
{
|
||||
// No state for it on the rsi :(
|
||||
if (!_baseStates[stateId])
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var stateLayer = LayerMap[stateId];
|
||||
spriteComponent.LayerSetVisible(stateLayer, true);
|
||||
spriteComponent.LayerSetState(stateLayer, stateId);
|
||||
}
|
||||
|
||||
private void ActivateAnimation(ISpriteComponent spriteComponent, AnimationPlayerComponent animationPlayer, string key)
|
||||
{
|
||||
if (!_animations.TryGetValue(key, out var animation))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!animationPlayer.HasRunningAnimation(key))
|
||||
{
|
||||
spriteComponent.LayerSetVisible(LayerMap[key], true);
|
||||
animationPlayer.Play(animation, key);
|
||||
}
|
||||
}
|
||||
|
||||
public enum VendingMachineVisualLayers
|
||||
{
|
||||
// Off / Broken. The other layers will overlay this if the machine is on.
|
||||
Unlit,
|
||||
// Normal / Deny / Eject
|
||||
Base,
|
||||
BaseUnshaded,
|
||||
// Screens that are persistent (where the machine is not off or broken)
|
||||
Screen,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user