use std::collections::HashMap;
use serde_derive::{Serialize, Deserialize};
use crate::{
id::RbxId,
value::RbxValue,
};
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "PascalCase")]
pub struct RbxInstanceProperties {
pub name: String,
pub class_name: String,
pub properties: HashMap<String, RbxValue>,
}
#[derive(Debug, Serialize, Deserialize, PartialEq)]
#[serde(rename_all = "PascalCase")]
pub struct RbxInstance {
#[serde(flatten)]
properties: RbxInstanceProperties,
id: RbxId,
pub(crate) children: Vec<RbxId>,
pub(crate) parent: Option<RbxId>,
}
impl RbxInstance {
pub(crate) fn new(properties: RbxInstanceProperties) -> RbxInstance {
RbxInstance {
properties,
id: RbxId::new(),
parent: None,
children: Vec::new(),
}
}
pub fn get_id(&self) -> RbxId {
self.id
}
pub fn get_parent_id(&self) -> Option<RbxId> {
self.parent
}
pub fn get_children_ids(&self) -> &[RbxId] {
&self.children
}
}
impl Clone for RbxInstance {
fn clone(&self) -> Self {
unimplemented!()
}
}
impl std::ops::Deref for RbxInstance {
type Target = RbxInstanceProperties;
fn deref(&self) -> &Self::Target {
&self.properties
}
}
impl std::ops::DerefMut for RbxInstance {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.properties
}
}