mod_plugins_resources/
lib.rs

1use std::{fmt::Debug, ops::Deref};
2use bevy::prelude::*;
3
4#[derive(Resource, Clone, Debug)]
5pub struct Current<T: Clone + Debug>(T);
6
7/// Allow Current to be dereferenced so it implements all the functions of the wrapped type
8impl <T: Clone + Debug> Deref for Current<T> {
9    type Target = T;
10
11    fn deref(&self) -> &Self::Target {
12        &self.0
13    }
14}
15
16impl <T: Clone + Debug> Current<T> {
17    /// Creates a new Current instance to wrap the given type
18    pub fn new(input: T) -> Self { Self(input) }
19
20    /// Get a reference to the wrapped object
21    pub fn get(&self) -> &T {
22        &self.0
23    }
24
25    /// Get a mutable reference to the wrapped object
26    pub fn get_mut(&mut self) -> &mut T {
27        &mut self.0
28    }
29
30    /// Transform this into the wrapped object
31    pub fn into_inner(self) -> T {
32        self.0
33    }
34}
35
36/// A trait to be implemented by structs that need to be able to execute something on the client.
37pub trait Executable<O> {
38    fn execute(self: Box<Self>, world: &mut World) -> O;
39}
40
41#[derive(Component, Default)]
42pub struct ScopeGlobal;
43
44#[derive(Component, Default)]
45pub struct ScopeLocal<S: States + Default>(pub S);