use crate::components::BehaviorLiteral;
use crate::ecs::{Entity, TraceVal};
#[derive(Clone, Copy, Debug, PartialEq)]
pub enum Val {
Bool(bool),
Int(i32),
Float(f32),
Vec3([f32; 3]),
Entity(Entity),
}
impl Val {
pub(crate) fn as_bool(self) -> Option<bool> {
match self {
Val::Bool(b) => Some(b),
_ => None,
}
}
pub(crate) fn as_entity(self) -> Option<Entity> {
match self {
Val::Entity(e) => Some(e),
_ => None,
}
}
pub(crate) fn as_vec3(self) -> Option<[f32; 3]> {
match self {
Val::Vec3(v) => Some(v),
_ => None,
}
}
pub fn as_f32(self) -> Option<f32> {
match self {
Val::Int(i) => Some(i as f32),
Val::Float(f) => Some(f),
_ => None,
}
}
pub fn from_literal(lit: &BehaviorLiteral) -> Val {
match *lit {
BehaviorLiteral::Bool(b) => Val::Bool(b),
BehaviorLiteral::Int(i) => Val::Int(i),
BehaviorLiteral::Float(f) => Val::Float(f),
BehaviorLiteral::Vec3(v) => Val::Vec3(v),
}
}
pub fn to_literal(self) -> BehaviorLiteral {
match self {
Val::Bool(b) => BehaviorLiteral::Bool(b),
Val::Int(i) => BehaviorLiteral::Int(i),
Val::Float(f) => BehaviorLiteral::Float(f),
Val::Vec3(v) => BehaviorLiteral::Vec3(v),
Val::Entity(_) => BehaviorLiteral::Int(0),
}
}
pub fn to_trace(self) -> TraceVal {
match self {
Val::Bool(b) => TraceVal::Bool(b),
Val::Int(i) => TraceVal::Int(i),
Val::Float(f) => TraceVal::Float(f),
Val::Vec3(v) => TraceVal::Vec3(v),
Val::Entity(e) => TraceVal::Entity(e.to_bits()),
}
}
pub fn same_type(self, other: Val) -> bool {
core::mem::discriminant(&self) == core::mem::discriminant(&other)
}
}
#[derive(Clone, Copy, Debug)]
pub enum Arith {
Add,
Sub,
Mul,
Div,
}
#[derive(Clone, Copy, Debug)]
pub enum Cmp {
Eq,
Ne,
Lt,
Le,
Gt,
Ge,
}