2021-04-28 10:49:37 -07:00
|
|
|
using System;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Content.Shared.Rounding;
|
|
|
|
|
using Content.Shared.Window;
|
2020-10-29 21:42:11 +02:00
|
|
|
using JetBrains.Annotations;
|
|
|
|
|
using Robust.Client.GameObjects;
|
2021-02-11 01:13:03 -08:00
|
|
|
using Robust.Shared.GameObjects;
|
2021-10-15 02:58:40 -07:00
|
|
|
using Robust.Shared.Log;
|
|
|
|
|
using Robust.Shared.Serialization.Manager.Attributes;
|
|
|
|
|
using Robust.Shared.Utility;
|
2020-10-29 21:42:11 +02:00
|
|
|
|
2021-06-09 22:19:39 +02:00
|
|
|
namespace Content.Client.Window
|
2020-10-29 21:42:11 +02:00
|
|
|
{
|
|
|
|
|
[UsedImplicitly]
|
|
|
|
|
public sealed class WindowVisualizer : AppearanceVisualizer
|
|
|
|
|
{
|
2021-10-15 02:58:40 -07:00
|
|
|
[DataField("crackRsi")]
|
|
|
|
|
public ResourcePath CrackRsi { get; } = new ("/Textures/Structures/Windows/cracks.rsi");
|
|
|
|
|
|
|
|
|
|
public override void InitializeEntity(IEntity entity)
|
|
|
|
|
{
|
|
|
|
|
if (!entity.TryGetComponent(out ISpriteComponent? sprite))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
sprite.LayerMapReserveBlank(WindowDamageLayers.Layer);
|
|
|
|
|
sprite.LayerSetVisible(WindowDamageLayers.Layer, false);
|
|
|
|
|
sprite.LayerSetRSI(WindowDamageLayers.Layer, CrackRsi);
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-29 21:42:11 +02:00
|
|
|
public override void OnChangeData(AppearanceComponent component)
|
|
|
|
|
{
|
|
|
|
|
base.OnChangeData(component);
|
|
|
|
|
|
2021-10-15 02:58:40 -07:00
|
|
|
if (!component.Owner.TryGetComponent(out ISpriteComponent? sprite))
|
2020-11-14 00:27:13 +11:00
|
|
|
return;
|
2020-10-29 21:42:11 +02:00
|
|
|
|
|
|
|
|
if (component.TryGetData(WindowVisuals.Damage, out float fraction))
|
|
|
|
|
{
|
2021-10-15 02:58:40 -07:00
|
|
|
var level = Math.Min(ContentHelpers.RoundToLevels(fraction, 1, 5), 3);
|
|
|
|
|
|
2020-10-29 21:42:11 +02:00
|
|
|
if (level == 0)
|
|
|
|
|
{
|
2021-10-15 02:58:40 -07:00
|
|
|
sprite.LayerSetVisible(WindowDamageLayers.Layer, false);
|
2020-10-29 21:42:11 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-15 02:58:40 -07:00
|
|
|
sprite.LayerSetVisible(WindowDamageLayers.Layer, true);
|
|
|
|
|
sprite.LayerSetState(WindowDamageLayers.Layer, $"{level}");
|
2020-10-29 21:42:11 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-15 02:58:40 -07:00
|
|
|
public enum WindowDamageLayers : byte
|
2020-10-29 21:42:11 +02:00
|
|
|
{
|
2021-10-15 02:58:40 -07:00
|
|
|
Layer,
|
2020-10-29 21:42:11 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|