mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-02-15 03:30:53 +01:00
SharedAppearanceSystem.TryGetData() generics support and small VisualizerSystem tweak (#3583)
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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()
|
||||
{
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user