use std::sync::atomic::{AtomicU64, Ordering}; use lyra_ecs::Component; use lyra_resource::ResHandle; use crate::lyra_engine; static SCRIPT_ID_COUNTER: AtomicU64 = AtomicU64::new(0); #[derive(Clone)] pub struct Script { res: ResHandle, name: String, id: u64 } impl Script { pub fn new(name: &str, script: ResHandle) -> Self { Self { res: script, name: name.to_string(), id: SCRIPT_ID_COUNTER.fetch_add(1, Ordering::AcqRel) } } pub fn res_handle(&self) -> ResHandle { self.res.clone() } pub fn name(&self) -> &str { &self.name } pub fn id(&self) -> u64 { self.id } } /// A list of scripts #[derive(Clone, Default, Component)] pub struct ScriptList(Vec>); impl ScriptList { pub fn new(list: Vec>) -> Self { Self(list) } } impl std::ops::Deref for ScriptList { type Target = Vec>; fn deref(&self) -> &Self::Target { &self.0 } } impl std::ops::DerefMut for ScriptList { fn deref_mut(&mut self) -> &mut Self::Target { &mut self.0 } }