Skip to content

Commit

Permalink
Update rbx-dom
Browse files Browse the repository at this point in the history
  • Loading branch information
sasial-dev committed Oct 31, 2024
1 parent c935149 commit dc151fd
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 43 deletions.
49 changes: 37 additions & 12 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions crates/lune-roblox/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ rand = "0.8"
thiserror = "1.0"
once_cell = "1.17"

rbx_binary = "0.7.7"
rbx_dom_weak = "2.9.0"
rbx_reflection = "4.7.0"
rbx_reflection_database = "0.2.12"
rbx_xml = "0.13.5"
rbx_binary = { version = "0.7.7", git = "https://github.com/rojo-rbx/rbx-dom/" }
rbx_dom_weak = { version = "2.9.0", git = "https://github.com/rojo-rbx/rbx-dom/" }
rbx_reflection = { version = "4.7.0", git = "https://github.com/rojo-rbx/rbx-dom/" }
rbx_reflection_database = { version = "0.2.12", git = "https://github.com/rojo-rbx/rbx-dom/" }
rbx_xml = { version = "0.13.5", git = "https://github.com/rojo-rbx/rbx-dom/" }

lune-utils = { version = "0.1.3", path = "../lune-utils" }
2 changes: 1 addition & 1 deletion crates/lune-roblox/src/document/kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ impl DocumentKind {
for child_ref in dom.root().children() {
if let Some(child_inst) = dom.get_by_ref(*child_ref) {
has_top_level_child = true;
if class_is_a_service(&child_inst.class).unwrap_or(false) {
if class_is_a_service(child_inst.class).unwrap_or(false) {
has_top_level_service = true;
break;
}
Expand Down
12 changes: 8 additions & 4 deletions crates/lune-roblox/src/document/postprocessing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ pub fn postprocess_dom_for_model(dom: &mut WeakDom) {
remove_matching_prop(inst, DomType::UniqueId, "HistoryId");
// Similar story with ScriptGuid - this is used
// in the studio-only cloud script drafts feature
if class_is_a(&inst.class, "LuaSourceContainer").unwrap_or(false) {
inst.properties.remove("ScriptGuid");
if class_is_a(inst.class, "LuaSourceContainer").unwrap_or(false) {
inst.properties.remove(&"ScriptGuid".into());
}
});
}
Expand All @@ -41,7 +41,11 @@ where
}

fn remove_matching_prop(inst: &mut DomInstance, ty: DomType, name: &'static str) {
if inst.properties.get(name).map_or(false, |u| u.ty() == ty) {
inst.properties.remove(name);
if inst
.properties
.get(&name.into())
.map_or(false, |u| u.ty() == ty)
{
inst.properties.remove(&name.into());
}
}
4 changes: 2 additions & 2 deletions crates/lune-roblox/src/instance/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ pub fn add_methods<'lua, M: LuaUserDataMethods<'lua, Instance>>(m: &mut M) {
"FindFirstAncestorWhichIsA",
|lua, this, class_name: String| {
ensure_not_destroyed(this)?;
this.find_ancestor(|child| class_is_a(&child.class, &class_name).unwrap_or(false))
this.find_ancestor(|child| class_is_a(child.class, &class_name).unwrap_or(false))
.into_lua(lua)
},
);
Expand Down Expand Up @@ -104,7 +104,7 @@ pub fn add_methods<'lua, M: LuaUserDataMethods<'lua, Instance>>(m: &mut M) {
|lua, this, (class_name, recursive): (String, Option<bool>)| {
ensure_not_destroyed(this)?;
let predicate =
|child: &DomInstance| class_is_a(&child.class, &class_name).unwrap_or(false);
|child: &DomInstance| class_is_a(child.class, &class_name).unwrap_or(false);
if matches!(recursive, Some(true)) {
this.find_descendant(predicate).into_lua(lua)
} else {
Expand Down
36 changes: 17 additions & 19 deletions crates/lune-roblox/src/instance/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ impl Instance {

Some(Self {
dom_ref,
class_name: instance.class.clone(),
class_name: instance.class.to_string(),
})
} else {
None
Expand Down Expand Up @@ -337,14 +337,14 @@ impl Instance {
/**
Gets a property for the instance, if it exists.
*/
pub fn get_property(&self, name: impl AsRef<str>) -> Option<DomValue> {
pub fn get_property(&self, name: &str) -> Option<DomValue> {
INTERNAL_DOM
.lock()
.expect("Failed to lock document")
.get_by_ref(self.dom_ref)
.expect("Failed to find instance in document")
.properties
.get(name.as_ref())
.get(&name.into())
.cloned()
}

Expand All @@ -361,7 +361,7 @@ impl Instance {
.get_by_ref_mut(self.dom_ref)
.expect("Failed to find instance in document")
.properties
.insert(name.as_ref().to_string(), value);
.insert(name.as_ref().into(), value);
}

/**
Expand All @@ -377,7 +377,7 @@ impl Instance {
.get_by_ref(self.dom_ref)
.expect("Failed to find instance in document");
if let Some(DomValue::Attributes(attributes)) =
inst.properties.get(PROPERTY_NAME_ATTRIBUTES)
inst.properties.get(&PROPERTY_NAME_ATTRIBUTES.into())
{
attributes.get(name.as_ref()).cloned()
} else {
Expand All @@ -398,7 +398,7 @@ impl Instance {
.get_by_ref(self.dom_ref)
.expect("Failed to find instance in document");
if let Some(DomValue::Attributes(attributes)) =
inst.properties.get(PROPERTY_NAME_ATTRIBUTES)
inst.properties.get(&PROPERTY_NAME_ATTRIBUTES.into())
{
attributes.clone().into_iter().collect()
} else {
Expand All @@ -425,14 +425,14 @@ impl Instance {
value => value,
};
if let Some(DomValue::Attributes(attributes)) =
inst.properties.get_mut(PROPERTY_NAME_ATTRIBUTES)
inst.properties.get_mut(&PROPERTY_NAME_ATTRIBUTES.into())
{
attributes.insert(name.as_ref().to_string(), value);
} else {
let mut attributes = DomAttributes::new();
attributes.insert(name.as_ref().to_string(), value);
inst.properties.insert(
PROPERTY_NAME_ATTRIBUTES.to_string(),
PROPERTY_NAME_ATTRIBUTES.into(),
DomValue::Attributes(attributes),
);
}
Expand All @@ -452,11 +452,11 @@ impl Instance {
.get_by_ref_mut(self.dom_ref)
.expect("Failed to find instance in document");
if let Some(DomValue::Attributes(attributes)) =
inst.properties.get_mut(PROPERTY_NAME_ATTRIBUTES)
inst.properties.get_mut(&PROPERTY_NAME_ATTRIBUTES.into())
{
attributes.remove(name.as_ref());
if attributes.is_empty() {
inst.properties.remove(PROPERTY_NAME_ATTRIBUTES);
inst.properties.remove(&PROPERTY_NAME_ATTRIBUTES.into());
}
}
}
Expand All @@ -473,11 +473,11 @@ impl Instance {
let inst = dom
.get_by_ref_mut(self.dom_ref)
.expect("Failed to find instance in document");
if let Some(DomValue::Tags(tags)) = inst.properties.get_mut(PROPERTY_NAME_TAGS) {
if let Some(DomValue::Tags(tags)) = inst.properties.get_mut(&PROPERTY_NAME_TAGS.into()) {
tags.push(name.as_ref());
} else {
inst.properties.insert(
PROPERTY_NAME_TAGS.to_string(),
PROPERTY_NAME_TAGS.into(),
DomValue::Tags(vec![name.as_ref().to_string()].into()),
);
}
Expand All @@ -495,7 +495,7 @@ impl Instance {
let inst = dom
.get_by_ref(self.dom_ref)
.expect("Failed to find instance in document");
if let Some(DomValue::Tags(tags)) = inst.properties.get(PROPERTY_NAME_TAGS) {
if let Some(DomValue::Tags(tags)) = inst.properties.get(&PROPERTY_NAME_TAGS.into()) {
tags.iter().map(ToString::to_string).collect()
} else {
Vec::new()
Expand All @@ -514,7 +514,7 @@ impl Instance {
let inst = dom
.get_by_ref(self.dom_ref)
.expect("Failed to find instance in document");
if let Some(DomValue::Tags(tags)) = inst.properties.get(PROPERTY_NAME_TAGS) {
if let Some(DomValue::Tags(tags)) = inst.properties.get(&PROPERTY_NAME_TAGS.into()) {
let name = name.as_ref();
tags.iter().any(|tag| tag == name)
} else {
Expand All @@ -534,14 +534,12 @@ impl Instance {
let inst = dom
.get_by_ref_mut(self.dom_ref)
.expect("Failed to find instance in document");
if let Some(DomValue::Tags(tags)) = inst.properties.get_mut(PROPERTY_NAME_TAGS) {
if let Some(DomValue::Tags(tags)) = inst.properties.get_mut(&PROPERTY_NAME_TAGS.into()) {
let name = name.as_ref();
let mut new_tags = tags.iter().map(ToString::to_string).collect::<Vec<_>>();
new_tags.retain(|tag| tag != name);
inst.properties.insert(
PROPERTY_NAME_TAGS.to_string(),
DomValue::Tags(new_tags.into()),
);
inst.properties
.insert(PROPERTY_NAME_TAGS.into(), DomValue::Tags(new_tags.into()));
}
}

Expand Down

0 comments on commit dc151fd

Please sign in to comment.