1pub mod objects;
12pub mod actions;
13pub mod traits;
14pub mod systems;
15pub mod error;
16
17pub use objects::Object;
19pub use actions::{Action, ActionContext, ActionResult};
20pub use traits::{Trait, TraitData};
21pub use systems::{System, SystemManager, Priority};
22pub use error::OatsError;
23
24pub type Result<T> = std::result::Result<T, OatsError>;
26
27#[derive(Default)]
29pub struct OatsSystem {
30 objects: Vec<Object>,
31 actions: Vec<Box<dyn Action>>,
32 systems: Vec<Box<dyn System>>,
33}
34
35impl OatsSystem {
36 #[inline]
38 pub fn new() -> Self {
39 Self::default()
40 }
41
42 pub fn with_capacity(objects: usize, actions: usize, systems: usize) -> Self {
44 Self {
45 objects: Vec::with_capacity(objects),
46 actions: Vec::with_capacity(actions),
47 systems: Vec::with_capacity(systems),
48 }
49 }
50
51 #[inline]
53 pub fn add_object(&mut self, object: Object) {
54 self.objects.push(object);
55 }
56
57 pub fn add_objects(&mut self, objects: impl IntoIterator<Item = Object>) {
59 self.objects.extend(objects);
60 }
61
62 #[inline]
64 pub fn add_action(&mut self, action: Box<dyn Action>) {
65 self.actions.push(action);
66 }
67
68 #[inline]
70 pub fn add_system(&mut self, system: Box<dyn System>) {
71 self.systems.push(system);
72 }
73
74 #[inline]
76 pub fn objects(&self) -> &[Object] {
77 &self.objects
78 }
79
80 #[inline]
82 pub fn actions(&self) -> &[Box<dyn Action>] {
83 &self.actions
84 }
85
86 #[inline]
88 pub fn systems(&self) -> &[Box<dyn System>] {
89 &self.systems
90 }
91
92 #[inline]
94 pub fn object_count(&self) -> usize {
95 self.objects.len()
96 }
97
98 #[inline]
100 pub fn action_count(&self) -> usize {
101 self.actions.len()
102 }
103
104 #[inline]
106 pub fn system_count(&self) -> usize {
107 self.systems.len()
108 }
109
110 #[inline]
112 pub fn clear_objects(&mut self) {
113 self.objects.clear();
114 }
115
116 #[inline]
118 pub fn clear_actions(&mut self) {
119 self.actions.clear();
120 }
121
122 #[inline]
124 pub fn clear_systems(&mut self) {
125 self.systems.clear();
126 }
127
128 #[inline]
130 pub fn reserve_objects(&mut self, additional: usize) {
131 self.objects.reserve(additional);
132 }
133
134 #[inline]
136 pub fn reserve_actions(&mut self, additional: usize) {
137 self.actions.reserve(additional);
138 }
139
140 #[inline]
142 pub fn reserve_systems(&mut self, additional: usize) {
143 self.systems.reserve(additional);
144 }
145}
146
147#[cfg(test)]
148mod tests {
149 use super::*;
150
151 #[test]
152 fn test_oats_system_creation() {
153 let system = OatsSystem::new();
154 assert_eq!(system.object_count(), 0);
155 assert_eq!(system.action_count(), 0);
156 assert_eq!(system.system_count(), 0);
157 }
158
159 #[test]
160 fn test_oats_system_with_capacity() {
161 let system = OatsSystem::with_capacity(100, 10, 5);
162 assert_eq!(system.object_count(), 0);
163 assert_eq!(system.action_count(), 0);
164 assert_eq!(system.system_count(), 0);
165 }
166
167 #[test]
168 fn test_oats_system_operations() {
169 let mut system = OatsSystem::new();
170
171 let obj = Object::new("test", "type");
173 system.add_object(obj);
174 assert_eq!(system.object_count(), 1);
175
176 let objects = vec![
178 Object::new("obj1", "type"),
179 Object::new("obj2", "type"),
180 ];
181 system.add_objects(objects);
182 assert_eq!(system.object_count(), 3);
183
184 system.reserve_objects(100);
186 assert!(system.objects.capacity() >= 103);
187 }
188}