72 lines
2.3 KiB
Rust
Executable File
72 lines
2.3 KiB
Rust
Executable File
use crate::app_interface::StringKey;
|
|
use crate::{ExternRef, ExternalReferenceType};
|
|
use core::fmt::{Display, Formatter};
|
|
|
|
#[repr(u8)]
|
|
enum EffectParameterType {
|
|
None,
|
|
Bool,
|
|
Int,
|
|
Float,
|
|
String,
|
|
}
|
|
|
|
#[derive(Clone)]
|
|
pub enum EffectParameter {
|
|
None,
|
|
Bool(bool),
|
|
Int(i64),
|
|
Float(f32),
|
|
String(StringKey),
|
|
}
|
|
|
|
impl EffectParameter {
|
|
#[cfg(not(feature = "mock_data"))]
|
|
pub(crate) fn new(ptr: ExternRef<Self>) -> Self {
|
|
unsafe {
|
|
match effect_parameter_get_type(ptr) {
|
|
EffectParameterType::None => Self::None,
|
|
EffectParameterType::Bool => Self::Bool(effect_parameter_as_bool(ptr)),
|
|
EffectParameterType::Int => Self::Int(effect_parameter_as_int(ptr)),
|
|
EffectParameterType::Float => Self::Float(effect_parameter_as_float(ptr)),
|
|
EffectParameterType::String => {
|
|
Self::String(StringKey::new(effect_parameter_as_string(ptr)))
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
#[cfg(not(feature = "mock_data"))]
|
|
impl ExternalReferenceType for EffectParameter {
|
|
fn from_extern_value(reference: ExternRef<Self>) -> Self
|
|
where
|
|
Self: Sized,
|
|
{
|
|
EffectParameter::new(reference)
|
|
}
|
|
}
|
|
|
|
impl Display for EffectParameter {
|
|
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
|
|
match self {
|
|
EffectParameter::None => f.write_str("EffectParameter::None"),
|
|
EffectParameter::Bool(b) => f.write_fmt(format_args!("EffectParameter::Bool({})", b)),
|
|
EffectParameter::Int(i) => f.write_fmt(format_args!("EffectParameter::Int({})", i)),
|
|
EffectParameter::Float(r) => f.write_fmt(format_args!("EffectParameter::Float({})", r)),
|
|
EffectParameter::String(s) => {
|
|
f.write_fmt(format_args!("EffectParameter::String(\"{}\")", s))
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
#[cfg(not(feature = "mock_data"))]
|
|
extern "wasm" {
|
|
fn effect_parameter_get_type(ptr: ExternRef<EffectParameter>) -> EffectParameterType;
|
|
fn effect_parameter_as_bool(ptr: ExternRef<EffectParameter>) -> bool;
|
|
fn effect_parameter_as_int(ptr: ExternRef<EffectParameter>) -> i64;
|
|
fn effect_parameter_as_float(ptr: ExternRef<EffectParameter>) -> f32;
|
|
fn effect_parameter_as_string(ptr: ExternRef<EffectParameter>) -> ExternRef<StringKey>;
|
|
}
|