Rework of FFI, adding a value identifier, so we can keep knowledge of data even when data moves.
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
use crate::StringKey;
|
||||
use crate::{StringKey, ValueIdentifiable, ValueIdentifier};
|
||||
#[doc(inline)]
|
||||
pub use growth_rates::*;
|
||||
#[doc(inline)]
|
||||
@@ -40,22 +40,57 @@ mod statistics;
|
||||
#[cfg_attr(feature = "wasm", derive(unique_type_id_derive::UniqueTypeId))]
|
||||
pub enum EffectParameter {
|
||||
/// A boolean value.
|
||||
Bool(bool),
|
||||
Bool(ValueIdentifier, bool),
|
||||
/// An integer value. Stored as a 64 bit int to deal with potentially large numbers.
|
||||
Int(i64),
|
||||
Int(ValueIdentifier, i64),
|
||||
/// A float value. Stored as a 32 bit float.
|
||||
Float(f32),
|
||||
Float(ValueIdentifier, f32),
|
||||
/// A string value.
|
||||
String(StringKey),
|
||||
String(ValueIdentifier, StringKey),
|
||||
}
|
||||
|
||||
impl Into<EffectParameter> for bool {
|
||||
fn into(self) -> EffectParameter {
|
||||
EffectParameter::Bool(Default::default(), self)
|
||||
}
|
||||
}
|
||||
|
||||
impl Into<EffectParameter> for i64 {
|
||||
fn into(self) -> EffectParameter {
|
||||
EffectParameter::Int(Default::default(), self)
|
||||
}
|
||||
}
|
||||
|
||||
impl Into<EffectParameter> for f32 {
|
||||
fn into(self) -> EffectParameter {
|
||||
EffectParameter::Float(Default::default(), self)
|
||||
}
|
||||
}
|
||||
|
||||
impl Into<EffectParameter> for StringKey {
|
||||
fn into(self) -> EffectParameter {
|
||||
EffectParameter::String(Default::default(), self)
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for EffectParameter {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
EffectParameter::Bool(v) => f.write_fmt(format_args!("EffectParameter::Bool({})", v)),
|
||||
EffectParameter::Int(v) => f.write_fmt(format_args!("EffectParameter::Int({})", v)),
|
||||
EffectParameter::Float(v) => f.write_fmt(format_args!("EffectParameter::Float({})", v)),
|
||||
EffectParameter::String(v) => f.write_fmt(format_args!("EffectParameter::String({})", v)),
|
||||
EffectParameter::Bool(_, v) => f.write_fmt(format_args!("EffectParameter::Bool({})", v)),
|
||||
EffectParameter::Int(_, v) => f.write_fmt(format_args!("EffectParameter::Int({})", v)),
|
||||
EffectParameter::Float(_, v) => f.write_fmt(format_args!("EffectParameter::Float({})", v)),
|
||||
EffectParameter::String(_, v) => f.write_fmt(format_args!("EffectParameter::String({})", v)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ValueIdentifiable for EffectParameter {
|
||||
fn value_identifier(&self) -> ValueIdentifier {
|
||||
match self {
|
||||
EffectParameter::Bool(i, _) => *i,
|
||||
EffectParameter::Int(i, _) => *i,
|
||||
EffectParameter::Float(i, _) => *i,
|
||||
EffectParameter::String(i, _) => *i,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user