Resolves TabletopItemVisualizer is Obsolete (#13911)

This commit is contained in:
TemporalOroboros
2023-02-03 06:47:29 -08:00
committed by GitHub
parent 1808b640ed
commit 0edbc21ce8
7 changed files with 34 additions and 41 deletions

View File

@@ -1,35 +0,0 @@
using Content.Shared.Tabletop;
using JetBrains.Annotations;
using Robust.Client.GameObjects;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Maths;
namespace Content.Client.Tabletop.Visualizers
{
[UsedImplicitly]
public sealed class TabletopItemVisualizer : AppearanceVisualizer
{
[Obsolete("Subscribe to AppearanceChangeEvent instead.")]
public override void OnChangeData(AppearanceComponent appearance)
{
var entities = IoCManager.Resolve<IEntityManager>();
if (!entities.TryGetComponent<SpriteComponent>(appearance.Owner, out var sprite))
{
return;
}
// TODO: maybe this can work more nicely, by maybe only having to set the item to "being dragged", and have
// the appearance handle the rest
if (appearance.TryGetData<Vector2>(TabletopItemVisuals.Scale, out var scale))
{
sprite.Scale = scale;
}
if (appearance.TryGetData<int>(TabletopItemVisuals.DrawDepth, out var drawDepth))
{
sprite.DrawDepth = drawDepth;
}
}
}
}

View File

@@ -0,0 +1,5 @@
namespace Content.Client.Tabletop.Visualizers;
[RegisterComponent]
public sealed class TabletopItemVisualizerComponent : Component
{}

View File

@@ -0,0 +1,25 @@
using Content.Shared.Tabletop;
using Robust.Client.GameObjects;
namespace Content.Client.Tabletop.Visualizers;
public sealed class TabletopItemVisualizerSystem : VisualizerSystem<TabletopItemVisualizerComponent>
{
protected override void OnAppearanceChange(EntityUid uid, TabletopItemVisualizerComponent comp, ref AppearanceChangeEvent args)
{
if (args.Sprite == null)
return;
// TODO: maybe this can work more nicely, by maybe only having to set the item to "being dragged", and have
// the appearance handle the rest
if (AppearanceSystem.TryGetData<Vector2>(uid, TabletopItemVisuals.Scale, out var scale, args.Component))
{
args.Sprite.Scale = scale;
}
if (AppearanceSystem.TryGetData<int>(uid, TabletopItemVisuals.DrawDepth, out var drawDepth, args.Component))
{
args.Sprite.DrawDepth = drawDepth;
}
}
}

View File

@@ -20,6 +20,7 @@ namespace Content.Server.Entry
"PuddleVisualizer",
"UIFragment",
"PDABorderColor",
"TabletopItemVisualizer",
};
}
}

View File

@@ -35,7 +35,6 @@
netsync: false
noRot: true
- type: Appearance
visuals:
- type: TabletopItemVisualizer
# The pieces

View File

@@ -36,7 +36,6 @@
netsync: false
noRot: true
- type: Appearance
visuals:
- type: TabletopItemVisualizer
# White pieces

View File

@@ -9,7 +9,6 @@
noRot: true
sprite: Objects/Fun/Tabletop/generic_pieces.rsi
- type: Appearance
visuals:
- type: TabletopItemVisualizer
- type: entity