diff options
author | 2024-10-11 16:03:43 -0400 | |
---|---|---|
committer | 2024-10-11 16:03:43 -0400 | |
commit | 535436e2e9164f9880e507d7057a8cdbf261608e (patch) | |
tree | db370db8e0caea99a9e6e3c501c7ea7e3b6dd708 /src/payload.rs | |
parent | ebc3ccfea4027a3eb0c80f6a3d64b6425d32d1ef (diff) | |
parent | 16c1574e400d73198713336e18975ff37ab78290 (diff) |
Merge pull request #1 from exvacuum/navigation
Navigation
Diffstat (limited to 'src/payload.rs')
-rw-r--r-- | src/payload.rs | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/src/payload.rs b/src/payload.rs new file mode 100644 index 0000000..2aa3f23 --- /dev/null +++ b/src/payload.rs @@ -0,0 +1,84 @@ +use std::{collections::HashMap, str::FromStr}; + +use avian3d::prelude::RigidBody; +use bevy::prelude::*; +use serde::{Deserialize, Serialize}; +use strum::{EnumDiscriminants, EnumString}; +use yarnspinner::core::YarnValue; + +#[derive(Serialize, Deserialize, Default, Clone, Deref, DerefMut, Debug)] +pub struct DirworldEntityPayload(Vec<DirworldComponent>); + +impl DirworldEntityPayload { + pub fn component(&self, name: &str) -> Option<&DirworldComponent> { + if let Ok(discriminant) = DirworldComponentDiscriminants::from_str(name) { + self.iter() + .find(|component| discriminant == DirworldComponentDiscriminants::from(*component)) + } else { + None + } + } + + pub fn component_mut(&mut self, name: &str) -> Option<&mut DirworldComponent> { + if let Ok(discriminant) = DirworldComponentDiscriminants::from_str(name) { + self.iter_mut() + .find(|component| discriminant == DirworldComponentDiscriminants::from(&**component)) + } else { + None + } + } + + pub fn components(&self, name: &str) -> Vec<&DirworldComponent> { + if let Ok(discriminant) = DirworldComponentDiscriminants::from_str(name) { + self.iter() + .filter(|component| { + discriminant == DirworldComponentDiscriminants::from(*component) + }) + .collect() + } else { + vec![] + } + } + + pub fn components_mut(&mut self, name: &str) -> Vec<&mut DirworldComponent> { + if let Ok(discriminant) = DirworldComponentDiscriminants::from_str(name) { + self.iter_mut() + .filter(|component| { + discriminant == DirworldComponentDiscriminants::from(&**component) + }) + .collect() + } else { + vec![] + } + } +} + +#[derive(Serialize, Deserialize, Clone, EnumDiscriminants, Debug)] +#[strum_discriminants(derive(EnumString))] +pub enum DirworldComponent { + Transform(Transform), + Name(String), + Actor { + local_variables: HashMap<String, YarnValue>, + yarn_source: Vec<u8>, + }, + Voice { + pitch: i32, + preset: i32, + bank: i32, + variance: u32, + speed: f32, + }, + Rigidbody(RigidBody), + MeshCollider { + convex: bool, + sensor: bool, + }, + Script { + lua_source: Vec<u8>, + }, + Relationship { + label: String, + hash: [u8; 16], + }, +} |