65 lines
2.4 KiB
C#
65 lines
2.4 KiB
C#
using System;
|
|
using PkmnLibSharp.Utils;
|
|
using Interface = PkmnLibSharp.FFI.StaticData.EffectParameter;
|
|
|
|
namespace PkmnLibSharp.StaticData
|
|
{
|
|
public class EffectParameter : HandleType
|
|
{
|
|
private ParameterType? _type;
|
|
public ParameterType? Type => _type ??= (ParameterType)Interface.effect_parameter_get_type(Handle);
|
|
|
|
private object? _data;
|
|
|
|
public object Data
|
|
{
|
|
get
|
|
{
|
|
_data ??= Type switch
|
|
{
|
|
ParameterType.Bool => Interface.effect_parameter_get_as_bool(Handle).Result() == 1,
|
|
ParameterType.Int => Interface.effect_parameter_get_as_int(Handle).Result(),
|
|
ParameterType.Float => Interface.effect_parameter_get_as_float(Handle).Result(),
|
|
ParameterType.String => Interface.effect_parameter_get_as_string(Handle).Result().PtrString()!,
|
|
_ => throw new ArgumentOutOfRangeException()
|
|
};
|
|
return _data!;
|
|
}
|
|
}
|
|
|
|
protected EffectParameter(FFIHandle handle) : base(handle)
|
|
{
|
|
}
|
|
|
|
public static EffectParameter FromBool(bool b) =>
|
|
Resolver.Instance.ResolveEffectParameter(Interface.effect_parameter_new_bool(b.ForeignBool()).Resolve());
|
|
|
|
public static EffectParameter FromLong(long l) =>
|
|
Resolver.Instance.ResolveEffectParameter(Interface.effect_parameter_new_int(l).Resolve());
|
|
|
|
public static EffectParameter FromFloat(float f) =>
|
|
Resolver.Instance.ResolveEffectParameter(Interface.effect_parameter_new_float(f).Resolve());
|
|
|
|
public static EffectParameter FromString(string s) =>
|
|
Resolver.Instance.ResolveEffectParameter(Interface.effect_parameter_new_string(s.ToPtr()).Result().Resolve());
|
|
|
|
public static implicit operator EffectParameter(bool b) => FromBool(b);
|
|
public static implicit operator EffectParameter(long l) => FromLong(l);
|
|
public static implicit operator EffectParameter(float f) => FromFloat(f);
|
|
public static implicit operator EffectParameter(string s) => FromString(s);
|
|
|
|
public enum ParameterType : byte
|
|
{
|
|
Bool = 0,
|
|
Int = 1,
|
|
Float = 2,
|
|
String = 3,
|
|
}
|
|
|
|
public override string ToString()
|
|
{
|
|
var data = Data;
|
|
return data is string ? $"{Type}(\"{data}\")" : $"{Type}({data})";
|
|
}
|
|
}
|
|
} |