* 1 warning in MechAssemblyVisualizerSystem * 2 warnings in RecyclerVisualizerSystem * 1 warning in ClusterGrenadeVisualizerSystem * 2 warnings in BarSignSystem * 4 warnings in AlertControl * 1 warning in ToolSystem * 2 warnings in PinpointerSystem * 2 warnings in ClientSpriteMovementSystem * 2 warnings in OptionsVisualizerSystem * 1 warning in FlatpackSystem * 1 warning in ZombieSystem * 1 warning in StackSystem * 1 warning in MiningOverlay * 1 warning in FlippableClothingVisualizerSystem * Guard clause for MechAssemblyVisualizerSystem * Get SpriteSystem in AlertControl constructor
50 lines
1.6 KiB
C#
50 lines
1.6 KiB
C#
using Content.Shared.Construction;
|
|
using Content.Shared.Construction.Components;
|
|
using Robust.Client.GameObjects;
|
|
using Robust.Shared.Prototypes;
|
|
|
|
namespace Content.Client.Construction;
|
|
|
|
/// <inheritdoc/>
|
|
public sealed class FlatpackSystem : SharedFlatpackSystem
|
|
{
|
|
[Dependency] private readonly AppearanceSystem _appearance = default!;
|
|
[Dependency] private readonly SpriteSystem _sprite = default!;
|
|
|
|
/// <inheritdoc/>
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
|
|
SubscribeLocalEvent<FlatpackComponent, AppearanceChangeEvent>(OnAppearanceChange);
|
|
}
|
|
|
|
private void OnAppearanceChange(Entity<FlatpackComponent> ent, ref AppearanceChangeEvent args)
|
|
{
|
|
var (_, comp) = ent;
|
|
if (!_appearance.TryGetData<string>(ent, FlatpackVisuals.Machine, out var machineBoardId) || args.Sprite == null)
|
|
return;
|
|
|
|
if (!PrototypeManager.TryIndex<EntityPrototype>(machineBoardId, out var machineBoardPrototype))
|
|
return;
|
|
|
|
if (!machineBoardPrototype.TryGetComponent<SpriteComponent>(out var sprite, EntityManager.ComponentFactory))
|
|
return;
|
|
|
|
Color? color = null;
|
|
foreach (var layer in sprite.AllLayers)
|
|
{
|
|
if (layer.RsiState.Name is not { } spriteState)
|
|
continue;
|
|
|
|
if (!comp.BoardColors.TryGetValue(spriteState, out var c))
|
|
continue;
|
|
color = c;
|
|
break;
|
|
}
|
|
|
|
if (color != null)
|
|
_sprite.LayerSetColor((ent.Owner, args.Sprite), FlatpackVisualLayers.Overlay, color.Value);
|
|
}
|
|
}
|