Fix bad reflection usage from OverlayEffectsComponent.

This commit is contained in:
Pieter-Jan Briers
2020-11-24 00:14:46 +01:00
parent fcb5787d33
commit 6395345925
4 changed files with 19 additions and 26 deletions

View File

@@ -141,23 +141,11 @@ namespace Content.Client.GameObjects.Components.Mobs
private void UpdateOverlayConfiguration(OverlayContainer container, Overlay overlay) private void UpdateOverlayConfiguration(OverlayContainer container, Overlay overlay)
{ {
var configurableTypes = overlay.GetType() if (overlay is IConfigurableOverlay configurable)
.GetInterfaces()
.Where(type =>
type.IsGenericType
&& type.GetGenericTypeDefinition() == typeof(IConfigurable<>)
&& container.Parameters.Exists(p => p.GetType() == type.GenericTypeArguments.First()))
.ToList();
if (configurableTypes.Count > 0)
{ {
foreach (var type in configurableTypes) foreach (var param in container.Parameters)
{ {
var method = type.GetMethod(nameof(IConfigurable<object>.Configure)); configurable.Configure(param);
var parameter = container.Parameters
.First(p => p.GetType() == type.GenericTypeArguments.First());
method!.Invoke(overlay, new []{ parameter });
} }
} }
} }
@@ -169,7 +157,7 @@ namespace Content.Client.GameObjects.Components.Mobs
if (overlayType != null) if (overlayType != null)
{ {
overlay = Activator.CreateInstance(overlayType) as Overlay; overlay = IoCManager.Resolve<IDynamicTypeFactory>().CreateInstance<Overlay>(overlayType);
UpdateOverlayConfiguration(container, overlay); UpdateOverlayConfiguration(container, overlay);
return true; return true;
} }

View File

@@ -14,7 +14,7 @@ using SixLabors.ImageSharp.PixelFormats;
namespace Content.Client.Graphics.Overlays namespace Content.Client.Graphics.Overlays
{ {
public class FlashOverlay : Overlay, IConfigurable<TimedOverlayParameter> public class FlashOverlay : Overlay, IConfigurableOverlay
{ {
[Dependency] private readonly IPrototypeManager _prototypeManager = default!; [Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[Dependency] private readonly IClyde _displayManager = default!; [Dependency] private readonly IClyde _displayManager = default!;
@@ -61,9 +61,12 @@ namespace Content.Client.Graphics.Overlays
_screenshotTexture = null; _screenshotTexture = null;
} }
public void Configure(TimedOverlayParameter parameters) public void Configure(OverlayParameter parameters)
{ {
_lastsFor = parameters.Length; if (parameters is TimedOverlayParameter timedParams)
{
_lastsFor = timedParams.Length;
}
} }
} }
} }

View File

@@ -1,7 +0,0 @@
namespace Content.Shared.Interfaces
{
public interface IConfigurable<in T>
{
public void Configure(T parameters);
}
}

View File

@@ -0,0 +1,9 @@
using Content.Shared.GameObjects.Components.Mobs;
namespace Content.Shared.Interfaces
{
public interface IConfigurableOverlay
{
void Configure(OverlayParameter parameter);
}
}