SharedAppearanceSystem.TryGetData() generics support and small VisualizerSystem tweak (#3583)

This commit is contained in:
AJCM-git
2022-12-20 18:21:10 -04:00
committed by GitHub
parent 1bbfd6b38f
commit 78a75daea2
4 changed files with 15 additions and 11 deletions

View File

@@ -19,16 +19,15 @@ public sealed class GenericVisualizerSystem : VisualizerSystem<GenericVisualizer
foreach (var (appearanceKey, layerDict) in component.Visuals)
{
if (!_appearanceSys.TryGetData(uid, appearanceKey, out var appearanceValue, args.Component))
if (!_appearanceSys.TryGetData<string?>(uid, appearanceKey, out var appearanceValue, args.Component))
continue;
var valueString = appearanceValue.ToString();
if (string.IsNullOrEmpty(valueString))
if (string.IsNullOrEmpty(appearanceValue))
continue;
foreach (var (layerKeyRaw, layerDataDict) in layerDict)
{
if (!layerDataDict.TryGetValue(valueString, out var layerData))
if (!layerDataDict.TryGetValue(appearanceValue, out var layerData))
continue;
object layerKey = _refMan.TryParseEnumReference(layerKeyRaw, out var @enum)

View File

@@ -10,7 +10,8 @@ namespace Robust.Client.GameObjects;
public abstract class VisualizerSystem<T> : EntitySystem
where T: Component
{
[Dependency] protected readonly AppearanceSystem AppearanceSystem = default!;
[Dependency] protected readonly AppearanceSystem AppearanceSystem = default!;
[Dependency] protected readonly AnimationPlayerSystem AnimationSystem = default!;
public override void Initialize()
{

View File

@@ -30,6 +30,7 @@ public abstract class AppearanceComponent : Component
_sysMan.GetEntitySystem<SharedAppearanceSystem>().SetData(Owner, key, value, this);
}
[Obsolete("Use SharedAppearanceSystem instead")]
public bool TryGetData<T>(Enum key, [NotNullWhen(true)] out T data)
{
if (AppearanceData.TryGetValue(key, out var dat) && dat is T)

View File

@@ -40,7 +40,7 @@ public abstract class SharedAppearanceSystem : EntitySystem
// anyways, so we can skip this.
if (_timing.ApplyingState
&& component.NetSyncEnabled) // TODO consider removing this and avoiding the component resolve altogether.
return;
return;
if (component.AppearanceData.TryGetValue(key, out var existing) && existing.Equals(value))
return;
@@ -52,15 +52,18 @@ public abstract class SharedAppearanceSystem : EntitySystem
MarkDirty(component);
}
public bool TryGetData(EntityUid uid, Enum key, [MaybeNullWhen(false)] out object value, AppearanceComponent? component = null)
public bool TryGetData<T>(EntityUid uid, Enum key, [NotNullWhen(true)] out T value, AppearanceComponent? component = null)
{
if (!Resolve(uid, ref component))
if (Resolve(uid, ref component) &&
component.AppearanceData.TryGetValue(key, out var objValue) &&
objValue is T)
{
value = null;
return false;
value = (T)objValue;
return true;
}
return component.AppearanceData.TryGetValue(key, out value);
value = default!;
return false;
}
}