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
//! Constructs that let you interface with the engine to safely swap and delete GameObjects.
//! 
//! TODO
//! 
use {
    crate::{
        scene::game_object::GameObject, 
        registration::id::ID
    },
    std::sync::{Arc, RwLock}
};

pub enum Swap{
    SwapParent(
        ID, // replace thing with ID 
        Arc<RwLock<dyn GameObject>>  // with this
    ), // replaces the parent object but keeps the child objects
    SwapFull(
        ID, // replace thing with ID 
        Arc<RwLock<dyn GameObject>>  // with this 
    ), // replaces the object and all its child objects
    Delete(ID), // Deletes the object with ID 
    None // don't swap
}

impl Swap{
    pub fn get_id(&self) -> Result<&ID, &'static str> {
        match self{ 
            Swap::SwapParent(id, _) => Ok(id),
            Swap::SwapFull(id, _) => Ok(id),
            Swap::Delete(id) => Ok(id),
            Swap::None => Err("None type has no ID")
        }
    }
}