1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
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],
},
}
|