using System;
using System.Collections.Generic;
using System.Reflection;
using Amphora;
using Azimuth;
using Prism;
namespace Konis.Testbed
{
///
/// One property of an emitter def that a tuning panel can show, and mostly change.
///
public class TunableProperty
{
private static readonly object[] NoChoices = new object[0];
private readonly PropertyInfo property;
///
/// Wraps , which must have a public getter and setter.
///
public TunableProperty(PropertyInfo property, TunableKind kind, TuneEffect effect)
{
this.property = property ?? throw new ArgumentNullException(nameof(property));
Kind = kind;
Effect = effect;
Choices = ChoicesFor(property, kind);
}
private static object[] ChoicesFor(PropertyInfo property, TunableKind kind)
{
if (kind == TunableKind.Sprite)
{
var sprites = new object[SpriteChoices.All.Count];
for (int i = 0; i < sprites.Length; i++)
{
sprites[i] = SpriteChoices.All[i].Def;
}
return sprites;
}
if (kind != TunableKind.Choice)
{
return NoChoices;
}
Array values = Enum.GetValues(property.PropertyType);
var returnMe = new object[values.Length];
values.CopyTo(returnMe, 0);
return returnMe;
}
///
/// Gets the property's name, which is how a def's initializer spells it.
///
public string Name => property.Name;
///
/// Gets the shape of value the property holds.
///
public TunableKind Kind { get; }
///
/// Gets what changing the property does to an emitter that is already running.
///
public TuneEffect Effect { get; }
///
/// Gets the type of value the property holds.
///
public Type ValueType => Kind == TunableKind.Gradient ? typeof(Gradient) : property.PropertyType;
///
/// Gets the values a or can take, in the
/// order a list shows them. It is empty for any other kind.
///
public IReadOnlyList