feo_oop_engine/scripting/swap.rs
1//! Constructs that let you interface with the engine to safely swap and delete GameObjects.
2//!
3//! TODO
4//!
5use {
6 crate::{
7 scene::game_object::GameObject,
8 registration::id::ID
9 },
10 std::sync::{Arc, RwLock}
11};
12
13pub enum Swap{
14 SwapParent(
15 ID, // replace thing with ID
16 Arc<RwLock<dyn GameObject>> // with this
17 ), // replaces the parent object but keeps the child objects
18 SwapFull(
19 ID, // replace thing with ID
20 Arc<RwLock<dyn GameObject>> // with this
21 ), // replaces the object and all its child objects
22 Delete(ID), // Deletes the object with ID
23 None // don't swap
24}
25
26impl Swap{
27 pub fn get_id(&self) -> Result<&ID, &'static str> {
28 match self{
29 Swap::SwapParent(id, _) => Ok(id),
30 Swap::SwapFull(id, _) => Ok(id),
31 Swap::Delete(id) => Ok(id),
32 Swap::None => Err("None type has no ID")
33 }
34 }
35}