use rbx_dom_weak::{
types::{Ref, Variant},
HashMapExt as _, Ustr, UstrMap,
};
use serde::{Deserialize, Serialize};
use super::{InstanceMetadata, InstanceSnapshot};
#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
pub struct PatchSet {
pub removed_instances: Vec<Ref>,
pub added_instances: Vec<PatchAdd>,
pub updated_instances: Vec<PatchUpdate>,
}
impl PatchSet {
pub fn new() -> Self {
PatchSet {
removed_instances: Vec::new(),
added_instances: Vec::new(),
updated_instances: Vec::new(),
}
}
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct PatchAdd {
pub parent_id: Ref,
pub instance: InstanceSnapshot,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct PatchUpdate {
pub id: Ref,
pub changed_name: Option<String>,
pub changed_class_name: Option<Ustr>,
pub changed_properties: UstrMap<Option<Variant>>,
pub changed_metadata: Option<InstanceMetadata>,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct AppliedPatchSet {
pub removed: Vec<Ref>,
pub added: Vec<Ref>,
pub updated: Vec<AppliedPatchUpdate>,
}
impl AppliedPatchSet {
pub fn new() -> Self {
AppliedPatchSet {
removed: Vec::new(),
added: Vec::new(),
updated: Vec::new(),
}
}
pub fn is_empty(&self) -> bool {
self.removed.is_empty() && self.added.is_empty() && self.updated.is_empty()
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AppliedPatchUpdate {
pub id: Ref,
pub changed_name: Option<String>,
pub changed_class_name: Option<Ustr>,
pub changed_properties: UstrMap<Option<Variant>>,
pub changed_metadata: Option<InstanceMetadata>,
}
impl AppliedPatchUpdate {
pub fn new(id: Ref) -> Self {
Self {
id,
changed_name: None,
changed_class_name: None,
changed_properties: UstrMap::new(),
changed_metadata: None,
}
}
}