lyra-engine/lyra-scripting/src/script.rs

57 lines
1.0 KiB
Rust
Raw Normal View History

2024-01-05 01:52:47 +00:00
use lyra_ecs::Component;
use lyra_resource::ResHandle;
use crate::lyra_engine;
#[derive(Clone)]
pub struct Script<T> {
res: ResHandle<T>,
name: String,
id: u64
}
impl<T> Script<T> {
pub fn new(name: &str, script: ResHandle<T>) -> Self {
Self {
res: script,
name: name.to_string(),
id: 0 // TODO: make a counter
}
}
pub fn res_handle(&self) -> ResHandle<T> {
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<T: 'static>(Vec<Script<T>>);
impl<T> ScriptList<T> {
pub fn new(list: Vec<Script<T>>) -> Self {
Self(list)
}
}
impl<T> std::ops::Deref for ScriptList<T> {
type Target = Vec<Script<T>>;
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl<T> std::ops::DerefMut for ScriptList<T> {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
}
}