Files
tbd-station-14/Content.Client/GameObjects/Components/WindowVisualizer.cs
Peter Wedder bd4f2b41df Prettier window breaking (#2368)
* Put the damage in the windows

* add crack overlays

* Window cracking

* glass related sounds

* let's use a valid state

* run optipng on these for posterity

* Examine damage descriptions

* add "Constructible" to dictionary

* Downmix stereo effects to mono

* breaking and knocking

* Add shard etc. sprites

* shard inhands

* more sprite wrangling

* Expand destructiblecomponent drop system + implement it for windows

* Shard descriptions

* Random sprite component

* no nullbabby

* Random destroysounds

* random offset on destructible drops

* fix fucked yaml

* sound collections

* random pitch for knocking

* Localization

* hascomponent

* better spawnondestroy

* missed one
2020-10-29 20:42:11 +01:00

61 lines
2.3 KiB
C#

using System;
using Content.Shared.GameObjects.Components;
using Content.Shared.Utility;
using JetBrains.Annotations;
using Robust.Client.GameObjects;
using Robust.Client.Interfaces.GameObjects.Components;
using Robust.Shared.GameObjects.Components.Transform;
using Robust.Shared.Interfaces.GameObjects;
namespace Content.Client.GameObjects.Components
{
[UsedImplicitly]
public sealed class WindowVisualizer : AppearanceVisualizer
{
public override void OnChangeData(AppearanceComponent component)
{
base.OnChangeData(component);
var sprite = component.Owner.GetComponent<ISpriteComponent>();
var snapGrid = component.Owner.GetComponent<SnapGridComponent>();
var lowWall = FindLowWall(snapGrid);
if (lowWall == null) return;
if (component.TryGetData(WindowVisuals.Damage, out float fraction))
{
var level = Math.Min(ContentHelpers.RoundToLevels(fraction, 1, 7), 5);
if (level == 0)
{
foreach (WindowDamageLayers val in Enum.GetValues(typeof(WindowDamageLayers)))
{
sprite.LayerSetVisible(val, false);
}
return;
}
foreach (WindowDamageLayers val in Enum.GetValues(typeof(WindowDamageLayers)))
{
sprite.LayerSetVisible(val, true);
}
sprite.LayerSetState(WindowDamageLayers.DamageNE, $"{(int) lowWall.LastCornerNE}_{level}");
sprite.LayerSetState(WindowDamageLayers.DamageSE, $"{(int) lowWall.LastCornerSE}_{level}");
sprite.LayerSetState(WindowDamageLayers.DamageSW, $"{(int) lowWall.LastCornerSW}_{level}");
sprite.LayerSetState(WindowDamageLayers.DamageNW, $"{(int) lowWall.LastCornerNW}_{level}");
}
}
private static LowWallComponent FindLowWall(SnapGridComponent snapGrid)
{
foreach (var entity in snapGrid.GetLocal())
{
if (entity.TryGetComponent(out LowWallComponent lowWall))
{
return lowWall;
}
}
return null;
}
}
}