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
|
public sealed class LatheSystem : SharedLatheSystem
|
||||||
{
|
{
|
||||||
|
[Dependency] private readonly AppearanceSystem _appearance = default!;
|
||||||
|
|
||||||
public override void Initialize()
|
public override void Initialize()
|
||||||
{
|
{
|
||||||
base.Initialize();
|
base.Initialize();
|
||||||
@@ -20,32 +22,19 @@ public sealed class LatheSystem : SharedLatheSystem
|
|||||||
if (args.Sprite == null)
|
if (args.Sprite == null)
|
||||||
return;
|
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.LayerMapTryGet(PowerDeviceVisualLayers.Powered, out _))
|
||||||
{
|
{
|
||||||
args.Sprite.LayerSetVisible(PowerDeviceVisualLayers.Powered, powered);
|
args.Sprite.LayerSetVisible(PowerDeviceVisualLayers.Powered, powered);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Lathe specific stuff
|
// 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;
|
var state = isRunning ? component.RunningState : component.IdleState;
|
||||||
args.Sprite.LayerSetAnimationTime(LatheVisualLayers.IsRunning, 0f);
|
args.Sprite.LayerSetAnimationTime(LatheVisualLayers.IsRunning, 0f);
|
||||||
args.Sprite.LayerSetState(LatheVisualLayers.IsRunning, state);
|
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>
|
///<remarks>
|
||||||
@@ -60,6 +49,5 @@ public sealed class LatheSystem : SharedLatheSystem
|
|||||||
|
|
||||||
public enum LatheVisualLayers : byte
|
public enum LatheVisualLayers : byte
|
||||||
{
|
{
|
||||||
IsRunning,
|
IsRunning
|
||||||
IsInserting
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,13 +3,43 @@ using Robust.Client.GameObjects;
|
|||||||
|
|
||||||
namespace Content.Client.Materials;
|
namespace Content.Client.Materials;
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// This handles...
|
|
||||||
/// </summary>
|
|
||||||
public sealed class MaterialStorageSystem : SharedMaterialStorageSystem
|
public sealed class MaterialStorageSystem : SharedMaterialStorageSystem
|
||||||
{
|
{
|
||||||
|
[Dependency] private readonly AppearanceSystem _appearance = default!;
|
||||||
[Dependency] private readonly TransformSystem _transform = 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)
|
public override bool TryInsertMaterialEntity(EntityUid user, EntityUid toInsert, EntityUid receiver, MaterialStorageComponent? component = null)
|
||||||
{
|
{
|
||||||
if (!base.TryInsertMaterialEntity(user, toInsert, receiver, component))
|
if (!base.TryInsertMaterialEntity(user, toInsert, receiver, component))
|
||||||
@@ -18,3 +48,8 @@ public sealed class MaterialStorageSystem : SharedMaterialStorageSystem
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public enum MaterialStorageVisualLayers : byte
|
||||||
|
{
|
||||||
|
Inserting
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,15 +0,0 @@
|
|||||||
namespace Content.Server.Lathe.Components
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// For EntityQuery to keep track of which lathes are inserting
|
|
||||||
/// </summary>
|
|
||||||
[RegisterComponent]
|
|
||||||
public sealed class LatheInsertingComponent : Component
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Remaining insertion time, in seconds.
|
|
||||||
/// </summary>
|
|
||||||
[DataField("timeRemaining", required: true)]
|
|
||||||
public float TimeRemaining;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -33,7 +33,6 @@ namespace Content.Server.Lathe
|
|||||||
public override void Initialize()
|
public override void Initialize()
|
||||||
{
|
{
|
||||||
base.Initialize();
|
base.Initialize();
|
||||||
SubscribeLocalEvent<LatheComponent, MaterialEntityInsertedEvent>(OnMaterialEntityInserted);
|
|
||||||
SubscribeLocalEvent<LatheComponent, GetMaterialWhitelistEvent>(OnGetWhitelist);
|
SubscribeLocalEvent<LatheComponent, GetMaterialWhitelistEvent>(OnGetWhitelist);
|
||||||
SubscribeLocalEvent<LatheComponent, MapInitEvent>(OnMapInit);
|
SubscribeLocalEvent<LatheComponent, MapInitEvent>(OnMapInit);
|
||||||
SubscribeLocalEvent<LatheComponent, PowerChangedEvent>(OnPowerChanged);
|
SubscribeLocalEvent<LatheComponent, PowerChangedEvent>(OnPowerChanged);
|
||||||
@@ -45,24 +44,13 @@ namespace Content.Server.Lathe
|
|||||||
SubscribeLocalEvent<LatheComponent, LatheSyncRequestMessage>(OnLatheSyncRequestMessage);
|
SubscribeLocalEvent<LatheComponent, LatheSyncRequestMessage>(OnLatheSyncRequestMessage);
|
||||||
|
|
||||||
SubscribeLocalEvent<LatheComponent, BeforeActivatableUIOpenEvent>((u,c,_) => UpdateUserInterfaceState(u,c));
|
SubscribeLocalEvent<LatheComponent, BeforeActivatableUIOpenEvent>((u,c,_) => UpdateUserInterfaceState(u,c));
|
||||||
SubscribeLocalEvent<LatheComponent, MaterialAmountChangedEvent>((u,c,_) => UpdateUserInterfaceState(u,c));
|
SubscribeLocalEvent<LatheComponent, MaterialAmountChangedEvent>(OnMaterialAmountChanged);
|
||||||
|
|
||||||
SubscribeLocalEvent<TechnologyDatabaseComponent, LatheGetRecipesEvent>(OnGetRecipes);
|
SubscribeLocalEvent<TechnologyDatabaseComponent, LatheGetRecipesEvent>(OnGetRecipes);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Update(float frameTime)
|
public override void Update(float frameTime)
|
||||||
{
|
{
|
||||||
foreach (var comp in EntityQuery<LatheInsertingComponent>())
|
|
||||||
{
|
|
||||||
comp.TimeRemaining -= frameTime;
|
|
||||||
|
|
||||||
if (comp.TimeRemaining > 0)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
UpdateInsertingAppearance(comp.Owner, false);
|
|
||||||
RemCompDeferred(comp.Owner, comp);
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (var (comp, lathe) in EntityQuery<LatheProducingComponent, LatheComponent>())
|
foreach (var (comp, lathe) in EntityQuery<LatheProducingComponent, LatheComponent>())
|
||||||
{
|
{
|
||||||
if (lathe.CurrentRecipe == null)
|
if (lathe.CurrentRecipe == null)
|
||||||
@@ -73,7 +61,7 @@ namespace Content.Server.Lathe
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnGetWhitelist(EntityUid uid, LatheComponent component, GetMaterialWhitelistEvent args)
|
private void OnGetWhitelist(EntityUid uid, LatheComponent component, ref GetMaterialWhitelistEvent args)
|
||||||
{
|
{
|
||||||
if (args.Storage != uid)
|
if (args.Storage != uid)
|
||||||
return;
|
return;
|
||||||
@@ -203,6 +191,11 @@ namespace Content.Server.Lathe
|
|||||||
args.Recipes = args.Recipes.Union(component.RecipeIds.Where(r => latheComponent.DynamicRecipes.Contains(r))).ToList();
|
args.Recipes = args.Recipes.Union(component.RecipeIds.Where(r => latheComponent.DynamicRecipes.Contains(r))).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void OnMaterialAmountChanged(EntityUid uid, LatheComponent component, ref MaterialAmountChangedEvent args)
|
||||||
|
{
|
||||||
|
UpdateUserInterfaceState(uid, component);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initialize the UI and appearance.
|
/// Initialize the UI and appearance.
|
||||||
/// Appearance requires initialization or the layers break
|
/// Appearance requires initialization or the layers break
|
||||||
@@ -215,15 +208,6 @@ namespace Content.Server.Lathe
|
|||||||
_materialStorage.UpdateMaterialWhitelist(uid);
|
_materialStorage.UpdateMaterialWhitelist(uid);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnMaterialEntityInserted(EntityUid uid, LatheComponent component, MaterialEntityInsertedEvent args)
|
|
||||||
{
|
|
||||||
var lastMat = args.MaterialComp.Materials.Keys.Last();
|
|
||||||
// We need the prototype to get the color
|
|
||||||
_proto.TryIndex(lastMat, out MaterialPrototype? matProto);
|
|
||||||
EnsureComp<LatheInsertingComponent>(uid).TimeRemaining = component.InsertionTime;
|
|
||||||
UpdateInsertingAppearance(uid, true, matProto?.Color);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Sets the machine sprite to either play the running animation
|
/// Sets the machine sprite to either play the running animation
|
||||||
/// or stop.
|
/// or stop.
|
||||||
@@ -233,17 +217,6 @@ namespace Content.Server.Lathe
|
|||||||
_appearance.SetData(uid, LatheVisuals.IsRunning, isRunning);
|
_appearance.SetData(uid, LatheVisuals.IsRunning, isRunning);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Sets the machine sprite to play the inserting animation
|
|
||||||
/// and sets the color of the inserted mat if applicable
|
|
||||||
/// </summary>
|
|
||||||
private void UpdateInsertingAppearance(EntityUid uid, bool isInserting, Color? color = null)
|
|
||||||
{
|
|
||||||
_appearance.SetData(uid, LatheVisuals.IsInserting, isInserting);
|
|
||||||
if (color != null)
|
|
||||||
_appearance.SetData(uid, LatheVisuals.InsertingColor, color);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void OnPowerChanged(EntityUid uid, LatheComponent component, ref PowerChangedEvent args)
|
private void OnPowerChanged(EntityUid uid, LatheComponent component, ref PowerChangedEvent args)
|
||||||
{
|
{
|
||||||
if (!args.Powered)
|
if (!args.Powered)
|
||||||
@@ -297,9 +270,11 @@ namespace Content.Server.Lathe
|
|||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
if (count > 0 && args.Session.AttachedEntity != null)
|
if (count > 0 && args.Session.AttachedEntity != null)
|
||||||
|
{
|
||||||
_adminLogger.Add(LogType.Action, LogImpact.Low,
|
_adminLogger.Add(LogType.Action, LogImpact.Low,
|
||||||
$"{ToPrettyString(args.Session.AttachedEntity.Value):player} queued {count} {recipe.Name} at {ToPrettyString(uid):lathe}");
|
$"{ToPrettyString(args.Session.AttachedEntity.Value):player} queued {count} {recipe.Name} at {ToPrettyString(uid):lathe}");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
TryStartProducing(uid, component);
|
TryStartProducing(uid, component);
|
||||||
UpdateUserInterfaceState(uid, component);
|
UpdateUserInterfaceState(uid, component);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,7 +54,6 @@ public sealed class MaterialStorageSystem : SharedMaterialStorageSystem
|
|||||||
var count = stack?.Count ?? 1;
|
var count = stack?.Count ?? 1;
|
||||||
_adminLogger.Add(LogType.Action, LogImpact.Low,
|
_adminLogger.Add(LogType.Action, LogImpact.Low,
|
||||||
$"{ToPrettyString(user):player} inserted {count} {ToPrettyString(toInsert):inserted} into {ToPrettyString(receiver):receiver}");
|
$"{ToPrettyString(user):player} inserted {count} {ToPrettyString(toInsert):inserted} into {ToPrettyString(receiver):receiver}");
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,12 +28,6 @@ namespace Content.Shared.Lathe
|
|||||||
[DataField("queue")]
|
[DataField("queue")]
|
||||||
public List<LatheRecipePrototype> Queue = new();
|
public List<LatheRecipePrototype> Queue = new();
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// How long the inserting animation will play
|
|
||||||
/// </summary>
|
|
||||||
[DataField("insertionTime")]
|
|
||||||
public float InsertionTime = 0.79f; // 0.01 off for animation timing
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The sound that plays when the lathe is producing an item, if any
|
/// The sound that plays when the lathe is producing an item, if any
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -46,9 +40,6 @@ namespace Content.Shared.Lathe
|
|||||||
|
|
||||||
[DataField("runningState", required: true)]
|
[DataField("runningState", required: true)]
|
||||||
public string RunningState = default!;
|
public string RunningState = default!;
|
||||||
|
|
||||||
[DataField("ignoreColor")]
|
|
||||||
public bool IgnoreColor;
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
using Robust.Shared.GameStates;
|
||||||
|
using Robust.Shared.Serialization;
|
||||||
|
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;
|
||||||
|
|
||||||
|
namespace Content.Shared.Materials;
|
||||||
|
|
||||||
|
[RegisterComponent, NetworkedComponent]
|
||||||
|
public sealed class InsertingMaterialStorageComponent : Component
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The time when insertion ends.
|
||||||
|
/// </summary>
|
||||||
|
[DataField("endTime", customTypeSerializer: typeof(TimeOffsetSerializer)), ViewVariables(VVAccess.ReadWrite)]
|
||||||
|
public TimeSpan EndTime;
|
||||||
|
|
||||||
|
[ViewVariables]
|
||||||
|
public Color? MaterialColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
[Serializable, NetSerializable]
|
||||||
|
public sealed class InsertingMaterialStorageComponentState : ComponentState
|
||||||
|
{
|
||||||
|
public TimeSpan EndTime;
|
||||||
|
public Color? MaterialColor;
|
||||||
|
|
||||||
|
public InsertingMaterialStorageComponentState(TimeSpan endTime, Color? materialColor)
|
||||||
|
{
|
||||||
|
EndTime = endTime;
|
||||||
|
MaterialColor = materialColor;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,6 +2,7 @@ using Content.Shared.Whitelist;
|
|||||||
using Robust.Shared.Audio;
|
using Robust.Shared.Audio;
|
||||||
using Robust.Shared.GameStates;
|
using Robust.Shared.GameStates;
|
||||||
using Robust.Shared.Serialization;
|
using Robust.Shared.Serialization;
|
||||||
|
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;
|
||||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.Dictionary;
|
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.Dictionary;
|
||||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.List;
|
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.List;
|
||||||
|
|
||||||
@@ -38,44 +39,56 @@ public sealed class MaterialStorageComponent : Component
|
|||||||
[DataField("materialWhiteList", customTypeSerializer: typeof(PrototypeIdListSerializer<MaterialPrototype>))]
|
[DataField("materialWhiteList", customTypeSerializer: typeof(PrototypeIdListSerializer<MaterialPrototype>))]
|
||||||
public List<string>? MaterialWhiteList;
|
public List<string>? MaterialWhiteList;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Whether or not the visualization for the insertion animation
|
||||||
|
/// should ignore the color of the material being inserted.
|
||||||
|
/// </summary>
|
||||||
|
[DataField("ignoreColor")]
|
||||||
|
public bool IgnoreColor;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The sound that plays when inserting an item into the storage
|
/// The sound that plays when inserting an item into the storage
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DataField("insertingSound")]
|
[DataField("insertingSound")]
|
||||||
public SoundSpecifier? InsertingSound;
|
public SoundSpecifier? InsertingSound;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// How long the inserting animation will play
|
||||||
|
/// </summary>
|
||||||
|
[DataField("insertionTime", customTypeSerializer: typeof(TimeOffsetSerializer))]
|
||||||
|
public TimeSpan InsertionTime = TimeSpan.FromSeconds(0.79f); // 0.01 off for animation timing
|
||||||
|
}
|
||||||
|
|
||||||
|
[Serializable, NetSerializable]
|
||||||
|
public enum MaterialStorageVisuals : byte
|
||||||
|
{
|
||||||
|
Inserting
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// event raised on the materialStorage when a material entity is inserted into it.
|
/// event raised on the materialStorage when a material entity is inserted into it.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public readonly struct MaterialEntityInsertedEvent
|
[ByRefEvent]
|
||||||
|
public readonly record struct MaterialEntityInsertedEvent(MaterialComponent MaterialComp)
|
||||||
{
|
{
|
||||||
public readonly MaterialComponent MaterialComp;
|
public readonly MaterialComponent MaterialComp = MaterialComp;
|
||||||
|
|
||||||
public MaterialEntityInsertedEvent(MaterialComponent materials)
|
|
||||||
{
|
|
||||||
MaterialComp = materials;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Event raised when a material amount is changed
|
/// Event raised when a material amount is changed
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public readonly struct MaterialAmountChangedEvent
|
[ByRefEvent]
|
||||||
{
|
public readonly record struct MaterialAmountChangedEvent;
|
||||||
|
|
||||||
}
|
/// <summary>
|
||||||
|
/// Event raised to get all the materials that the
|
||||||
public sealed class GetMaterialWhitelistEvent : EntityEventArgs
|
/// </summary>
|
||||||
|
[ByRefEvent]
|
||||||
|
public record struct GetMaterialWhitelistEvent(EntityUid Storage)
|
||||||
{
|
{
|
||||||
public readonly EntityUid Storage;
|
public readonly EntityUid Storage = Storage;
|
||||||
|
|
||||||
public List<string> Whitelist = new();
|
public List<string> Whitelist = new();
|
||||||
|
|
||||||
public GetMaterialWhitelistEvent(EntityUid storage)
|
|
||||||
{
|
|
||||||
Storage = storage;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Serializable, NetSerializable]
|
[Serializable, NetSerializable]
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Content.Shared.Interaction;
|
using Content.Shared.Interaction;
|
||||||
using Content.Shared.Stacks;
|
using Content.Shared.Stacks;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
using Robust.Shared.GameStates;
|
using Robust.Shared.GameStates;
|
||||||
|
using Robust.Shared.Prototypes;
|
||||||
|
using Robust.Shared.Timing;
|
||||||
|
|
||||||
namespace Content.Shared.Materials;
|
namespace Content.Shared.Materials;
|
||||||
|
|
||||||
@@ -12,14 +14,40 @@ namespace Content.Shared.Materials;
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public abstract class SharedMaterialStorageSystem : EntitySystem
|
public abstract class SharedMaterialStorageSystem : EntitySystem
|
||||||
{
|
{
|
||||||
|
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
|
||||||
|
[Dependency] private readonly IGameTiming _timing = default!;
|
||||||
|
[Dependency] private readonly IPrototypeManager _prototype = default!;
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public override void Initialize()
|
public override void Initialize()
|
||||||
{
|
{
|
||||||
base.Initialize();
|
base.Initialize();
|
||||||
|
|
||||||
|
SubscribeLocalEvent<MaterialStorageComponent, MapInitEvent>(OnMapInit);
|
||||||
SubscribeLocalEvent<MaterialStorageComponent, InteractUsingEvent>(OnInteractUsing);
|
SubscribeLocalEvent<MaterialStorageComponent, InteractUsingEvent>(OnInteractUsing);
|
||||||
SubscribeLocalEvent<MaterialStorageComponent, ComponentGetState>(OnGetState);
|
SubscribeLocalEvent<MaterialStorageComponent, ComponentGetState>(OnGetState);
|
||||||
SubscribeLocalEvent<MaterialStorageComponent, ComponentHandleState>(OnHandleState);
|
SubscribeLocalEvent<MaterialStorageComponent, ComponentHandleState>(OnHandleState);
|
||||||
|
SubscribeLocalEvent<InsertingMaterialStorageComponent, ComponentGetState>(OnGetInsertingState);
|
||||||
|
SubscribeLocalEvent<InsertingMaterialStorageComponent, ComponentHandleState>(OnHandleInsertingState);
|
||||||
|
SubscribeLocalEvent<InsertingMaterialStorageComponent, EntityUnpausedEvent>(OnUnpaused);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Update(float frameTime)
|
||||||
|
{
|
||||||
|
base.Update(frameTime);
|
||||||
|
foreach (var inserting in EntityQuery<InsertingMaterialStorageComponent>())
|
||||||
|
{
|
||||||
|
if (_timing.CurTime < inserting.EndTime)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
_appearance.SetData(inserting.Owner, MaterialStorageVisuals.Inserting, false);
|
||||||
|
RemComp(inserting.Owner, inserting);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnMapInit(EntityUid uid, MaterialStorageComponent component, MapInitEvent args)
|
||||||
|
{
|
||||||
|
_appearance.SetData(uid, MaterialStorageVisuals.Inserting, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnGetState(EntityUid uid, MaterialStorageComponent component, ref ComponentGetState args)
|
private void OnGetState(EntityUid uid, MaterialStorageComponent component, ref ComponentGetState args)
|
||||||
@@ -38,6 +66,25 @@ public abstract class SharedMaterialStorageSystem : EntitySystem
|
|||||||
component.MaterialWhiteList = new List<string>(state.MaterialWhitelist);
|
component.MaterialWhiteList = new List<string>(state.MaterialWhitelist);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void OnGetInsertingState(EntityUid uid, InsertingMaterialStorageComponent component, ref ComponentGetState args)
|
||||||
|
{
|
||||||
|
args.State = new InsertingMaterialStorageComponentState(component.EndTime, component.MaterialColor);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnHandleInsertingState(EntityUid uid, InsertingMaterialStorageComponent component, ref ComponentHandleState args)
|
||||||
|
{
|
||||||
|
if (args.Current is not InsertingMaterialStorageComponentState state)
|
||||||
|
return;
|
||||||
|
|
||||||
|
component.EndTime = state.EndTime;
|
||||||
|
component.MaterialColor = state.MaterialColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnUnpaused(EntityUid uid, InsertingMaterialStorageComponent component, ref EntityUnpausedEvent args)
|
||||||
|
{
|
||||||
|
component.EndTime += args.PausedTime;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the volume of a specified material contained in this storage.
|
/// Gets the volume of a specified material contained in this storage.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -128,7 +175,8 @@ public abstract class SharedMaterialStorageSystem : EntitySystem
|
|||||||
component.Storage.Add(materialId, 0);
|
component.Storage.Add(materialId, 0);
|
||||||
component.Storage[materialId] += volume;
|
component.Storage[materialId] += volume;
|
||||||
|
|
||||||
RaiseLocalEvent(uid, new MaterialAmountChangedEvent());
|
var ev = new MaterialAmountChangedEvent();
|
||||||
|
RaiseLocalEvent(uid, ref ev);
|
||||||
Dirty(component);
|
Dirty(component);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -171,7 +219,18 @@ public abstract class SharedMaterialStorageSystem : EntitySystem
|
|||||||
TryChangeMaterialAmount(receiver, mat, vol * multiplier, component);
|
TryChangeMaterialAmount(receiver, mat, vol * multiplier, component);
|
||||||
}
|
}
|
||||||
|
|
||||||
RaiseLocalEvent(component.Owner, new MaterialEntityInsertedEvent(material));
|
var insertingComp = EnsureComp<InsertingMaterialStorageComponent>(receiver);
|
||||||
|
insertingComp.EndTime = _timing.CurTime + component.InsertionTime;
|
||||||
|
if (!component.IgnoreColor)
|
||||||
|
{
|
||||||
|
_prototype.TryIndex<MaterialPrototype>(material.Materials.Keys.Last(), out var lastMat);
|
||||||
|
insertingComp.MaterialColor = lastMat?.Color;
|
||||||
|
}
|
||||||
|
_appearance.SetData(receiver, MaterialStorageVisuals.Inserting, true);
|
||||||
|
Dirty(insertingComp);
|
||||||
|
|
||||||
|
var ev = new MaterialEntityInsertedEvent(material);
|
||||||
|
RaiseLocalEvent(component.Owner, ref ev);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -186,7 +245,7 @@ public abstract class SharedMaterialStorageSystem : EntitySystem
|
|||||||
if (!Resolve(uid, ref component, false))
|
if (!Resolve(uid, ref component, false))
|
||||||
return;
|
return;
|
||||||
var ev = new GetMaterialWhitelistEvent(uid);
|
var ev = new GetMaterialWhitelistEvent(uid);
|
||||||
RaiseLocalEvent(uid, ev);
|
RaiseLocalEvent(uid, ref ev);
|
||||||
component.MaterialWhiteList = ev.Whitelist;
|
component.MaterialWhiteList = ev.Whitelist;
|
||||||
Dirty(component);
|
Dirty(component);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
shader: unshaded
|
shader: unshaded
|
||||||
map: ["enum.PowerDeviceVisualLayers.Powered"]
|
map: ["enum.PowerDeviceVisualLayers.Powered"]
|
||||||
- state: inserting
|
- state: inserting
|
||||||
map: ["enum.LatheVisualLayers.IsInserting"]
|
map: ["enum.MaterialStorageVisualLayers.Inserting"]
|
||||||
- state: panel
|
- state: panel
|
||||||
map: ["enum.WiresVisualLayers.MaintenancePanel"]
|
map: ["enum.WiresVisualLayers.MaintenancePanel"]
|
||||||
- type: Appearance
|
- type: Appearance
|
||||||
@@ -102,7 +102,7 @@
|
|||||||
shader: unshaded
|
shader: unshaded
|
||||||
map: ["enum.PowerDeviceVisualLayers.Powered"]
|
map: ["enum.PowerDeviceVisualLayers.Powered"]
|
||||||
- state: inserting
|
- state: inserting
|
||||||
map: ["enum.LatheVisualLayers.IsInserting"]
|
map: ["enum.MaterialStorageVisualLayers.Inserting"]
|
||||||
- state: panel
|
- state: panel
|
||||||
map: ["enum.WiresVisualLayers.MaintenancePanel"]
|
map: ["enum.WiresVisualLayers.MaintenancePanel"]
|
||||||
- type: Appearance
|
- type: Appearance
|
||||||
@@ -335,7 +335,7 @@
|
|||||||
- state: fab-idle
|
- state: fab-idle
|
||||||
map: ["enum.LatheVisualLayers.IsRunning"]
|
map: ["enum.LatheVisualLayers.IsRunning"]
|
||||||
- state: fab-load
|
- state: fab-load
|
||||||
map: ["enum.LatheVisualLayers.IsInserting"]
|
map: ["enum.MaterialStorageVisualLayers.Inserting"]
|
||||||
- state: fab-o
|
- state: fab-o
|
||||||
map: ["enum.WiresVisualLayers.MaintenancePanel"]
|
map: ["enum.WiresVisualLayers.MaintenancePanel"]
|
||||||
- type: Machine
|
- type: Machine
|
||||||
@@ -376,7 +376,7 @@
|
|||||||
shader: unshaded
|
shader: unshaded
|
||||||
map: ["enum.PowerDeviceVisualLayers.Powered"]
|
map: ["enum.PowerDeviceVisualLayers.Powered"]
|
||||||
- state: inserting
|
- state: inserting
|
||||||
map: ["enum.LatheVisualLayers.IsInserting"]
|
map: ["enum.MaterialStorageVisualLayers.Inserting"]
|
||||||
- state: panel
|
- state: panel
|
||||||
map: ["enum.WiresVisualLayers.MaintenancePanel"]
|
map: ["enum.WiresVisualLayers.MaintenancePanel"]
|
||||||
- type: Machine
|
- type: Machine
|
||||||
@@ -432,7 +432,7 @@
|
|||||||
shader: unshaded
|
shader: unshaded
|
||||||
map: ["enum.PowerDeviceVisualLayers.Powered"]
|
map: ["enum.PowerDeviceVisualLayers.Powered"]
|
||||||
- state: inserting
|
- state: inserting
|
||||||
map: ["enum.LatheVisualLayers.IsInserting"]
|
map: ["enum.MaterialStorageVisualLayers.Inserting"]
|
||||||
- state: panel
|
- state: panel
|
||||||
map: ["enum.WiresVisualLayers.MaintenancePanel"]
|
map: ["enum.WiresVisualLayers.MaintenancePanel"]
|
||||||
- type: Lathe
|
- type: Lathe
|
||||||
@@ -579,18 +579,18 @@
|
|||||||
shader: unshaded
|
shader: unshaded
|
||||||
map: ["enum.PowerDeviceVisualLayers.Powered"]
|
map: ["enum.PowerDeviceVisualLayers.Powered"]
|
||||||
- state: inserting
|
- state: inserting
|
||||||
map: ["enum.LatheVisualLayers.IsInserting"]
|
map: ["enum.MaterialStorageVisualLayers.Inserting"]
|
||||||
- state: panel
|
- state: panel
|
||||||
map: ["enum.WiresVisualLayers.MaintenancePanel"]
|
map: ["enum.WiresVisualLayers.MaintenancePanel"]
|
||||||
- type: Machine
|
- type: Machine
|
||||||
board: OreProcessorMachineCircuitboard
|
board: OreProcessorMachineCircuitboard
|
||||||
- type: MaterialStorage
|
- type: MaterialStorage
|
||||||
dropOnDeconstruct: false #should drop ores instead of ingots/sheets
|
dropOnDeconstruct: false #should drop ores instead of ingots/sheets
|
||||||
|
ignoreColor: true
|
||||||
whitelist:
|
whitelist:
|
||||||
tags:
|
tags:
|
||||||
- Ore
|
- Ore
|
||||||
- type: Lathe
|
- type: Lathe
|
||||||
ignoreColor: true
|
|
||||||
staticRecipes:
|
staticRecipes:
|
||||||
- SheetSteel30
|
- SheetSteel30
|
||||||
- SheetGlass30
|
- SheetGlass30
|
||||||
|
|||||||
Reference in New Issue
Block a user