Resolves SingularityVisualizer is Obsolete (#13906)
* Split SingularityVisualizer into Component/System pair * Server ignore SingularityVisualizer * Update YAML * Move to SingularityComponent
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
using Robust.Shared.GameStates;
|
||||
using Content.Shared.Singularity;
|
||||
using Content.Shared.Singularity.Components;
|
||||
using Content.Shared.Singularity.EntitySystems;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Content.Client.Singularity.EntitySystems;
|
||||
|
||||
@@ -10,11 +13,14 @@ namespace Content.Client.Singularity.EntitySystems;
|
||||
/// </summary>
|
||||
public sealed class SingularitySystem : SharedSingularitySystem
|
||||
{
|
||||
[Dependency] private readonly AppearanceSystem _appearanceSystem = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<SingularityComponent, ComponentHandleState>(HandleSingularityState);
|
||||
SubscribeLocalEvent<SingularityComponent, AppearanceChangeEvent>(OnAppearanceChange);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -30,4 +36,31 @@ public sealed class SingularitySystem : SharedSingularitySystem
|
||||
|
||||
SetLevel(uid, state.Level, comp);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles ensuring that the singularity has a sprite to see.
|
||||
/// </summary>
|
||||
protected override void OnSingularityStartup(EntityUid uid, SingularityComponent comp, ComponentStartup args)
|
||||
{
|
||||
base.OnSingularityStartup(uid, comp, args);
|
||||
if (TryComp<SpriteComponent>(uid, out var sprite))
|
||||
{
|
||||
sprite.LayerMapReserveBlank(comp.Layer);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles updating the visible state of the singularity to reflect its current level.
|
||||
/// </summary>
|
||||
private void OnAppearanceChange(EntityUid uid, SingularityComponent comp, ref AppearanceChangeEvent args)
|
||||
{
|
||||
if (args.Sprite == null)
|
||||
return;
|
||||
|
||||
if(!_appearanceSystem.TryGetData<byte>(uid, SingularityVisuals.Level, out var level, args.Component))
|
||||
return;
|
||||
|
||||
args.Sprite.LayerSetSprite(comp.Layer,
|
||||
new SpriteSpecifier.Rsi(new ResourcePath($"{comp.BaseSprite.RsiPath}_{level}.rsi"), $"{comp.BaseSprite.RsiState}_{level}"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,43 +0,0 @@
|
||||
using Content.Shared.Singularity;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Content.Client.Singularity.Visualizers
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public sealed class SingularityVisualizer : AppearanceVisualizer
|
||||
{
|
||||
[DataField("layer")]
|
||||
private int Layer { get; } = 0;
|
||||
|
||||
[Obsolete("Subscribe to your component being initialised instead.")]
|
||||
public override void InitializeEntity(EntityUid entity)
|
||||
{
|
||||
base.InitializeEntity(entity);
|
||||
|
||||
IoCManager.Resolve<IEntityManager>().GetComponentOrNull<SpriteComponent>(entity)?.LayerMapReserveBlank(Layer);
|
||||
}
|
||||
|
||||
[Obsolete("Subscribe to AppearanceChangeEvent instead.")]
|
||||
public override void OnChangeData(AppearanceComponent component)
|
||||
{
|
||||
base.OnChangeData(component);
|
||||
|
||||
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(component.Owner, out SpriteComponent? sprite))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!component.TryGetData(SingularityVisuals.Level, out byte level))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
sprite.LayerSetSprite(Layer, new SpriteSpecifier.Rsi(new ResourcePath("Structures/Power/Generation/Singularity/singularity_" + level + ".rsi"), "singularity_" + level));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ using Robust.Shared.GameStates;
|
||||
|
||||
using Content.Shared.Singularity.EntitySystems;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Content.Shared.Singularity.Components;
|
||||
|
||||
@@ -81,6 +82,22 @@ public sealed class SingularityComponent : Component
|
||||
|
||||
#endregion Audio
|
||||
|
||||
#region Appearance
|
||||
|
||||
/// <summary>
|
||||
/// The sprite layer the singularity appearance is attached to.
|
||||
/// </summary>
|
||||
[DataField("layer")]
|
||||
public int Layer { get; } = 0;
|
||||
|
||||
/// <summary>
|
||||
/// The base sprite file and state of the singularity.
|
||||
/// </summary>
|
||||
[DataField("baseSprite")]
|
||||
public SpriteSpecifier.Rsi BaseSprite = new SpriteSpecifier.Rsi(new ResourcePath("Structures/Power/Generation/Singularity/singularity"), "singularity");
|
||||
|
||||
#endregion Appearance
|
||||
|
||||
#region Update Timing
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -45,7 +45,5 @@
|
||||
enabled: true
|
||||
radius: 10
|
||||
- type: Appearance
|
||||
visuals:
|
||||
- type: SingularityVisualizer
|
||||
- type: GuideHelp
|
||||
guides: [ Singularity, Power ]
|
||||
|
||||
Reference in New Issue
Block a user