decouple material insertion visualization from lathes (#13242)
This commit is contained in:
@@ -8,6 +8,8 @@ namespace Content.Client.Lathe;
|
||||
|
||||
public sealed class LatheSystem : SharedLatheSystem
|
||||
{
|
||||
[Dependency] private readonly AppearanceSystem _appearance = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
@@ -20,32 +22,19 @@ public sealed class LatheSystem : SharedLatheSystem
|
||||
if (args.Sprite == null)
|
||||
return;
|
||||
|
||||
if (args.Component.TryGetData(PowerDeviceVisuals.Powered, out bool powered) &&
|
||||
if (_appearance.TryGetData(uid, PowerDeviceVisuals.Powered, out bool powered, args.Component) &&
|
||||
args.Sprite.LayerMapTryGet(PowerDeviceVisualLayers.Powered, out _))
|
||||
{
|
||||
args.Sprite.LayerSetVisible(PowerDeviceVisualLayers.Powered, powered);
|
||||
}
|
||||
|
||||
// Lathe specific stuff
|
||||
if (args.Component.TryGetData(LatheVisuals.IsRunning, out bool isRunning))
|
||||
if (_appearance.TryGetData(uid, LatheVisuals.IsRunning, out bool isRunning, args.Component))
|
||||
{
|
||||
var state = isRunning ? component.RunningState : component.IdleState;
|
||||
args.Sprite.LayerSetAnimationTime(LatheVisualLayers.IsRunning, 0f);
|
||||
args.Sprite.LayerSetState(LatheVisualLayers.IsRunning, state);
|
||||
}
|
||||
|
||||
if (args.Component.TryGetData(LatheVisuals.IsInserting, out bool isInserting)
|
||||
&& args.Sprite.LayerMapTryGet(LatheVisualLayers.IsInserting, out var isInsertingLayer))
|
||||
{
|
||||
if (args.Component.TryGetData(LatheVisuals.InsertingColor, out Color color)
|
||||
&& !component.IgnoreColor)
|
||||
{
|
||||
args.Sprite.LayerSetColor(isInsertingLayer, color);
|
||||
}
|
||||
|
||||
args.Sprite.LayerSetAnimationTime(isInsertingLayer, 0f);
|
||||
args.Sprite.LayerSetVisible(isInsertingLayer, isInserting);
|
||||
}
|
||||
}
|
||||
|
||||
///<remarks>
|
||||
@@ -60,6 +49,5 @@ public sealed class LatheSystem : SharedLatheSystem
|
||||
|
||||
public enum LatheVisualLayers : byte
|
||||
{
|
||||
IsRunning,
|
||||
IsInserting
|
||||
IsRunning
|
||||
}
|
||||
|
||||
@@ -3,13 +3,43 @@ using Robust.Client.GameObjects;
|
||||
|
||||
namespace Content.Client.Materials;
|
||||
|
||||
/// <summary>
|
||||
/// This handles...
|
||||
/// </summary>
|
||||
public sealed class MaterialStorageSystem : SharedMaterialStorageSystem
|
||||
{
|
||||
[Dependency] private readonly AppearanceSystem _appearance = default!;
|
||||
[Dependency] private readonly TransformSystem _transform = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<MaterialStorageComponent, AppearanceChangeEvent>(OnAppearanceChange);
|
||||
}
|
||||
|
||||
private void OnAppearanceChange(EntityUid uid, MaterialStorageComponent component, ref AppearanceChangeEvent args)
|
||||
{
|
||||
if (args.Sprite == null)
|
||||
return;
|
||||
|
||||
if (!args.Sprite.LayerMapTryGet(MaterialStorageVisualLayers.Inserting, out var layer))
|
||||
return;
|
||||
|
||||
if (!_appearance.TryGetData(uid, MaterialStorageVisuals.Inserting, out bool inserting, args.Component))
|
||||
return;
|
||||
|
||||
if (inserting && TryComp<InsertingMaterialStorageComponent>(uid, out var insertingComp))
|
||||
{
|
||||
args.Sprite.LayerSetAnimationTime(layer, 0f);
|
||||
|
||||
args.Sprite.LayerSetVisible(layer, true);
|
||||
if (insertingComp.MaterialColor != null)
|
||||
args.Sprite.LayerSetColor(layer, insertingComp.MaterialColor.Value);
|
||||
}
|
||||
else
|
||||
{
|
||||
args.Sprite.LayerSetVisible(layer, false);
|
||||
}
|
||||
}
|
||||
|
||||
public override bool TryInsertMaterialEntity(EntityUid user, EntityUid toInsert, EntityUid receiver, MaterialStorageComponent? component = null)
|
||||
{
|
||||
if (!base.TryInsertMaterialEntity(user, toInsert, receiver, component))
|
||||
@@ -18,3 +48,8 @@ public sealed class MaterialStorageSystem : SharedMaterialStorageSystem
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public enum MaterialStorageVisualLayers : byte
|
||||
{
|
||||
Inserting
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user